-
Notifications
You must be signed in to change notification settings - Fork 0
/
IIC_Scan_2.ino
55 lines (50 loc) · 1.06 KB
/
IIC_Scan_2.ino
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* @Description: None
* @version: V1.0.0
* @Author: None
* @Date: 2024-07-29 16:28:31
* @LastEditors: LILYGO_L
* @LastEditTime: 2024-07-29 16:29:17
* @License: GPL 3.0
*/
#include <Arduino.h>
#include <Wire.h>
#define SDA YOU_SDA
#define SCL YOU_SCL
void scan_i2c_device(TwoWire &i2c)
{
Serial.println("Scanning for I2C devices ...");
Serial.print(" ");
for (int i = 0; i < 0x10; i++)
{
Serial.printf("0x%02X|", i);
}
uint8_t error;
for (int j = 0; j < 0x80; j += 0x10)
{
Serial.println();
Serial.printf("0x%02X |", j);
for (int i = 0; i < 0x10; i++)
{
Wire.beginTransmission(i | j);
error = Wire.endTransmission();
if (error == 0)
Serial.printf("0x%02X|", i | j);
else
Serial.print(" -- |");
}
}
Serial.println();
}
void setup()
{
Serial.begin(115200);
Serial.println("Ciallo");
Wire.begin(SDA, SCL);
scan_i2c_device(Wire);
}
void loop()
{
scan_i2c_device(Wire);
delay(1000);
}