Skip to content

Commit f51a510

Browse files
authored
Add files via upload
1 parent 9d1aab3 commit f51a510

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Lab-MPU6050/i2cScanner.ino

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ESP32 I2C Scanner
2+
// Based on code of Nick Gammon http://www.gammon.com.au/forum/?id=10896
3+
// ESP32 DevKit - Arduino IDE 1.8.5
4+
// Device tested PCF8574 - Use pullup resistors 3K3 ohms !
5+
// PCF8574 Default Freq 100 KHz
6+
7+
#include <Wire.h>
8+
9+
void setup()
10+
{
11+
Serial.begin (115200);
12+
Wire.begin (21, 22); // sda= GPIO_21 /scl= GPIO_22
13+
}
14+
15+
void Scanner ()
16+
{
17+
Serial.println ();
18+
Serial.println ("I2C scanner. Scanning ...");
19+
byte count = 0;
20+
21+
Wire.begin();
22+
for (byte i = 8; i < 120; i++)
23+
{
24+
Wire.beginTransmission (i); // Begin I2C transmission Address (i)
25+
if (Wire.endTransmission () == 0) // Receive 0 = success (ACK response)
26+
{
27+
Serial.print ("Found address: ");
28+
Serial.print (i, DEC);
29+
Serial.print (" (0x");
30+
Serial.print (i, HEX); // PCF8574 7 bit address
31+
Serial.println (")");
32+
count++;
33+
}
34+
}
35+
Serial.print ("Found ");
36+
Serial.print (count, DEC); // numbers of devices
37+
Serial.println (" device(s).");
38+
}
39+
40+
void loop()
41+
{
42+
Scanner ();
43+
delay (100);
44+
}

0 commit comments

Comments
 (0)