{"id":302,"date":"2021-08-14T16:30:17","date_gmt":"2021-08-14T15:30:17","guid":{"rendered":"https:\/\/fletch.scot\/wp\/?p=302"},"modified":"2021-08-14T16:35:06","modified_gmt":"2021-08-14T15:35:06","slug":"setting-the-time-on-a-ds1307-rtc-without-gps-or-ntp","status":"publish","type":"post","link":"https:\/\/fletch.scot\/wp\/?p=302","title":{"rendered":"Setting the time on a DS1307 RTC without GPS or NTP"},"content":{"rendered":"<p>I\u2019m going to use a real-time clock (RTC) in a future WSPR project so that I can start transmitting at the start of a minute. I\u2019ve never used an RTC before so I thought I\u2019d better fix that. I got a <a href=\"https:\/\/hobbycomponents.com\/rtc\/58-tiny-rtc-i2c-at24c32-ds1307-real-time-clock-module-with-eeprom-arm-pic\">DS1307 RTC from Hobby Components<\/a>. This module comes with an Arduino library to drive the I2C connection so I\u2019m using a SEM01K Arduino Nano clone to drive it. As you can see the wiring is simple, just ground, 5V, and the two wires for I2C.<\/p>\n<p>Typically you might set the time on an RTC using a GPS module or over the Ethernet from an NTP server. I don\u2019t currently have either a GPS module or an Arduino Ethernet module so neither method is immediately available to me. But I do have a MacBook Pro whose time is set by a local NTP server. So I wrote a small Arduino sketch to set the RTC time from the Mac. The procedure to set the time is a bit manual but it only needs done once as the RTC is kept alive by a battery.<\/p>\n<p>From the sketch:<\/p>\n<pre>\/\/ To run:<br \/>\/\/ 1) compile and upload this sketch<br \/>\/\/ 2) on a Mac terminal do: cat &lt; \/dev\/cu.usbserial-14430<br \/>\/\/ where \/dev\/cu.usbserial-14430 is the Arduino device<br \/>\/\/ 3) on another Mac terminal do: date \"+%y\/%m\/%d_%H:%M:%S\" &gt;&gt; \/dev\/cu.usbserial-14430<br \/>\/\/ the date and time is output<br \/>\/\/ 4) Kill (^C) the cat.<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IMG_0126.jpeg\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2021\/08\/IMG_0126.jpeg\" alt=\"Arduino and RTC \" width=\"450\" height=\"600\" border=\"0\" \/><\/p>\n<p>To check that I could use the RTC after the date and time is set I also wrote a little demo sketch which turns on the Arduino internal LED for two seconds at the start of each minute.<\/p>\n<p>The sketches are in this <a href=\"https:\/\/fletch.scot\/code\/RTCsketches.zip\">ZIP file<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m going to use a real-time clock (RTC) in a future WSPR project so that I can start transmitting at the start of a minute. I\u2019ve never used an RTC before so I thought I\u2019d better fix that. I got a DS1307 RTC from Hobby Components. This module comes with an Arduino library to drive &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/fletch.scot\/wp\/?p=302\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting the time on a DS1307 RTC without GPS or NTP&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[5],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","tag-programming"],"_links":{"self":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=302"}],"version-history":[{"count":2,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/302\/revisions"}],"predecessor-version":[{"id":305,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/302\/revisions\/305"}],"wp:attachment":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}