To keep costs low, the Raspberry Pi does not include a Real Time Clock module. Instead, users are expected to have it always connected to WiFi or Ethernet and keep time by checking the network. Since we want to include an external module, we'll have to wire one up. We'll go with the easy-to-use and low-cost DS1307. To make the job really easy, we'll use the the Adafruit DS1307 RTC Breakout Board Kit - it comes with all the parts you need, just add a coin battery!
The Kit does require a little light soldering. In theory you could use all the parts and build them onto a breadboard, but the coin holder is a little difficult since its not breadboard-friendly, so please go ahead and build the kit.
When building the kit, leave out the 2.2KΩ resistors - by leaving them out, we force the RTC to communicate at 3.3V instead of 5V, which is better for the Pi!
Wiring is simple:
- Connect VCC on the breakout board to the 5.0V pin of the Pi
- Connect GND on the breakout board to the GND pin of the Pi
- Connect SDA on the breakout board to the SDA pin of the Pi
- Connect SCL on the breakout board to the SCL pin of the Pi
DONT FORGET TO POWER IT FROM 5V - THIS IS FINE AND SAFE FOR THE PI - JUST MAKE SURE TO REMOVE THE 2.2K PULLUPS AS MENTIONED IN THE LARGE RED BOX UP ABOVE TO KEEP THE I2C PINS AT 3.3V LOGIC LEVELS
You'll also need to set up i2c on your Pi, to do so, check out our tutorial on Raspberry Pi i2c setup and testing at http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c
Reboot once you've done that with sudo reboot
Verify your wiring by running sudo i2cdetect -y 1 at the command line, you should see ID #68 show up - that's the address of the DS1307!
If you have an older Pi 1, you will have to run sudo i2cdetect -y 0 as the I2C bus address changed from 0 to 1