{"id":287,"date":"2018-02-22T17:37:53","date_gmt":"2018-02-22T16:37:53","guid":{"rendered":"https:\/\/www.andreavinci.it\/blog\/?p=287"},"modified":"2024-02-06T08:49:58","modified_gmt":"2024-02-06T08:49:58","slug":"rapberry-pi-3-ds3231-real-time-clock","status":"publish","type":"post","link":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/en\/2018\/02\/22\/rapberry-pi-3-ds3231-real-time-clock\/","title":{"rendered":"Raspberry Pi 3 and DS3231 real time clock"},"content":{"rendered":"<p><em>Adding a Real Time Clock module to a Raspberry Pi can solve issues about time synchronization <!--more-->when an\u00a0Internet connection is not available. If your Raspberry Pi is not always connected to the Internet, and its system time messes up, you can install and configure a Real Time Clock module (RTC). This post shows how to install and configure a DS3231 module on a Raspberry Pi.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>When a Raspberry Pi is unplugged from the main power, its system time will reset on start-up, and then synchronized by exploiting the NTP protocol. If you have no Internet connection, it can cause a lot of issues for certain application, such as sensors monitor and logging. This problem can be solved by the exploitation of a real-time clock module.<\/p>\n<figure id=\"attachment_288\" aria-describedby=\"caption-attachment-288\" style=\"width: 138px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-288\" src=\"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/wp-content\/uploads\/2018\/02\/ds3231-300x300.jpg\" alt=\"\" width=\"138\" height=\"138\" srcset=\"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/wp-content\/uploads\/2018\/02\/ds3231-300x300.jpg 300w, https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/wp-content\/uploads\/2018\/02\/ds3231-150x150.jpg 150w, https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/wp-content\/uploads\/2018\/02\/ds3231.jpg 500w\" sizes=\"auto, (max-width: 138px) 100vw, 138px\" \/><figcaption id=\"caption-attachment-288\" class=\"wp-caption-text\">A DS3231 real-time clock (RTC) module<\/figcaption><\/figure>\n<p>After a little search on the web, I found the best guide for setting up the DS3231 real-time clock (RTC) module on the Raspberry Pi 3, here summarized.<\/p>\n<h5>Prerequisites<\/h5>\n<p>The following is tested on:<\/p>\n<ul>\n<li>A Raspberry Pi 3 mod B+, with Raspbian Stretch<\/li>\n<li>A DS3231 module,\u00a0 which can be bought\u00a0<a href=\"https:\/\/www.amazon.it\/Gaoxing-Tech-memoria-precisione-Raspberry\/dp\/B06XSJ974V\/ref=sr_1_5?ie=UTF8&amp;qid=1519313432&amp;sr=8-5&amp;keywords=ds3231\">here (amazon.it link)<\/a>.<\/li>\n<\/ul>\n<h5>Wiring the module<\/h5>\n<p>The DS3231 module can be physically installed using the adjacent pins 1-3-5-7-9 on the Raspberry Pi 3.<\/p>\n<h5>Software configuration<\/h5>\n<p>After that, only two steps are required:<\/p>\n<ol>\n<li>put the below line into the \/boot\/config.txt file:\n<pre>dtoverlay=i2c-rtc<span style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;\">,ds3231<\/span><\/pre>\n<\/li>\n<li>edit the \/lib\/udev\/hwclock-set file, so as to remove (or comment out) the following lines:\n<pre>if [ -e \/run\/systemd\/system ] ; then\n    exit 0\nfi<\/pre>\n<\/li>\n<\/ol>\n<h5>Testing<\/h5>\n<p>After reboot, you can test if all is ok by the\u00a0command:<\/p>\n<pre>$ sudo hwclock -r<\/pre>\n<p>which will show the current time from the RTC module.<\/p>\n<p>For further testing, you can try to\u00a0disable network connection, shutdown the system,\u00a0unplug the power cable, wait for a few minutes and then power on the raspberry. Finally, use the command:<\/p>\n<pre>$ date<\/pre>\n<p>for retrieving the system time and verifying\u00a0if it is consistent with the actual time.<\/p>\n<p>&nbsp;<\/p>\n<p>This is it.<\/p>\n<p>Main source: <a href=\"https:\/\/www.raspberrypi.org\/forums\/viewtopic.php?p=1043263&amp;sid=a21faed3373177fa366612cc0aff1065#p1043263\">The Raspberry Pi forums<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding a Real Time Clock module to a Raspberry Pi can solve issues about time synchronization<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[263,237],"tags":[21,216,24,34,37,39,45],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-blog","category-guides","tag-ds3231-it","tag-english-en","tag-howto-it","tag-postit","tag-raspberry-pi","tag-real-time-clock","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":1,"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"predecessor-version":[{"id":536,"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/287\/revisions\/536"}],"wp:attachment":[{"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staff.icar.cnr.it\/vinci\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}