RTC acting strange

Very strange things are going on. I rewired almost everything with shorter wires like you suggested (I was using cheap male-to-male wire connectors and switched to stripping solid core 22 gauge wire) and this time I did nothing to pullup SCL, like before. This time the output seemed to be working, but displayed the time as 3:50, which is approximately the time I tried pulling SCL up with the same resistor as SDA. So I tried pulling SCL up again, and just like the last time I pulled it up, nothing worked and nothing output to the serial monitor. Just afterwards I tried the circuit without pulling up SCL and this time it reads 4:39. The actual time was 4:41, and 4:39 is when I tried to pull up SCL.

So I did this procedure over again, except tried to switch it as fast as possible, between having a pullup resistor and having no pullup resistor for SCL. I found the quicker I can switch it, the more accurate the time displays. So for some reason the chip's time is set when SCL is pulled up, but can only display the time when there's no voltage?

Just took some pictures, they'll up in a couple minutes.

megamax42:
Hmm, interesting, I appreciate the informative post, though you are correct about me being confused XD.

I only have one 4.7k ohm resistor, so I had both SDA and SCL going through that to the voltage, but then that turned the entire system off, outputting nothing to the serial monitor. Is this just a case of requiring another resistor?

One other thing I should note is I have SQW/OUT wired to nothing.

Using one resistor wired to +5vdc and then to both SDA and SCL signal lines results in just shorting the two signal wires to each other, a total disaster as wiring schemes go. Yes each signal line requires its own separate pull-up resistor.
No problem not using the SQW/OUT pin, it's an optional feature that you are not required to use.

Lefty

Come on with your pics already!!!

Sorry! :blush: Had to sprint out the door to radioshack to get another 4.7k resistor before they closed.

Well, it seems to be working now that I have two separate resistors. It's still approximately one minute behind but I'm not too bothered by that.

And now everything is printing in the correct place, the format for the serial monitor is:

Current Date/Time

of seconds and days since 1970

One week and 30 seconds from now Date/Time

For example:
2012/10/14 18:0:56
since 1970 = 1350237656s = 15627d
now + 7d + 30s: 2012/10/21 18:1:26

Before today, when the circuit was semi-working, and I didn't have SCL pulled up with a resistor, it would occasionally count time correctly. The odd thing is the actual date and time would always print in the "One week and 30 seconds from now Date/Time" slot.
Whereas now the actual date and time prints in the "Current Data/Time" slot, as it should.

Anyways, thanks for everyones help and clarification. This was driving me nuts!

Here's the pictures if you were still curious:
The Battery on the right kind of got cut off, but that's what the red and black wires disappearing go to.

No Pullup resistor

Additional pullup resistor added

If you want a more permanent setup, this one will help (you only need to get the PCB):

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/item/rtc-real-time-clock-module-%2B-eeprom-slot/

I made these a while back before I designed the phi-1 and phi-2 shields.

Oh wait, your battery holder is different from mine :frowning:

Thanks for the advice! This would definitely look a lot cleaner on a PCB, and since they're so cheap maybe I'll just order a new battery holder.

Also thank you very much robtillaart for the updated code! It compiled perfectly the first time, and worked very well in the serial monitor.

The only thing I'm currently stuck on now is the time that is set to the arduino when I compile/upload is about 5 minutes ahead of the actual time. According to the code it should be set exactly to my computers time, but it's consistently ~5 minutes fast, with both robtillaart's code and the unmodified code I've been using. I'm very confused as to what could be causing this error. I've also tried ungrounding the battery each time to 'reset' the DS1307 chip.

about 5 minutes ahead of the actual time.

If it is just at start-up you might compensate it by add/sub enough seconds,
better is try to catch the root cause, which might be in the RTC lib ?

a longer term observation is needed to see if the clock is fast or not. If you can leave your RTC on for weeks and check later, then you will know if it runs slow or just has an offset.

Well, increased observation of the serial monitor has brought me back to where I started pretty much. Using both robtillart's code and my original code I get this on the serial monitor:

