Skip to main content
Share Your Experience: Take the 2024 Developer Survey
13 votes
Accepted

Multiple I2C sensors with the same address

If you're using MPU6050 IMUs, there's an easy trick: put them all on the I2C bus, and connect each IMU's AD0 pin to a separate digital pin on the Arduino[*]. When you want to read from a specific IMU, ...
dda's user avatar
  • 1,588
11 votes

How to design and debug a custom I2C master-slave system?

This tutorial I gave at the Embedded Linux Conference tries to answer the questions, providing links to more detailed description of the topics addressed and using the practical example of driving a ...
Igor Stoppa's user avatar
  • 2,125
10 votes
Accepted

What does it mean in I2C, "NACK received"?

A NACK is signaled by an acknowledgement slot in which SDA remains high while SCL cycles under control of the master. Since high is the un-driven state of the pulled-up bus, in the absence of a ...
Chris Stratton's user avatar
9 votes

Calling I2C functions inside an ISR

Here is an analogy for you to help you understand why using the IRQ is a good idea. Imagine you are at a conference. There's hundreds of you in the audience, and you are in a question and answer ...
Majenko's user avatar
  • 105k
9 votes
Accepted

What is the right way to query an I2C device from an interrupt service routine?

Just because a pin is called "interrupt" doesn't mean that you have to read it using an interrupt input. The INTx pins of the ADXL345 are simple "level" outputs. All the time there is an "interrupt" ...
Majenko's user avatar
  • 105k
8 votes
Accepted

Confused between SPI and I2C for SSD1306 OLED

SCK and SCL are the same thing. Serial ClocK Serial CLock They seem to be interchangeable. The fact you have SDA (Serial DAta) as opposed to separate SDI / SDO or MOSI / MISO pins means it's I2C. ...
Majenko's user avatar
  • 105k
7 votes
Accepted

Wire.h library works on Uno but won't compile for ATtiny85

You get this error, because the ATTiny85 doesn't have full I2C hardware. It only as an USI (Universal Serial Interface). This can be utilized to do the rest of the I2C protocol via software. There are ...
chrisl's user avatar
  • 16.3k
7 votes
Accepted

How to choose alternate I2C pins on ESP32?

I was able to resolve my issue thanks to Juraj comment. I did : Wire.begin(16, 17); htu21d.begin(Wire);
Gazouu's user avatar
  • 273
7 votes
Accepted

Is there any limitation with Arduino Nano serial communication distance?

For that sort of difference you are better using RS-485 instead of UART. UART is really only designed for short-distance communication. Converting UART to RS-232 will give an improvement, but ...
Majenko's user avatar
  • 105k
7 votes

Multiple Wire.write() not working for Arduino Nano I2C

Important information: Wire.write() does NOT send anything over the I2C lines. It just puts the data into the libraries internal buffer. The actual transmission is then done by Wire.endTransmission(). ...
chrisl's user avatar
  • 16.3k
6 votes

Difference between Wire.setClock() method and TWBR method for changing I2C Frequency

They are both one and the same. One is easier to remember though (I'll let you work out which). Wire.setClock(frequency) just (ultimately) does: TWBR = ((F_CPU / frequency) - 16) / 2; You can set ...
Majenko's user avatar
  • 105k
6 votes

I2C and SPI at the same time?

is it possible to use I2C and SPI at the same time? Yes it is. Both are implemented in hardware in the chip. They can operate "in the background" and raise an interrupt when there is something to do. ...
Nick Gammon's user avatar
  • 38.3k
6 votes

Which EEPROM has a long lifecycle?

You can cycle through all the addresses in the EEPROM like a ring buffer. You'll need to reserve a bit so you can binary search for the head of the buffer during startup. You can also reduce how ...
ratchet freak's user avatar
6 votes
Accepted

Arduino slave with 2 masters sharing the same I2C Bus?

The situation you describe is called MultiMaster. It is normally done in hardware using the I2C peripheral in the MCU. However the ESP8266 doesn't have one (or if it does, it's not used), and uses bit-...
Majenko's user avatar
  • 105k
5 votes

What does this notation stands for? Wire.read() <<8 | Wire.read()

Just adding a couple of points to Michel Keijzers's answer. The expression Wire.read() << 8 takes the value returned by Wire.read(), which is an int, and shifts it 8 bits to the left, which is ...
Edgar Bonet's user avatar
  • 43.2k
