forked from Xinyuan-LilyGO/LilyGo-Modem-Series
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQWIIC_I2C_Scan.ino
More file actions
74 lines (62 loc) · 1.95 KB
/
QWIIC_I2C_Scan.ino
File metadata and controls
74 lines (62 loc) · 1.95 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file QWIIC_I2C_Scan.ino
* @author Lewis He (lewishe@outlook.com)
* @license MIT
* @copyright Copyright (c) 2025 ShenZhen XinYuan Electronic Technology Co., Ltd
* @date 2025-09-05
* @note The example uses Standard Series pins by default. For other boards, please refer to Change Available GPIO.
*/
#include <Arduino.h>
#include <Wire.h>
#define QWIIC_SDA_PIN (3)
#define QWIIC_SCL_PIN (2)
// The default is the UART port, which is used to configure the second I2C port
#define QWIIC_UART_TX_PIN (43)
#define QWIIC_UART_RX_PIN (44)
uint32_t deviceScan(TwoWire &_port)
{
uint8_t err, addr;
int nDevices = 0;
for (addr = 1; addr < 127; addr++) {
_port.beginTransmission(addr);
err = _port.endTransmission();
if (err == 0) {
Serial.print("I2C device found at address 0x");
if (addr < 16)
Serial.print("0");
Serial.print(addr, HEX);
Serial.println(" !");
nDevices++;
} else if (err == 4) {
Serial.print("Unknow error at address 0x");
if (addr < 16)
Serial.print("0");
Serial.println(addr, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("Done\n");
return nDevices;
}
void setup()
{
Serial.begin(115200);
while (!Serial) {}
Serial.println("QWIIC I2C Scanner");
// Change the Qwiic UART port to an I2C port
Wire.begin(QWIIC_UART_TX_PIN, QWIIC_UART_RX_PIN);
// Initialize the Qwiic I2C port
Wire1.begin(QWIIC_SDA_PIN, QWIIC_SCL_PIN);
Serial.println("Please note that the UART port does not have an I2C pull-up resistor and is configured for I2C function.");
}
void loop()
{
Serial.println("Scanning I2C bus 0 ...");
deviceScan(Wire);
delay(5000);
Serial.println("Scanning I2C bus 1 ...");
deviceScan(Wire1);
delay(5000);
}