I have a Real Time Clock board (TinyRTC V1.1) from Arduino kit but suspected it was faulty or needed a new battery as it was not keeping time on the Arduino. Having a raspberry pi zero I decided to investigate using this.
The raspberry pi zero does not have it's own RTC and uses Network Time Protocol servers to get it's time when connected to a network. It also has kernel modules for dealing with the DS1307 on the (TinyRTC V1.1) .
After a quick Google (other search engines are available) I found this article RTC Pi on a Raspberry Pi with Raspbian , the first part shows how to set up the DS1307 as hwclock device. by using "sudo hwclock -r" gives the DS1307 time "Wed 04 Jan 2017 18:25:55 GMT -0.965293 seconds" which can be compared against "date" giving time and date in the format Wed 04 Jan 09:25:55 GMT 2017" this is from the NTP servers set up when connected to a network.
The details of NTP client are explained here http://raspberrypi.tomasgreno.cz/ntp-client-and-server.html. It looks like the NTP client is pre installed on Raspbian Jessie. This should give me a reference for my RTC.
I used "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device" to link in my RTC. So decided to have a poke around in "/sys/class/i2c-adapter/i2c-1".
ls /sys/class/i2c-adapter/i2c-1
1-0068 device name of_node subsystem
delete_device i2c-dev new_device power uevent
1-0068 look a interesting place to go?
ls /sys/class/i2c-adapter/i2c-1/1-0068
driver modalias name nvram power rtc subsystem uevent
Going down gave.
ls /sys/class/i2c-adapter/i2c-1/1-0068/rtc/rtc0
date device max_user_freq power subsystem uevent
dev hctosys name since_epoch time
And at the bottom
cat /sys/class/i2c-adapter/i2c-1/1-0068/rtc/rtc0/time
08:49:05
gave up the time and "cat /sys/class/i2c-adapter/i2c-1/1-0068/rtc/rtc0/date" gave up the date in 2017-01-04 format.
cat /sys/class/rtc/rtc0/time
09:47:44
also gives time. Both are only there when DS1307 is installed via "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device" from "sudo bash"
The raspberry pi zero keeps the time when not connected to network in "fake-hwclock" so the bash commands line "cat /etc/fake-hwclock.data" returns date time in this format "2017-01-04 10:17:01"
All I need do now is to run a long time test and compare the NTP time with RTC time..........
After 6 days manual checking I can say my Real Time Clock board is working fine.
ReplyDelete