1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

時計で遊ぶ。(シリアル出力)(M5NanoC6)

Last updated at Posted at 2024-10-08

x 過去ログを見よ!!
x 時間合わせは、別

目的
DS1307のテスト

結果

o_coq495.jpg

o_coq496.jpg

プログラム



//I2C_DS1307_M5NanoC6_1


//インクルド
#include <Arduino.h>
#include <Wire.h>   //I2C


//定義
// デバイスアドレス(スレーブ)
#define ADDR    0x68    // 2進数 1101000


//初期化
void setup()
{

  //シリアルの初期化処理
  Serial.begin(9600);
    
  //i2cの初期化処理
  Wire.begin(); // 1 2 NanoC6

} //setup


//メインループ
void loop()
{

  // レジスタのアドレスを先頭にする
  Wire.beginTransmission(ADDR);
  Wire.write(0x00);
  Wire.endTransmission();
  delay(1);

  // I2Cスレーブに8byteのレジスタデータを要求する
  Wire.requestFrom(ADDR, 8);

  // 8byteのデータを取得する
  char data_read[16] = {0x88, 0x88, 0x88}; //データバッファー
  int ii = 0;
  while (Wire.available())  {   // 要求より短いデータが来る可能性あり
    data_read[ii++] = Wire.read();       // 1バイトを受信
  }//while
  delay(1);

  //表示変換する パック二進化十進を文字列にする
  char cn1[16];  //桁
  cn1[0] = '0' + (data_read[2] >> 4);  //0 時 上位
  cn1[1] = '0' + (data_read[2] & 0xf); //1 時 下位
  cn1[2] = ':';
  cn1[3] = '0' + (data_read[1] >> 4);  //2 分 上位
  cn1[4] = '0' + (data_read[1] & 0xf); //3 分 下位
  cn1[5] = ':';
  cn1[6] = '0' + (data_read[0] >> 4);  //4 秒 上位
  cn1[7] = '0' + (data_read[0] & 0xf); //5 秒 下位
  cn1[8] = 0;

  Serial.println(cn1); //時刻を表示する

  delay(1000); //1秒待つ

} //loop



1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?