Last active
October 12, 2017 09:44
-
-
Save heborras/293d8da78ce7e75864fd3f956eda882c to your computer and use it in GitHub Desktop.
A utility for scanning the I2C bus 0 and 1 of an Arduino DUE.
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 <Wire.h> | |
void i2cs(int arg) { | |
int adr, err, cnt; | |
Serial.print("Scanning bus: "); | |
Serial.println(arg); | |
cnt = 0; | |
for (adr=1; adr<127; adr++) { | |
if (arg==1) { | |
Wire1.beginTransmission(adr); | |
err = Wire1.endTransmission(); | |
} else { | |
Wire.beginTransmission(adr); | |
err = Wire.endTransmission(); | |
} | |
if (err == 0) { | |
Serial.print("Detected device with adress: "); | |
Serial.println(adr); | |
cnt++; | |
} | |
} | |
Serial.print("Number of detected devices: "); | |
Serial.println(cnt); | |
} | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
Wire.begin(); | |
Wire1.begin(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
i2cs(0); | |
i2cs(1); | |
delay(10000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment