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?

[I2C]8バイトをI2Cで受信して遊ぶ。

Last updated at Posted at 2025-10-27

参考

いろいろ注意

  • 過去ログがたくさん、あるので見てね!!!
  • m5nanoc6とuno3のペア
  • いろいろ、いろいろアップして、いたの教授だったんだ、小規模のマイコンは、限界性能が低いから、差がつきづらいんだ(何の事?
  • いろいろ、I2Cブザーは、毎日、1バイトづつ削て、行けば、動く予定?

目的

  • I2Cブザーのテスト

結果

Screenshot from 2025-10-28 07-48-52.png

image_original(82).jpg

プログラム



//I2C_Slave_8byte_test1_UNO3_2


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


//定義
volatile unsigned char buf[32+1] = {
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,
  0};


//初期化
void setup() {

  //シリアルポートの初期化
  Serial.begin(9600);

  //I2Cの初期化
  Wire.begin(  0x1e  );      // I2Cスレーブアドレスの設定
  Wire.onReceive(receiveEvent);  // データが来ると呼ばれる関数

}  //setup


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

  if (buf[0] != 0) { //空文では、ない場合

    delay(20); //[必要]ちょっと待つ(消すな)

    //受信データの出力
    Serial.print((char *)(&buf));
    Serial.println();

    buf[0] = 0; //空文

  }  //endif

  delay(3);  //ダミー

}  //loop


//レシーブイベント(受信)
void receiveEvent(int howMany) {

  int i = 0;
  while (0 < Wire.available() && (i < 32) ) {  // loop through all but the last

    // I2C受信データの読み込み
    buf[i++] = Wire.read();                    // receive byte as a character

  }  //while

}  //receiveEvent


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?