Pages

RTC Setup

One of the features I wanted to implement was the ability to keep time without a network connection. To do this, I needed a realtime clock. I found one at SparkFun that was flexible enough for my needs, based on the popular DS1307 chip.

After a bit of Google-probing I found another article on adding RTCs that stated that many other guides didn’t do it properly, or left out important steps.

I went through it. At every step, my sudo i2cdetect -y 1 was returning nothing. Not a 0x68 to be seen, not even a UU. (UU = In use by driver)

I ran through every step again. Still no sign of the clock.

I pulled out my trusty Arduino. About 15 minutes later, I had a sketch that requested the time from the clock. I uploaded it and found that Wire (Arduino’s name for I2C) has a bug in which endTransmission() and requestFrom() both hang for a variable amount of time before continuing.

Abandoning the debug attempt, I plugged my clock back into my Pi. I forgot which pins the clock was supposed to sit on, so I pulled up a pinout chart. It was then I found I had been using the wrong pins. I had the SCL in the right place, but the clock’s SDA was connected to GPIO pin 4. (facepalm)

Now it works perfectly – when I run

sudo hwclock

it will give me the time to within a 0.7s accuracy. I still need to adjust for drift, but it’s good enough for now.

Leave a Reply