I am using an Arduino Mega 2560 board have an LCD and a real time clock on the I2C. At one time it was working. Now the RTC will not initialize the LCD works just fine. If I unplug the LCD the RTC works? Anybody got an idea what I am doing wrong. Here is some of the code I am using:
#include <Wire.h> // required by RTCLib.h
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
what is the address of the RTC?
did you try an I2Cscanner?
Can you make a photo of the wiring ?
Some use flat ribbon cable for the I2C bus, that is not so good for the I2C signals.
I ran the scanner and had an interesting thing happen. With both the RTC and the LCD plugged in I only saw the 0X3F address of the LCD. I unplugged the LCD and the RTC address 0X68 showed up. I plugged the LCD back in then both addresses showed up?
I attached a couple of pics of the wiring.
Thanks for the help!
The Mega has physical pullup resistors on it for SDA and SCL. Do you know if either the LCD and / or the RTC have pullup resistors too?
At one time it was working.
Has anything changed in the wiring etc between then and now?
Thanks for the photos, everything seems fine as far as I can tell.
That single tyrap can't cause so much trouble.
We have to dig a lot deeper.
The combined pullup resistor of the I2C could be too high or too low. Or there are some bad contacts. Or a bug in the libraries or sketch. Like Hackscribble, I think the pullup resistors for the I2C bus is the first thing to look into.
Do you have a link to the DS1307 and the LCD modules ?
The Arduino Mega has onboard 10k pullup resistors, plus internal 50k.
If the DS1307 module has 4k7 pullup resistors, it might still be okay, but if they are 2k2, it might be too low.
With a multimeter, it is possible to measure the pullup resistors. Load the Arduino with an empty sketch (empy setup() and loop() functions or the blink example), and measure the shortcut current of SDA to GND and the shortcut current of SCL to GND. If they are about 1mA (0.5 to 2mA), they are okay.
There is another test you can do, the Multi Speed I2C scanner : MultiSpeed I2C Scanner - 50,100,200,400 KHz. - Libraries - Arduino Forum
The code is here : Arduino/sketches/MultiSpeedI2CScanner at master · RobTillaart/Arduino · GitHub
Do you use the newest Arduino IDE 1.0.6 or 1.5.8 BETA ? And the newest versions of the libraries ?
Or do you perhaps allocate too much ram with an array of variables or many Serial.print strings ? Could you show the whole sketch ?
I have found a work around but I do not understand why it works. I simply move some code around so the RTC is initialized before I do any thing with the LCD. So far it has worked every time I reset or restarted the Mega. If I have issues again I will test for the pull up resistor.
Thanks for all your help!
There were old bugs with the Arduino Mega 2560 board, and shifting around the memory was a workaround for it. Do you use a Mega 2560 clone from Ebay or an older board ?
Allthoug I think this is not the old bugs, the old bugs can be fixed by using the newest Arduino IDE 1.0.6 or 1.5.8 BETA and also burning a new bootloader.