For my next project I would like to use a DS1307 I2C RTC and a Adafruit I2C 7 segment led display-Quad Alphanumeric Display - White 0.54 Digits w/ I2C Backpack [STEMMA QT / Qwiic] : ID 2157 : $13.95 : Adafruit Industries, Unique & fun DIY electronics and kits to display the amount of days until Christmas. Both of the I2C modules use analog pins 4 and 5. How would I program two I2C modules that use the same pins?Could I use the wire library?
I2C is a bus, shared between one or more devices. Each device must have a unique I2C address, which the above do have. Sample code is available on the web for both devices.
Connect all SCK signals to A5 and all SDA signals to A4. Make sure that there are at least one set of external pullup resistors of around 4.7K (SDA to Vcc and SCL to Vcc). The internal pullup resistors on the A4 and A5 pins are enabled by the library but are often not enough.
You definitely need the Wire library. You need unique addresses. All SDA pins connected together, and SCL addresses connected together. You need to include pull up resistors on both lines - as required for I2C
In order to determine what valued resistors you need:
For most cases 3.3k to 10k Ohms is fine
For power sensitive circuits, use a higher value.
For speed sensitive circuits use a lower value, 1k ohms is quite common
if you want to read into why these values are ok - i found this to read
Do I need to include the address in the code. If so, how can I find the addresses? Thanks!
The device datasheets should have the addresses. If you are using a library the I2C addresses are in the library for the device as all devices of the same type have the same address. For instance the DS1307 library has the address defined as 068. To confirm that the address is correct and to verify communication, use Nick Gammon's I2C scanner attached.
The Adafruit library for the backpack 0.54" Alphanumeric Backpack | Adafruit LED Backpacks | Adafruit Learning System
has the address at 0x70 by default, but can be changed in the begin method.
i2c_scanner.ino (776 Bytes)
I'll try that. Thanks for your help!