I2C problem with LCD and RTC


I use a Arduino Duelmilanove to talk to a DS1307 RTC and to a Matrix Orbital LCD with i2c (wire library).
The i2c addresses are different for the two devices.

The RTC works fine when it is the only device connected to the i2c bus.
When the LCD and the RTC are connected to the i2c bus at the same time, the LCD works but the RTC send weird data.

Any help or clue is welcomed !

Maybe you need to add a resistor to pull up a line or so? Please post a drawing of your connections to check.

And of course the RTC and LCD should not "talk" simultaneously, otherwise the signals will interfere ...


I tried two connections schemas, one without any pull-up resistors and the other on with 2 2.2Kohms resistors.
The same behaviour occurs in the two schemas.

The LCD is a Matrix Orbital 20x4 with high voltage options (from 7 to 12 v).


Moreover, as soon as I disconnect the SCL wire of the LCD, the RTC returns the right time.
As I reconnect the SCL wire, the RTC returns weird data ...

Idem for the SDA wire.

When reading the time, you will have somewhere:

 Wire.endTransmission ();

If you change that to:

byte err = Wire.endTransmission ();

And then test "err" for non-zero and do something like flash a LED (or print a debug message) you will know that the I2C failed. Perhaps the LCD library constantly polls the LCD or something.

Thanks Nick,

I do not use any specific library for the LCD.

I change my code to :

byte err = Wire.endTransmission ();

And, I get the error code "2".

I found in the file twi.c the following error code :

2 .. address send, NACK received

What does that mean ?

NACK is Not ACKnowledged. It means that the device at the specified address did not acknowledge (admit receipt of) the packet that was sent.

It's hard to say more without putting a logic analyzer on the wires. If the clock works without the LCD connected, then possibly the LCD's "backpack" or whatever you have connected is frequently using the I2C for some purpose, thus denying the clock "space" to send its data. One thing you could do is check the error code, and discard the data if it (the error code) is non-zero. Maybe some of the time you get a good transmission.

just an idea: does the voltage level drop when the LCD is attached?

Try 10k pullups?
And how long are the cables to the lcd??? The lcd expects 12v or 5v levels for i2c???(datasheet)

Finally, using wire, serial and lcd libs together USED to require all 6 args for the lcd to work.Search the old forum for this.

Thanks orbitalair,

The wires are about 30 cm long for the LCD and the RTC.

In the LCD manual, I found that "The I2C data line operates on 5 volts CMOS levels.", so it should be ok and it is since it's the RTC which does not work anymore when the LCD is connected (LCD is ok in all cases).
Note that I'm using only the wire lib.

Finally, I will give a try tonight to change the pullups and measure the voltages.

Thanks all !

It finally works with 4,7KOhms pullups and, most important part, shorter I2C wires !!!

Just thinking, if you drop the speed of I2C bus, you should get less interference and longer distance. Could someone comment on this?

Thanks all !

It finally works with 4,7KOhms pullups and, most important part, shorter I2C wires !!!

Glad you worked that out. After extra research I found that 4.7K was the recommended value - a lot of sites just mention "use a pull-up resistor" without going into too many details.

I also note in the Atmega spec it mentions "The number of devices that can be connected to the bus is only limited by the bus capacitance limit of 400 pF and the 7-bit slave address space." So perhaps the longer wires were introducing too much capacitance.

Further to that, I found this quote:

One common mistake I see is people using I2C with controllers and accepting the internal pull-up as being adequate for driving the bus. It just might work if the one I2C peripheral or memory part is the only thing connected to the processor and it is very close to the host. But even then many users report that they cannot get the 100kHz or 400kHz speed of the I2C bus, the might have to reduce the clock to 10kHz or even less. I2C was specified with a 4.7K pull-up for a darned good reason, and you will see that the rise times and thus speed capability of the bus only achieve optimal values when you use that pull-up.

At: The errant engineer: Pullup resistors - how and why

If you want see the impact of using different pullup resistor values checkout the below article: