daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Oct 12th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2.  
  3. void i2cs(int arg) {
  4.  
  5.   int adr, err, cnt;
  6.  
  7.   Serial.print("Scanning bus: ");
  8.   Serial.println(arg);
  9.  
  10.   cnt = 0;  
  11.   for (adr=1; adr<127; adr++) {
  12.     if (arg==1) {
  13.           Wire1.beginTransmission(adr);
  14.           err = Wire1.endTransmission();
  15.     } else {
  16.           Wire.beginTransmission(adr);
  17.           err = Wire.endTransmission();
  18.     }
  19.     if (err == 0) {
  20.       Serial.print("Detected device with adress: ");
  21.       Serial.println(adr);
  22.       cnt++;
  23.     }
  24.   }
  25.   Serial.print("Number of detected devices: ");
  26.   Serial.println(cnt);
  27. }
  28.  
  29.  
  30. void setup() {
  31.   // put your setup code here, to run once:
  32.   Serial.begin(9600);
  33.   Wire.begin();
  34.   Wire1.begin();
  35. }
  36.  
  37. void loop() {
  38.   // put your main code here, to run repeatedly:
  39.   i2cs(0);
  40.   i2cs(1);
  41.  
  42.   delay(10000);
  43. }
RAW Paste Data
Top