Skip to content

Instantly share code, notes, and snippets.

@sukesh-ak
Last active November 12, 2020 22:18
Show Gist options
  • Save sukesh-ak/680176a582c205490e6255bd5bf12b0f to your computer and use it in GitHub Desktop.
Save sukesh-ak/680176a582c205490e6255bd5bf12b0f to your computer and use it in GitHub Desktop.
i2c_scanner - useful when you are not sure of the i2c address for an i2c device. Works on multiple microcontroller
#include <Wire.h>
void setup() {
Serial.begin (115200);
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1);
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
}
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment