arduinoにRTC接続
 以前ESP32で試したRTC_DS1307について、arduino NANO にSDcardへのデータ記録が出来ることが確認できたことから、データ記録には時刻が必要ではと思い試してみた。
 ネットワークへの接続が出来ればNTPによる時刻の取得も出来るがNANOにはそれもない。
 接続はI2Cのため他のI2Cセンサーと同じように接続する。

I2C   RTC   Arduino
GND   GND   GND
VCC   VCC   5V
SCL   SCL   A5
SDA   SDA   A4
------------------------------------------------------------------------------------
#include 
#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);
}
-------------------------------------------------------------------------------------------
 時刻がずれている場合は、下のように時刻調整部分をブロックの外に出して再コンパイル&転送する。
 現在時刻がコンパイルした時刻で設定される。 (理屈上数秒の遅れが出ます)。
-------------------------------------------------------------------------------------------
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__));
 }
 RTC.adjust(DateTime(__DATE__, __TIME__)); // ここに出す
}
------------------------------------------------------------------------------------------
シリアルモニターの表示、1秒毎に時間が表示される。