2012/10/16 22:49:46
since 1970 = 1350427786s = 15629d
now + 7d + 30s: 2012/10/23 22:50:16
2165/165/165 165:85:47
since 1970 = 2028815851s = 23481d
now + 7d + 30s: 2034/4/23 15:58:1
2012/10/16 22:49:48
since 1970 = 1350427788s = 15629d
now + 7d + 30s: 2012/10/23 22:50:18
2165/165/165 165:85:49
since 1970 = 2028815853s = 23481d
now + 7d + 30s: 2034/4/23 15:58:3
2165/165/25 22:49:50
since 1970 = 2016202894s = 23335d
now + 7d + 30s: 2033/11/28 16:22:4
2165/165/165 165:85:51
since 1970 = 2028815855s = 23481d
now + 7d + 30s: 2034/4/23 15:58:5
2165/25/16 22:49:52
since 1970 = 1908548496s = 22089d
now + 7d + 30s: 2030/7/1 16:22:6

And although when I watched the serial monitor for a while after adding the resistor for SCL, it was printing perfectly, now it's messed up again. I also highlighted the dates, as I believe they may be important in troubleshooting this problem. I checked the libraries and downloaded the latest ones so I know they're all good. Could it be a bad chip or would they react differently? :~ :~

Continued analyzing of the serial monitor has shown a certain pattern, where every once in a while the date/time is replaced by one in the year 2165 and a random time, though usually in the hour 5 p.m. or 3 p.m. (15 or 17). This is very troublesome for me because my fade function for the LEDs is based off of decreasing the brightness each second if the condition is met, and the condition is a time. Sometimes the monitor will display 15 correct values, sometimes every other value will be in the year 2165. I can't wrap my head around it

Maybe it is time to go get yourself a radioshack perf board and solder the parts together to make sure there's no problem with the connections. I have had some problems with RTCs but nothing other than weak connections and breadboards.

Ahh you very well may be on to something here, as I'm using a very cheap made-in-china breadboard. Will report back once I've got it soldered.

megamax42:
Ahh you very well may be on to something here, as I'm using a very cheap made-in-china breadboard. Will report back once I've got it soldered.

Breadboards are always the source of some problems. The clips in the board that hold wires have capacitance and could couple to other wires. So once you finish breadboarding, move to a perf solder board.

Got a tiny PCB from radioshack yesterday and got everything soldered up. It finally works! Well, almost.
But I'm so happy I could cry, this has been driving me nuts. Even though it's my fault for buying such a cheap breadboard, you can guarantee the company I bought it from is going to get a very descriptive letter on where they can shove their breadboards.

The only issue I'm running into now, and it may not even be an issue, is the LED on the breadboard. Something I've noticed after I upload the program is the little orange LED labeled 'TX' glows a solid orange, but when I open the serial monitor the LED blinks with each second, is this just the Arduino telling me it's interfacing with a computer, or is it more indicative of a running program?

Edit: Nevermind, just read the Arduino tutorial on RX and TX, thanks again for your help everybody! You've all been fantastic, I really can't thank you enough.

megamax42:
Got a tiny PCB from radioshack yesterday and got everything soldered up. It finally works!

Could have bought my shields or board and save all that trouble. $)

Lol I should've! Are you talking about the Phi-Connect shield and Phi-Connect breakout boards?
The Phi-2 looks like a cool shield, I would've definitely gone that route if the TFT LCD displays weren't as cheap.

I've got a few different shields and hardware :slight_smile:
The problem of having TFT displays with arduino is that you have this nice display but not enough memory to make good use of it. Plus, your arduino will have to store all the font used on the display. That's a lot of memory, around 600B-1KB. Arduino only has 2KB, so unless you only want to use that display and not many other stuff for a project (I don't know what that project might be), you will be running out of memory all the time. Similar thing with SD cards. The SD card library takes about 1.1-1.3KB memory. You have to find ways to save SRAM before it runs out. In that case, I'd use my own phi-panel serial LCD keypad panels. Everything is taken care of by the panel controller and your Arduino needs neither LCD library nor keypad library.

Well the RTC module has been working quite well for some time now, I've only encountered one issue: Daylight savings time. I figured I could just recompile the program on my computer and count on it working like it has in the past, grabbing the time off my computer, which does account for daylight savings time. Unfortunately though, the serial monitor displays the time an hour ahead when I try to re-upload the program.

My solution in the meantime is to change the times for 'sunrise' (dim on) and 'sunset' (dim off) accordingly, which I suppose works, however I was wondering if there was an easier way of doing this?

Have an interactive interface with lcd and buttons so you can change time without recompiling code. I have an alarm code you can use as reference though.