{"id":923,"date":"2015-08-01T23:35:21","date_gmt":"2015-08-01T14:35:21","guid":{"rendered":"https:\/\/hack.gpl.jp\/?p=923"},"modified":"2015-08-01T23:35:21","modified_gmt":"2015-08-01T14:35:21","slug":"post-923","status":"publish","type":"post","link":"https:\/\/hack.gpl.jp\/2015\/08\/01\/post-923.html","title":{"rendered":"Tiny RTC DS1307 I2C \u305d\u306e\uff12"},"content":{"rendered":"
\u6691\u304f\u3066\u3001\u590f\u5230\u6765\u3067\u3059\u306d\u30028\u6708\u306b\u5165\u3063\u3066\u3001\u307e\u305f\u4eca\u5e74\u3082\u6691\u3044\u590f\u304c\u3084\u3063\u3066\u304d\u307e\u3057\u305f\uff01<\/p>\n
\u663c\u9593\u306f\u3068\u3066\u3082\u3001PC\u89e6\u308b\u6c17\u306b\u306a\u3089\u306a\u3044\u306e\u3067\u81ea\u7136\u3068\u591c\u578b\u306b\u306a\u308a\u307e\u3059\u3002\u663c\u306f\u53cb\u9054\u3068\u304a\u8336\u3057\u3066\u3001\u69cb\u60f3\u3092\u7df4\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n
<\/p>\n
\u3055\u3066\u3001RTC \u3092\u534a\u7530\u4ed8\u3051\u3057\u3066\u914d\u7dda\u3057\u3066\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3092\u30b3\u30d4\u30da\u3057\u3066\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
ProMini \u306b\u3064\u3051\u3066\u307f\u307e\u3057\u305f\u3002\u914d\u7dda\u306f4\u672c\u3067\u30012\u672c\u306f\u96fb\u529b\u30012\u672c\u304c\u30c7\u30fc\u30bf\u901a\u4fe1\u3067\u3059\u3002ProMini \u306eA4(SDA) \u3068 A5(SCL) \u304c\u3069\u3053\u306b\u3042\u308b\u306e\u304b\u308f\u304b\u3089\u305a\u3001\u30d4\u30f3\u3092\u3064\u3051\u308b\u524d\u306e\u3092\u898b\u3066\u5224\u660e\u3002<\/p>\n
<\/p>\n
\u3068\u308a\u3042\u3048\u305a\u3001\u3053\u3093\u306a\u611f\u3058\u3067PC \u306b\u30b7\u30ea\u30a2\u30eb\u7d4c\u7531\u3067\u30c7\u30fc\u30bf\u3092\u6d41\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
<\/p>\n
\u30b7\u30ea\u30a2\u30eb\u901a\u4fe1\u306b\u3001\u6642\u304c\u6d41\u308c\u3066\u3001\u96fb\u6e90\u3092\u5207\u3063\u3066\u518d\u63a5\u7d9a\u3057\u3066\u3082\u3001\u5f53\u7136\u306a\u304c\u3089\u6642\u304c\u523b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u30d7\u30ed\u30b0\u30e9\u30e0\u30bd\u30fc\u30b9\u306f\u4ee5\u4e0b\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n
\/*\n Tiny RTC (DS1307) Sample.\n RTClib.h\n --> https:\/\/github.com\/jcw\/rtclib\n\n JunkHack 2015.07.31(Fri)\n *\/\n\n#include <Wire.h> \/\/ Wire lib.\n#include "RTClib.h" \/\/ need to install the RTClib by jcw\n\nRTC_DS1307 RTC; \/\/ RTC Modul\n\nvoid setup(void) {\n\n Wire.begin(); \/\/ Initialisiere I2C\n RTC.begin(); \/\/ Initialisiere RTC\n Serial.begin(9600);\n\n \/\/ Set SQW\/Out signal frequency to 1 Hz.\n RTC.setSqwOutSignal(RTC_DS1307::Frequency_1Hz);\n\n \/\/ Serial mes.\n Serial.print(__DATE__ " " __TIME__); \/\/ \u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u305f\u3068\u304d\u306e\u65e5\u6642\u3000Aug 1 2015 13:24:48\n Serial.println(" : Tiny RTC DS1307 I2C --- test");\n\n \/\/ RTC \u306b\u30af\u30ed\u30c3\u30af\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u308b\u304b\uff1f\n if (! RTC.isrunning()) {\n\n \/\/ \u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306e\u3001\u73fe\u5728\u306e\u65e5\u4ed8\u3068\u6642\u523b\u3092\u8a2d\u5b9a\n RTC.adjust(DateTime(__DATE__, __TIME__)); \/\/ IDE \u306e PC \u6642\u523b\n Serial.println("Current time to the RTC");\n }\n else Serial.println("RTC\u306f\u3001\u3059\u3067\u306b\u5b9f\u884c\u3055\u308c\u3066\u3044\u307e\u3059\u3002");\n}\n\nvoid loop(){\n DateTime now=RTC.now(); \/\/ Current time geting from RTC\n show_time_and_date(now); \/\/ Print Serial\n delay(1000); \/\/ 1 Sec\n}\n\n\/\/ set week\nString get_day_of_week(uint8_t dow){\n\n String dows=" ";\n switch(dow){\n case 0: dows="Sun"; break;\n case 1: dows="Mon"; break;\n case 2: dows="Tue"; break;\n case 3: dows="Wed"; break;\n case 4: dows="Thu"; break;\n case 5: dows="Fri"; break;\n case 6: dows="Sat"; break;\n }\n\n return dows;\n}\n\n\/\/ print date time. ex 2015.07.31(Fri) 23:22:31\nvoid show_time_and_date(DateTime datetime){\n \/\/ 2015.07.31(Fri) \n Serial.print(datetime.year(),DEC);\n Serial.print(".");\n if(datetime.month()<10)Serial.print(0);\n Serial.print(datetime.month(),DEC);\n Serial.print(".");\n if(datetime.day()<10)Serial.print(0);\n Serial.print(datetime.day(),DEC);\n Serial.print("(");\n Serial.print(get_day_of_week(datetime.dayOfWeek()));\n Serial.print(") ");\n\n \/\/ Time 23:22:31\n if(datetime.hour()<10)Serial.print(0);\n Serial.print(datetime.hour(),DEC);\n Serial.print(":");\n if(datetime.minute()<10)Serial.print(0);\n Serial.print(datetime.minute(),DEC);\n Serial.print(":");\n if(datetime.second()<10)Serial.print(0);\n Serial.println(datetime.second(),DEC);\n}<\/pre>\n\u5b9f\u969b\u306b\u52d5\u304b\u3057\u3066\u307f\u308b\u3068\u3001\u306a\u308b\u307b\u3069\u30fc\u3068\u3044\u3046\u611f\u3058\u3067\u5b9f\u611f\u304c\u6cb8\u304d\u307e\u3059\u3002\u6642\u523b\u306fIDE \u306e PC \u304b\u3089\u306e\u6642\u523b\u3092\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u5b9a\u6570\u306b\u6e21\u3057\u3066\u305d\u308c\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3044\u308b\u611f\u3058\u3067\u3059\u306e\u3067\u3001\u8ee2\u9001\u5b8c\u4e86\u307e\u3067\u30bf\u30a4\u30e0\u30e9\u30b0\u304c\u3042\u308a\u3001\u6b63\u78ba\u306b\u30bb\u30c3\u30c8\u3059\u308b\u306b\u306f\u5de5\u592b\u304c\u5fc5\u8981\u3060\u3068\u308f\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u6691\u304f\u3066\u3001\u590f\u5230\u6765\u3067\u3059\u306d\u30028\u6708\u306b\u5165\u3063\u3066\u3001\u307e\u305f\u4eca\u5e74\u3082\u6691\u3044\u590f\u304c\u3084\u3063\u3066\u304d\u307e\u3057\u305f\uff01 \u663c\u9593\u306f\u3068\u3066\u3082\u3001PC\u89e6\u308b\u6c17\u306b\u306a\u3089\u306a\u3044\u306e\u3067\u81ea\u7136\u3068\u591c\u578b\u306b\u306a\u308a\u307e\u3059\u3002\u663c\u306f\u53cb\u9054\u3068\u304a\u8336\u3057\u3066\u3001\u69cb\u60f3\u3092\u7df4\u3063\u3066\u3044\u307e\u3057\u305f\u3002 \u3055\u3066\u3001RTC \u3092\u534a\u7530\u4ed8\u3051\u3057\u3066\u914d […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[9,63],"tags":[],"acf":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"JunkHack","author_link":"https:\/\/hack.gpl.jp\/author\/junkhack\/"},"uagb_comment_info":0,"uagb_excerpt":"\u6691\u304f\u3066\u3001\u590f\u5230\u6765\u3067\u3059\u306d\u30028\u6708\u306b\u5165\u3063\u3066\u3001\u307e\u305f\u4eca\u5e74\u3082\u6691\u3044\u590f\u304c\u3084\u3063\u3066\u304d\u307e\u3057\u305f\uff01 \u663c\u9593\u306f\u3068\u3066\u3082\u3001PC\u89e6\u308b\u6c17\u306b\u306a\u3089\u306a\u3044\u306e\u3067…","_links":{"self":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/posts\/923"}],"collection":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/comments?post=923"}],"version-history":[{"count":0,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/posts\/923\/revisions"}],"wp:attachment":[{"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/media?parent=923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/categories?post=923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hack.gpl.jp\/wp-json\/wp\/v2\/tags?post=923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}