Skip to content

Instantly share code, notes, and snippets.

@Tolerant
Last active January 26, 2019 17:16
Show Gist options
  • Save Tolerant/26a04b513becede834cfe8ec7a16d61b to your computer and use it in GitHub Desktop.
Save Tolerant/26a04b513becede834cfe8ec7a16d61b to your computer and use it in GitHub Desktop.
I2C scanner
// Robo India Tutorial
// Digital Input and Output on LED
// Hardware: NodeMCU
// scanner. Scanning ...
// 23:13:22.263 -> Found address: 39 (0x27)
// Done.
// 23:13:22.298 -> Found 1 device(s).
// Ref- Nick Gammon http://www.gammon.com.au/forum/?id=10896
// I2C Scanner
#include <Wire.h>
void setup() {
Serial.begin(115200);
while (!Serial) // Waiting for serial connection
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 0; 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); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment