Leeds, England
Offline
Full Member
Karma: 6
Posts: 184
Quick, chuck it in the bin before the boss finds out...
|
 |
« Reply #15 on: October 14, 2012, 05:22:48 pm » |
Any chance of a link to the RTC module you bought? Or is it a home brew?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #17 on: October 14, 2012, 05:42:09 pm » |
My confusion was the datasheet at the top has a picture of a 'typical operating circuit', which has both SDA and SCL with a pullup resistor to Vcc, however further down the datasheet it says only SDA needs the pullup resistor and SCL doesn't say anything about the resistor, only that it should have a pullup voltage of 5.5V? Possibly worded a little awkward, but 'have a pullup voltage...' means also having a pull-up resistor. The I2C standard dictates that both data and clock signal use external pull-ups as these signals are bidirectional so they cannot rely on one side always providing a valid logic voltage level output. The actual value of the pull-up resistor can depend on things like the speed the bus will be operated on, the number of slave modules wired to the bus, that total length of the bus, etc. But 4.7K ohms is a pretty standard recommendations. Now to confuse you further (not intended, really) one can sometime get away with wiring a I2C device to an arduino board with no pull-ups at all. That is because the arduino I2C library enables the internal 'weak pull-ups' on the open drain clock and data I2C pins. I've run a 1307 I2C RTC module with several of my arduino board without using external pull-ups and it works fine, however that is not per I2C standards and is not be a recommended practice. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
|
 |
« Reply #18 on: October 14, 2012, 05:55:25 pm » |
Hmm, interesting, I appreciate the informative post, though you are correct about me being confused  . 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.
|
|
|
|
|
Logged
|
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 35
Posts: 5915
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #19 on: October 14, 2012, 05:58:49 pm » |
You use the same setup I use on all my phi-1 and phi-2 shields (same source too), literally hundreds of them spread across the world. No reason it won't run unless you made some mistakes. First, make sure you have very short wires. Then make sure you did the pull-up correctly. Actual setup pictures are way better than your picture-perfect diagram. It is totally correct but whether you followed the diagram is up for debate. You can only end the debate by providing actual pictures. Is that clear enough? Correct connections won't produce this: 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. The following is not going to affect the output: One other thing I should note is I have SQW/OUT wired to nothing.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
|
 |
« Reply #20 on: October 14, 2012, 06:56:14 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #21 on: October 14, 2012, 07:02:44 pm » |
Hmm, interesting, I appreciate the informative post, though you are correct about me being confused  . 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
|
|
|
|
|
Logged
|
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 35
Posts: 5915
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #22 on: October 14, 2012, 07:14:46 pm » |
Come on with your pics already!!!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
|
 |
« Reply #23 on: October 14, 2012, 08:08:17 pm » |
Sorry!  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
|
|
|
|
« Last Edit: October 14, 2012, 08:10:42 pm by megamax42 »
|
Logged
|
|
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
|
 |
« Reply #25 on: October 15, 2012, 11:43:10 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 87
Posts: 9368
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #26 on: October 16, 2012, 01:23:58 pm » |
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 ?
|
|
|
|
|
Logged
|
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 35
Posts: 5915
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #27 on: October 16, 2012, 04:42:01 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
|
 |
« Reply #28 on: October 17, 2012, 12:57:56 am » |
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:162165/165/165 165:85:47 since 1970 = 2028815851s = 23481d now + 7d + 30s: 2034/4/23 15:58:12012/10/16 22:49:48 since 1970 = 1350427788s = 15629d now + 7d + 30s: 2012/10/23 22:50:182165/165/165 165:85:49 since 1970 = 2028815853s = 23481d now + 7d + 30s: 2034/4/23 15:58:32165/165/25 22:49:50 since 1970 = 2016202894s = 23335d now + 7d + 30s: 2033/11/28 16:22:42165/165/165 165:85:51 since 1970 = 2028815855s = 23481d now + 7d + 30s: 2034/4/23 15:58:52165/25/16 22:49:52 since 1970 = 1908548496s = 22089d now + 7d + 30s: 2030/7/1 16:22:6And 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? 
|
|
|
|
« Last Edit: October 17, 2012, 12:59:44 am by megamax42 »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 32
|
 |
« Reply #29 on: October 17, 2012, 01:07:13 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
|