I know this is probably a simple question, but I have been dabbling into the Arduino for a few months now as I built an LED array I need to control and am having newcomer issues. I have an Arduino Uno, Rev 3 I believe. First off, I have a display and an RTC.
I have merged the code for these two tutorials while I test these devices.
For starters, I have the display working. I have no problem communicating or outputting to it. I am having problems with the RTC. It appears to be working, but if I disconnect power to the whole setup and reconnect, it's not retaining the date correctly. I'm not even sure it's working since I can run the exact sketch without the RTC even connected. The display uses I2C and I also believe the RTC uses I2C. Now, my real question is, where am I supposed to hook the wires up to for both of these at the same time? I see references to the I2C pins being A4 and A5 on the Arduino, but I was under the impression the I2C pins were on the top left, next to the AREF pin. What is the difference between the A4-A5 I2C and the I2C pins next to the AREF? My problem may be that I bussed the RTC into the top two pins instead of A4 and A5 and the code I am using is for the analog pins.
Like I said, this may just be a dumb noob question so I figured I'd ask the experts to point me in the right direction. TIA
A4/A5 are the I2C pins. Connect to all devices in parallel. Be sure to use ~4.7K pullup resistors on both lines.
Do you have backup battery connected to the RTC? It will not maintain time without it.
Use a meter, I believe you will find the two sets of pins are identical. That's what the schematic shows.
The RTC came with a watch battery, it is in there and I believe when I checked it's voltage to the pins on the battery holder it was reading 2.2v. So to answer your question, yes I believe I have a backup battery connected.
I did read something about a pullup resistor for I2C a little earlier. I couldn't determine whether or not the Arduino had built-in pullups or if that was even possible. By your response, I'm assuming that's not the case. What do I connect the pullups to? I've heard that term a few times, but I'm not quite sure how to implement them. Where does the resistor pullup to, 5v or ground?
2.2 sounds low. I would have expected 3V.
VBAT Battery Voltage VBAT min 2.0 typ 3 max3.5 V
Pullup goes to 5V.
(pulldown would go to ground).
ATMega IO pins have 'weak' pullups, like 20K. If you watch the signals on a scope, they go from low to high really slow with internal only vs have 4.7K.
I was able to get the RTC working today. I added the pullups as suggested, but I had to hook the RTC up to A4/A5 while my LCD connected to the "other" I2C pins on the other side of the board; which confuses me because I was under the impression they were connected. I tested both ways with both devices, connected them in parallel bussed together, but I couldn't get them to work. If they were bussed on A4 and A5, the RTC would only work and like-wise if they were bussed on the other I2C pins only the LCD would work. I think that may have to do with the sketch, but connecting them to their respective "working" pins, I was able to get both of them to work. If that makes sense. I am not new to software, but to micro controller programming, so I may be addressing hardware wrong but I only had example sketches to reference for each library to build my program. In the end, it's working so I'm happy for now.
FWIW the battery is 3v and is indeed reading 2.2v, but it does work to retain the time while the board is powered down.
I agree; I must be doing something awkward. If I use the pins up top, the time on my display shows 165 for all the values it should be retrieving from the RTC. Using the analog pins, on my LCD the back light doesn't come on and no characters appear. It does appear to receive power though.
rrasco:
If they were bussed on A4 and A5, the RTC would only work and like-wise if they were bussed on the other I2C pins only the LCD would work.
That almost sounds as if you have accidentally got the terminals reversed on one of those groups. When you say 'tested both ways' does this mean you tried swapping the wires over for the non-working device? If not, I'd be tempted to give that a try.
By 'tested both ways' I mean I had them hooked up in parallel directly to the A4/A5 pins on one test and the other test I had them in parallel to the 'other' I2C pins. I think tonight I may try each device individually on each set of pins to see if that has any effect on the matter.
What type of arduino do you have?
There are no real "other" I2C pins. There are only one set. The ones marked SLC and SDA above the Aref pin are duplicates of what ever real pins hold the I2C signals on that board's processor. This is so shields can work with all sorts of boards.
If you have no pull up resistors on your arduino the you need to fit some externally. The internal pull ups are not sufficient especially with two devices on the bus.
I have an Uno, R3. I understand the I2C pins should all be the same, I am referring to them as the 'other pins' because they are not marked as anything on my board, they are just there.