Last active
February 27, 2020 19:16
-
-
Save vaderj/770645b4c34c946c588d to your computer and use it in GitHub Desktop.
#Arduino i2c scanner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I2C Scanner | |
// Written by Nick Gammon | |
// Date: 20th April 2011 | |
#include <Wire.h> | |
void setup() { | |
Serial.begin (115200); | |
Serial.println (); | |
Serial.println ("I2C scanner. Scanning ..."); | |
byte count = 0; | |
Wire.begin(); | |
for (byte i = 1; 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++; | |
} // end of good response | |
delay (5); // give devices time to recover | |
} // 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