I cannot use two devices on i2c

Hello,

i am trying to read the time from a ds1307 and draw it on a display (oled with i2c interface).

Both are working once at time, i can not see them if connected togheter (i'm on arduino nano).

The scanner says ds1307 address is 0x68 and the oled's address is 0x3C, so i guess they should work togheter...

Have you got two sets of pull ups? (i.e. in parallel)

For what it's worth, I have both running happily alongside each other with those addresses on an Uno.

Without seeing your code, just guessing....
I'm wondering if your program is requesting data from, lets say the 1307, but never terminating the transfer with a stop, and then request data from the other device, then possibly both slaves are pulling down the SDA line causing garbled data or bus collisions.

Due_unto:
Without seeing your code, just guessing....
I'm wondering if your program is requesting data from, lets say the 1307, but never terminating the transfer with a stop, and then request data from the other device, then possibly both slaves are pulling down the SDA line causing garbled data or bus collisions.

I doubt something like that may happen as long as there is no noise problem on the lines. Until stop or repeated start comes only those devices selected after the last start are responding. After either reset or repeated start selected devices should consider themselves deselected and wait for their address. Bus contention between slaves may happen only if

  1. More slaves have the same address
  2. Due to week pull-ups, long wires or some interference the slaves see different data - for example one miss repeated start condition or sees one when the master didn't send it.
    Since repeated start looks exactly the same as "normal" start there is no way to force slaves into contention as long as they recieve the same data (and follow the protocol, clock speed is not too high, voltage is stable ...)

I have pull up resistors on the ds1307, not on the oled which is working as it is (i guess it has pullups on board?).

The scanner works if just one device is connected. If both devices are connected the scanner will find just the oled (0x3C) and not the ds1307, so it is not a code mistake.

It is very probably hardware problem. Adding more devices incrases capacitance of the bus and that leads to problems such as slower transitions from 0 to 1. What voltage is the OLED? Maybe it is 3.3V with onboard regulator and its pullups are pulldowns from the DS1307 point of view (just a wild guess).
Also note that DS1307 has maximum SCL speed 100kHz. Are you sure you are not running faster? If you are running at 100kHz you may tray reduce the speed a bit "just to be safe".
If you are using library for the OLED it may switch I2C speed to 400kHz (another wild guess) and then it is not suitable for the DS (probably not causing described problem but caveat after you solve it).

Anyway - how strong are your pullups? Possibly making them stronger (3k3? 1k???) may solve the issue - but I am not sure how much current the SDA/SCL pins of your devices can sink. (It may be the other way - the pullups are too strong and DS1307 is unable to pull down??? Hardly but in theory possible.)

You only need one pull up resistor on each of the two wires, 4K7 should do it.

Have you any power supply decoupling on each of the two devices?

Draw a schematic of your system and add a photograph of your wiring, both not just one. Then read the how to use this forum sticky post, and post all your code.

I use 10k pullup resistors on the ds1307. If the display is NOT connected i can read and set properly date and time (using HCRTC library).

The display without pullups works, i can draw on it with the u8g library, but when i connect it the ds1307 isn't available anymore.

Both takes power from the arduino nano.

Isn’t the I/O voltage of the OLEDs 3.3V?

So you would need a level shifter for the I2C lines of the OLED?

There could be pullups to 3.3V on the OLED module.

What part of:-
Draw a schematic of your system and add a photograph of your wiring, both not just one. Then read the how to use this forum sticky post, and post all your code

Are you having trouble understanding?

Grumpy_Mike:
What part of:-
Draw a schematic of your system and add a photograph of your wiring, both not just one. Then read the how to use this forum sticky post, and post all your code

Are you having trouble understanding?

No problem sir, i apologize, it’s just i have a very badly drawn -by hand- schematic which is not helping, and also pictures will not be helpfull cause cabling is a real mess and already soldered!
See attachements.

Anyway… i confirm oled has its own pullups, you can clearly see paths on the board going from the pins sda and scl to a resistor (cod103 = 10k Ohm). Also the rtc had 10k Ohm resistors.

I just tryied with smaller resistors (4.7k Ohm) and now i have both rtc and oled working togheter, apparently without issues!

It looks like you don’t understand meaning of pull-up. On the first schematic
63f6a0af2eaceb48ffe11436385b1333aae48f56.jpg
the resistors are between SCL(SDA) of RTC and SCL(SDA) of Arduino. It is not pull-up, it may be overcurrent protection of some sort. Pull-up would be from SCL of RTC to 5V and both SCLs connected directly without any resistor. The same for SDA.
Here is the second picture:
a365d6390d738376de642a1cca4018dd60ef7326.jpg
Include your pictures into your post next time please.