Skip to content

Commit e43abed

Browse files
committed
add i2c master scan
1 parent 74b2463 commit e43abed

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <Wire.h>
2+
3+
TwoWire *wi = &Wire;
4+
//TwoWire *wi = &Wire1;
5+
6+
void setup()
7+
{
8+
Serial.begin(115200); // start serial for output
9+
while ( !Serial ) delay(10); // for nrf52840 with native usb
10+
wi->begin(); // join i2c bus (address optional for master)
11+
}
12+
13+
void loop()
14+
{
15+
Serial.println("Scanning address from 0 to 127");
16+
for (int addr = 1; addr < 128; addr++)
17+
{
18+
wi->beginTransmission(addr);
19+
if ( 0 == wi->endTransmission() )
20+
{
21+
Serial.print("Found: 0x");
22+
Serial.print(addr, HEX);
23+
Serial.println();
24+
}
25+
}
26+
27+
delay(5000);
28+
}

0 commit comments

Comments
 (0)