mdleiton / rpi.rtc

Simple Python module to deal with DS1302 RTC chip on Raspberry Pi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rpi.rtc

Simple Python module to deal with DS1302 RTC on Raspberry Pi

Wire map (default conf.)

Chip Rpi pin
VCC 3.3v pin
GND GND pin
CLK pin 11
DATA pin 13
CE (RST) pin 15

Setup

sudo apt-get -y install python3-rpi.gpio
sudo python3 setup.py install

Read RTC chip date and time

ds1302_get_utc

RPi date and time (UTC) to RTC chip

ds1302_set_utc

Set date and time(UTC) from string to RTC chip

ds1302_set_utc_from_string "09/19/18 13:55:26"

Update Rpi system time from RTC chip

Typically call at RPi startup

sudo date -s `./ds1302_get_utc`

One line to check RTC chip time vs system time

Since RTC store only second and not millisecond a 1s delta can occur (or more after a few days)

# drift in second
echo $(($(date -u -d`ds1302_get_utc` +%s) - $(date -u +%s)))
# human readable
echo "RTC `ds1302_get_utc`"; echo "SYS `date --utc +%FT%TZ`";

About

Simple Python module to deal with DS1302 RTC chip on Raspberry Pi

License:MIT License


Languages

Language:Python 100.0%