{"id":225,"date":"2013-01-24T21:52:47","date_gmt":"2013-01-24T20:52:47","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=225"},"modified":"2014-05-09T22:47:19","modified_gmt":"2014-05-09T20:47:19","slug":"first-steps-with-arduino","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=225","title":{"rendered":"Arduino : display a clock based on a lcd screen and a RTC"},"content":{"rendered":"<p>I got my arduino for a few days now and here comes my first adventure :<br \/>\nuse an arduino + a <a href=\"http:\/\/dx.com\/p\/lcd-keypad-shield-for-arduino-duemilanove-lcd-1602-118059\" target=\"_blank\">lcd <\/a>+ a <a href=\"http:\/\/dx.com\/p\/ds1302-real-time-clock-module-with-battery-cr2032-126453\" target=\"_blank\">RTC <\/a> to display a clock.<\/p>\n<p><strong>First lets go with the wiring :<\/strong><\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/?attachment_id=231\" rel=\"attachment wp-att-231\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-231\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/lcd_keypad_bb-300x165.png\" alt=\"lcd_keypad_bb\" width=\"300\" height=\"165\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/lcd_keypad_bb-300x165.png 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/lcd_keypad_bb.png 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Then the code :<\/strong><\/p>\n<pre>\r\n\/\/ ds1302 library can be found here : http:\/\/www.henningkarlsen.com\/electronics\r\n\/\/\r\n\/\/ DS1302: RST \/ CE pin - Arduino Digital 12\r\n\/\/ I\/O \/ DAT pin - Arduino Digital 11\r\n\/\/ SCLK pin - Arduino Digital 10\r\n\/\/ LCD: DB7 - Arduino Digital 7\r\n\/\/ DB6 - Arduino Digital 6\r\n\/\/ DB5 - Arduino Digital 5\r\n\/\/ DB4 - Arduino Digital 4\r\n\/\/ RS - Arduino Digital 8\r\n\/\/ E - Arduino Digital 9\r\n\/\/ RW to ground?\r\n\r\n\r\n\/\/seems it is better to NOT plug VCC when setting the clock...\r\n\r\n#include <LiquidCrystal.h>\r\n#include <DS1302.h>\r\n\r\n\/\/ Init the DS1302\r\n\/\/DS1302(ce, data, clock);\r\nDS1302 rtc(12,11,10);\r\n\r\n\/\/ Init the LCD\r\nLiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );\r\n\r\nvoid set_time() {\r\nrtc.setDOW(SUNDAY); \/\/ Set Day-of-Week to FRIDAY\r\nrtc.setTime(19, 2, 0); \/\/ Set the time to 12:00:00 (24hr format)\r\nrtc.setDate(13, 1, 2013); \/\/ Set the date to August 6th, 2010\r\n}\r\n\r\nvoid setup()\r\n{\r\nSerial.begin(9600);\r\n\/\/ Set the clock to run-mode, and disable the write protection\r\nrtc.halt(false);\r\nrtc.writeProtect(false);\r\n\/\/ Setup LCD to 16x2 characters\r\nlcd.begin(16, 2);\r\n\r\n\/\/ The following lines can be commented out to use the values already stored in the DS1302\r\n\/\/set_time();\r\n}\r\n\r\nvoid loop()\r\n{\r\n\/\/ Display time centered on the upper line\r\nlcd.setCursor(4, 0);\r\nlcd.print(rtc.getTimeStr());\r\n\r\n\/\/ Display abbreviated Day-of-Week in the lower left corner\r\nlcd.setCursor(0, 1);\r\nlcd.print(rtc.getDOWStr(FORMAT_SHORT));\r\n\r\n\/\/ Display date in the lower right corner\r\nlcd.setCursor(6, 1);\r\nlcd.print(rtc.getDateStr());\r\n\r\nSerial.print(rtc.getTimeStr());\r\nSerial.print(\" \");\r\nSerial.print(rtc.getDOWStr(FORMAT_SHORT));\r\nSerial.print(\" \");\r\nSerial.println(rtc.getDateStr());\r\n\r\n\/\/ Wait one second before repeating :)\r\ndelay (1000);\r\n}\r\n<\/pre>\n<p><strong>And finally a nice picture to illustrate it :<\/strong><\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/IMG_2013-01-24_213950.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-228\" title=\"IMG_2013-01-24_213950\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/IMG_2013-01-24_213950-300x189.jpg\" alt=\"\" width=\"300\" height=\"189\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/IMG_2013-01-24_213950-300x189.jpg 300w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/01\/IMG_2013-01-24_213950-1024x647.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Hope you&rsquo;ll enjoy it as much as I did \ud83d\ude42<\/p>\n<p>\/Erwan<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got my arduino for a few days now and here comes my first adventure : use an arduino + a lcd + a RTC to display a clock. First lets go with the wiring : Then the code : \/\/ ds1302 library can be found here : http:\/\/www.henningkarlsen.com\/electronics \/\/ \/\/ DS1302: RST \/ CE <a href='https:\/\/labalec.fr\/erwan\/?p=225' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-arduino","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225"}],"version-history":[{"count":12,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":1205,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/225\/revisions\/1205"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}