First Commit
This commit is contained in:
38
i2c_test/i2c_test.ino
Normal file
38
i2c_test/i2c_test.ino
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <Wire.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin (57600);
|
||||
Wire.begin (); // 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 (10000);
|
||||
}
|
||||
Reference in New Issue
Block a user