-
Notifications
You must be signed in to change notification settings - Fork 3
/
IIC_Scan_2.ino
55 lines (50 loc) · 1.12 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: IIC_Scan_2.cpp
* @version: V1.0.0
* @Author: LILYGO_L
* @Date: 2023-11-23 10:26:49
* @LastEditors: LILYGO_L
* @LastEditTime: 2023-12-20 15:39:31
* @License: GPL 3.0
*/
#include <Arduino.h>
#include <Wire.h>
#define SDA 17
#define SCL 18
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);
}