5 votes

Problems with I2C connection on ESP8266 - 12F, which pins should I use?

Unlike most Arduinos, the ESP8266 doesn't have a hardware TWI, so I²C is bit-banged in software. This means that you can use any GPIO pins. By default, Wire.begin() initializes pins 4 (SDA) and 5 (SCL)...
tttapa's user avatar
  • 1,320
5 votes

Sensor TSL2591 with Arduino Mega

Looking at the datasheet, the TSL2591 does not appear to have a comfigurable address mechanism, therefore you are most likely obliged to use an I2C Multiplexer. One example of such a device is the ...
Greenonline's user avatar
  • 2,982
5 votes
Accepted

Arduino Uno 2 I2C devices problem

I imagine you are using the Adafruit Library, since thats the URL of the product you posted. If so, in RTClib.h: #define DS1307_ADDRESS 0x68 #define DS3231_ADDRESS 0x68 And in the OBDs product ...
Wesley Lee's user avatar
5 votes

What is the right way to query an I2C device from an interrupt service routine?

Majenko's answer is useful — you can simply forego the use of interrupts for this and poll the pin directly in your main loop. Especially on AVR where the external pins are exposed as registers which ...
hobbs's user avatar
  • 234
5 votes

Sparkfun CCS811 Air Quality Sensor is just not working

You need to solder those headers to the breakout. Just inserting them into the plated-through-holes doesn't give a reliable connection.
Gerben's user avatar
  • 11.3k
5 votes
Accepted

Convert float to byte, from Arduino to Raspberry Pi i2c

First of all, if you want the Arduino to send data as a slave, it should do so onRequest(), not onReceive(). Thus: void setup() { Wire.begin(0x08); Wire.onRequest(handleRequest); } Next, as ...
Edgar Bonet's user avatar
  • 43.2k
5 votes
Accepted

Arduino with LCD Display does not reset/restart/start on connection to power

You've tagged the question with both nano and arduino-nano-33-iot, but I'm guessing between the two you're using the latter, because on Arduinos with native USB (not a plain Arduino Nano) while (!...
timemage's user avatar
  • 5,299
5 votes
Accepted

Arduino Uno freezes for unknown reason during code execution

The program most likely hangs at Wire.endTransmission();, because that's where the actual I2C communication happens. Wire.write() does nothing but placing the data into the internal buffer of the Wire ...
chrisl's user avatar
  • 16.3k
5 votes
Accepted

I2C sensors not working when I connect to LCD 20X04

Welcome to Stack Exchange! I can spot a few problems with the circuit. As @hcheung said, the I2C pull-up resistors should only be wired between SDA>3.3V and SCL>3.3V (in parallel), not in series ...
Liftyee's user avatar
  • 126
5 votes
Accepted

My Atlas Scientific sensors measurement give zero values at first reading

Each time you call receive_reading() you pass it one sensor to read the value from. But each time you call receive_reading() you print out all three sensors. So you: Read EC and print EC PC TEMP Read ...
Majenko's user avatar
  • 105k
4 votes
Accepted

How do I use two I2C LCDs with 4 pins?

With the I2C backpack there are three pairs of landings, A0, A1, A2, which determine the 3 LSB of the device's address, using inverted binary. Left alone, they generate part of the F or 7 part of ...
SDsolar's user avatar
  • 1,165
4 votes

Alternatives to Wire library for I2C

Also Procyon AVR library worth be checking. It is a bit old now but very professional and kinda minimalistic. Not much dependencies, should be fine to use just I2C module only. There is hardly ...
Flanker's user avatar
  • 529
4 votes
Accepted

I2C: What is the difference between A4&A5 and SCL&SDA pins?

They are the same pins. They are physically connected to each other on the UNO board. (So SDA is connected to A4. SCL is connected to A5)
Gerben's user avatar
  • 11.3k
4 votes
Accepted

ATTiny85 I2C LCD

After hours of Googling, I found a blog post by Dimitris Platis where he describes using an ATTiny85 with I2C LCD. I emailed the guy and he replied with a link to his LCD I2C ATTiny library on GitHub. ...
Thijs's user avatar
  • 432

Only top scored, non community-wiki answers of a minimum length are eligible