Skip to content

Instantly share code, notes, and snippets.

@heborras
Last active October 12, 2017 09:44
Show Gist options
  • Save heborras/293d8da78ce7e75864fd3f956eda882c to your computer and use it in GitHub Desktop.
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.
#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