環境
OS: windows7 64bit
IDE: Arduino 1.6.9
Contents
概要
リアルタイムクロック(RTC)モジュールTinyRTC(DS1307)を使ってみました。
ピンヘッダで端子を作る必要があります。
準備
ライブラリの準備
1. ライブラリのダウンロード
2. Zipの展開と配置
私の環境の場合、
%USERPROFILE%\Documents\Arduino\libraries
または
C:\Users\*ユーザ名*\Documents\Arduino\libraries
3.Open the code directly by the path:File -> Example ->RTC.
結線
1.「Bat」:バックアップ電圧(DS1307 3番ピン)
2.「Gnd」:GND
3.「Vcc」:VCC(5V)
4.「Sda」:SDA(I2C)
5.「Scl」:SCL(I2C)
6.「DS」:DS18B20 I/O
7.「SQ」:クロックパルス出力(1Hz、4.096kHz、8.192kHz、32.768kHz)
下のサンプルスケッチでは、2~6側の端子を使っています。
サンプルスケッチ
参考: https://www.elecrow.com/wiki/index.php?title=Tiny_RTC#Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include <Wire.h> #include "RTClib.h" RTC_DS1307 RTC; void setup () { Serial.begin(9600); Wire.begin(); RTC.begin(); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } } void loop () { DateTime now = RTC.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); delay(1000); } |
実行結果
その他
2165/165/165 165:165:85 というエラーに悩まされた
サンプルスケッチを動作させると「RTC is NOT running!」と表示された後、ずっと
「2165/165/165 165:165:85」が出力される事象が発生しました。
私の場合、上記の件はモジュールとピンをはんだ付けしていなかったことによる接触不良が原因でした。
参考
[toggle heading=”h3″ title=”参考” ]
秋月電子のHPでは以下のデータをダウンロードすることができます。
取扱説明書
回路図
DS1307 PDFデータシート
EEPROM PDFデータシート
[/toggle]