Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====Adding a DS3231 Real Time Clock To The Raspberry Pi, module DS3231 or DS1307==== {{ :fr:documents:sku196722-3.jpg?direct&150 |}} ===Activation I2C et installation of Real Time Clock=== In order to ensure you have got the latest updates you should run the following commands : <code bash> sudo apt-get update sudo apt-get upgrade sudo apt-get install i2c-tools </code> I2C activation on Raspberry Pi <code bash> sudo raspi-config </code> Choose **8-Advanced Options** -> **A7 I2C** answer **Yes** and press enter -> **Ok** -> **Yes** -> **Ok** Now we need to modify a system file using : <code bash> sudo nano /etc/modules </code> If it isn't already there add rtc-ds1307 to the bottom so it looks something like : <code python | modules> snd-bcm2835 i2c-bcm2835 i2c-dev rtc-ds1307 </code> You can save and quit using CTRL-X, Y and ENTER. restart the system <code bash> sudo reboot </code> Test of I2C interface Power up the Pi and run the following command : <code bash> sudo i2cdetect -y 1 </code> {{ :fr:documents:ds3231_rtc_module_01.png?nolink&500 |}} <WRAP center round important 60%> If you are using a Rev 1 you will need to use sudo i2cdetect -y 0.</WRAP> ===Commands:=== You can read the Pi system time using : <code bash> date </code> If you need to set the system time for any reason you can use the following command : <code bash> sudo date -s "29 AUG 2015 13:00:00" </code> Once correct you can write the system date and time to the RTC module using : <code bash> sudo hwclock -w </code> Should be able to read the date and time back from the RTC using : <code bash> sudo hwclock -r </code> ===Setup auto update of system date and time :=== ==Update with reboot== Synchronize DS1307 ou DS3231 ;you need add 2 lines in system file: <code bash> sudo nano /etc/rc.local </code> Add the following two lines before the exit 0 line : use the line that corresponds to your version (Raspberry Pi V1) <code bash> echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device hwclock -s </code> (Raspberry Pi V2) <code bash> echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device hwclock -s </code> like this: {{ :fr:documents:ds1308_rtc_module_06.png?nolink&500 |}} reboot system <code bash> sudo reboot </code> ==Auto update daily== For autoupdated daily you need addd line in CRON files [[https://en.wikipedia.org/wiki/Cron#crontab|CRON]] <code bash> sudo crontab -e </code> Clock updated every day at 11h30pm, add folowed lines: <code bash> 30 23 * * * hwclock -s </code> You can save and quit using CTRL-X, Y and ENTER. <WRAP center round tip 60%> Force clock update using ntp <code bash> sudo service ntp stop sudo ntpd -gq sudo service ntp start </code> </WRAP> en/horloge_externe_ds3231.txt Last modified: 2020/07/05 17:13(external edit)