In Time
In the previous column we looked at the DS1307 real-time clock and the I2C bus. This month, we look at three more real-time clocks and compare all four.
In the previous column we looked at the DS1307 real-time clock and the I2C bus. This month, we look at three more real-time clocks and compare all four.
A real-time clock (RTC) is necessary for any project requiring accurate time-keeping, especially when you don't always have an Internet connection – for example, if you're sending a Raspberry Pi up in a balloon. The Raspberry Pi keeps pretty good time, but only if it is connected to the Internet. If you're not on the Internet, and you turn it off at, say, 10:43am and then turn it on at 12:34pm, the clock will resume at 10:43am and go forward.
The Pi uses an Internet service called NTP to set the clock on power-up if the Internet is available. It then calls the NTP servers (some are hosted by the National Institute of Standards and Technology [NIST] and linked to their atomic clocks). You aren't going to get atomic clock accuracy using NTP, but it's pretty good. Here, I used NTP to update the Raspberry Pi so I can use it to estimate the error rates of these RTCs.
I chose four popular RTCs to test. They had to meet the following criteria:
The chosen RTC boards are (top to bottom in Figure 1): the DS1307, the PCF8563, the DS3231, and the MCP79400. Each of these boards have different features and are compared in Table 1 (note the I2C addresses).
Table 1
Feature Comparison
Device | Board Name | I2C Address | Vendor | Power Supply | Price | Notes |
---|---|---|---|---|---|---|
MCP79400 |
BM005 Clock Calendar Module |
0x6F |
Solutions Cubed |
3.3V/5.0V |
US$ 12.00 |
4.7K pull-ups on SCL/SDA (64 bytes EEPROM); can trim +/-127ppm. No battery included |
DS1307 |
DS1307 RTC Breakout |
0x68 |
Adafruit |
5.0V |
US$ 9.00 |
Cut pull-up resistors on SCL/SDA to use on Raspberry Pi |
DS3231 |
High Precision RTC I2C |
0x68 |
Amazon.com |
3.3V/5.0V |
US$ 6.26 |
Best specs on error. Temperature compensated |
PCF8563 |
PCF8563T CMOS Real-time Clock/Calendar |
0x51 |
Amazon.com |
3.3V/5.0V |
US$ 9.00 |
4.7K pull-ups on SCL/SDA |
Listing 1 shows a scan of the I2C bus for the devices. Note that you don't see DS1307 mapped, because it conflicts with the DS3231 address, which is also 0x68. Additionally, 0x56 is the EPROM address on the MCP79400 board.
Listing 1
Scan of I2C Bus
pi@MouseAir2 /var/www $ sudo i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- 51 -- -- -- -- 56 -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- 6f 70: -- -- -- -- -- -- -- --
I hand-wired a prototype board to mount the four RTC boards and connect them to the Raspberry Pi I2C bus. The underside of the board is shown in Figure 2, and the full board with all of the RTCs mounted is shown poised on interesting reading material in Figure 3.
Pages: 6
Price $15.99
(incl. VAT)