[아두이노] I2C 장비 주소 찾는 방법!!
센서등 I2C 장비 주소를 모를때가 있습니다
아래 아두이노 코드로 쉽게 I2C 장배 주소를 확인할 수 있습니다
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(115200);
}
void loop() {
byte Error, address;
int DeviceCount;
Serial.println("Scanning I2C devices...");
DeviceCount = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
Error = Wire.endTransmission();
if (Error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
DeviceCount++;
}
else if (Error==4) {
Serial.print("Unknown Error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (DeviceCount == 0) {
Serial.println("No I2C devices found!");
}
else {
Serial.println("Success!\n");
}
delay(5000);
}