add i2c master scan
This commit is contained in:
1 parent
74b2463953
commit
e43abed51c
1 file changed
+28
@@ -0,0 +1,28 @@
|
||||
#include <Wire.h>
|
||||
|
||||
TwoWire *wi = &Wire;
|
||||
//TwoWire *wi = &Wire1;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200); // start serial for output
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
wi->begin(); // join i2c bus (address optional for master)
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Scanning address from 0 to 127");
|
||||
for (int addr = 1; addr < 128; addr++)
|
||||
{
|
||||
wi->beginTransmission(addr);
|
||||
if ( 0 == wi->endTransmission() )
|
||||
{
|
||||
Serial.print("Found: 0x");
|
||||
Serial.print(addr, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
Reference in new issue
Block a user