Created
September 20, 2023 16:59
-
-
Save MarcoCiau/db58b59a4cae2a464f2e1bca09f7a731 to your computer and use it in GitHub Desktop.
Universal Arduino I2C Finder
This file contains 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
#include <Arduino.h> | |
#include <Wire.h> | |
void setup() { | |
Serial.begin(9600); | |
Wire.begin(); | |
} | |
void loop() { | |
byte error, address; | |
int nDevices = 0; | |
delay(5000); | |
Serial.println("Scanning for I2C devices ..."); | |
for(address = 0x01; address < 0x7f; address++){ | |
Wire.beginTransmission(address); | |
error = Wire.endTransmission(); | |
if (error == 0){ | |
Serial.print("I2C device found at address: "); | |
Serial.println(address, HEX); | |
nDevices++; | |
} else if(error != 2){ | |
Serial.print("Error: "); | |
Serial.print(error); | |
Serial.print("at Address: "); | |
Serial.println(address, HEX); | |
} | |
} | |
if (nDevices == 0){ | |
Serial.println("No I2C devices found"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment