티스토리 뷰
728x90
반응형
I2C 통신에서 각 장치는 고유한 주소를 가지고 있어야 한다.
이 주소를 통해 마이크로컨트롤러가 특정 장치와 통신할 수 있으며,
같은 버스상에 여러 장치가 연결되어 있더라도 각각을 구분하여 제어할 수 있다.
아두이노에서 I2C 주소 찾는코드
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ ) {
// The i2c_scanner uses the return value of
// the Write.endTransmission to see if
// a device did acknowledge to the 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.print(address, HEX);
Serial.println(" !");
nDevices++;
}
else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
// Wait 5 seconds for the next scan
delay(5000);
}
Scanning...
I2C device found at address 0x23 !
I2C device found at address 0x3C !
I2C device found at address 0x5A !
I2C device found at address 0x60 !
I2C device found at address 0x6A !
done
0x23: 이 주소는 일반적으로 BH1750 조도 센서
0x3C 주소는 일반적으로 SSD1306 기반의 OLED 디스플레이
728x90
반응형
'Iot' 카테고리의 다른 글
아두이노 nano 33 IoT: LM386 스피커 모듈+ VL53L1X ToF 레이저 거리 측정 센서 (MQTT 통신) (0) | 2024.05.17 |
---|---|
아두이노_전구_릴레이 (0) | 2024.04.26 |
아두이노 _ 플로터 _DIY (GRBL CNC Shield + Z axis servo MIGRBL) + UGS (0) | 2024.04.21 |
아두이노 나노 33 IOT _ UART ? (0) | 2024.04.19 |
아두이노 -GPS 센서 (GY-NEO6MV2) (1) | 2024.04.18 |
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- three.js
- colab
- houdini
- ai film
- Python
- ai image generator
- krea
- AI
- imgtoimg
- VR
- runwayai
- docker
- Express
- CNC
- sequelize
- MCP
- Midjourney
- google ai studio
- TouchDesigner
- DeepLeaning
- opencv
- MQTT
- Unity
- 라즈베리파이
- RNN
- 유니티
- Arduino
- 후디니
- Java
- node.js
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함
반응형