I2C Bus Connections For 2 Or More Devices

Many devices (0-127) can use the 2 pin I2C bus (OLED, NEO7GPS, BMP180), but you have to connect them in parallel to pins SCL-A4 and SDA-A5 of a Nano so they share the bus. (SDA and SCL are marked on an Uno). The Wire.h library is required as an #include.

They need to be able to pull voltages low (from 5v to 0V) to communicate:

so the bus needs 2 x 4.7k “pull up” resistors from the Nano 5V supply pin to A4 and A5 resp. to give a bus voltage of 5V.

(The resistor value technically depends on many factors like bus speed and capacitance, but in reality for a few devices on short wires, 4.7k resistors works fine). See Texas Inst. PDF link: https://www.ti.com/lit/an/slva689/slva689.pdf )

“A simple analogy for open drain is a bus, and the rope / harness you use for signalling the driver for a stop. Everyone on the bus can yank on it and pull it down, but tension in that line will pull it back up after you release it. The strength of the pull up + the capacitance in the line will determine how fast you can run.”

Note that a common reset pin in the event of comms corruption maybe used (e.g. for the OLED); on the Uno/Nano it’s pin 4 stated in the OLED code comment line: #define OLED_RESET 4 // Reset pin

Once all devices are connected, run the I2C address scanner here to check each device is seen:

With the OLED and BMP180 connected, SerialMon shows me:

22:00:28.641 -> Scanning…
22:00:28.641 -> I2C device found at address 0x3C !
22:00:28.674 -> I2C device found at address 0x77 !
22:00:28.707 -> done

Now I need to combine code from all the prior Posts for each device to function and display; OLED, BMP180, DHT11 and Neo7 GPS.

I could add the GPS to the bus also, but for now I’ll leave it on Nano pins 8,9 due to code. I’ll play with that another time.

Power should be possible from the Nano due to the lower power requirements of the OLED over an LCD…?  We’ll see…

I learned it’s possible to overload the Nano to lock up with many tasks (and bad coding no doubt!), trying printing data to both serial and OLED screens with the same data.

Also, I realised the benefits of calling modular functions from within loop() once written, as you can comment them in or out to fault find. That’s how I found the data overload issue when code was ok!

For now, I have tidy code, part serial code removed, with GPS and BMP data on the OLED screen:

Finally, the code with DHT11 data added:

This code displays how I want and has all serialmon code removed: