-
Notifications
You must be signed in to change notification settings - Fork 2
/
ESP32_I2Cscanner2.ino
49 lines (42 loc) · 1.09 KB
/
ESP32_I2Cscanner2.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
// ESP32 I2C Scanner
// Based on code of Nick Gammon http://www.gammon.com.au/forum/?id=10896
// ESP32 DevKit - Arduino IDE 1.8.5
// Device tested PCF8574 - Use pullup resistors 3K3 ohms !
// Gustavo Murta - 19/02/2018
// PCF8574 Default Freq 100 KHz
#include <Wire.h>
# define SDApin 21
# define SCLpin 22
void setup()
{
Serial.begin (115200);
Wire.begin (SDApin, SCLpin); // sda= GPIO_21 /scl= GPIO_22
}
void Scanner ()
{
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i); // Begin I2C transmission Address (i)
if (Wire.endTransmission () == 0) // Receive 0 = success (ACK response)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX); // PCF8574 7 bit address
Serial.println (")");
count++;
}
}
Serial.print ("Found ");
Serial.print (count, DEC); // numbers of devices
Serial.println (" device(s).");
}
void loop()
{
Scanner ();
delay (100);
}