Skip to content

Instantly share code, notes, and snippets.

@EnsekiTT
Created June 24, 2013 09:23
Show Gist options
  • Save EnsekiTT/5848829 to your computer and use it in GitHub Desktop.
Save EnsekiTT/5848829 to your computer and use it in GitHub Desktop.
I2Cスキャナ。何がつながってるかわからないので0x00を送って受け取ってくれるかどうかを調べる。
#include <Wire.h> //I2C Arduino Library
int i,j;
void setup(){
//Initialize Serial and I2C communications
Serial.begin(38400);
Wire.begin();
j = 0;
Serial.println("init");
}
void loop(){
Wire.beginTransmission(j);
Wire.write(0x00);
i = Wire.endTransmission();
if(i == 0){
Serial.print(j,HEX);
Serial.print(",");
Serial.println(i);
}
j++;
if(j > 0xFF){
Serial.println("Over");
while(1){
delay(1000);
}
}
delay(25);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment