This code provides capabilities to find the address of connected I2C devices

Dependencies:   mbed

Revision:
1:6a79412e380e
Parent:
0:1301fb16e306
--- a/main.cpp	Mon May 04 09:03:32 2015 +0000
+++ b/main.cpp	Thu May 03 17:06:09 2018 +0000
@@ -1,18 +1,19 @@
 // Original program found here: http://playground.arduino.cc/Main/I2cScanner
 // Modified by Domen Ornik, 4.5.2015
-
 #include "mbed.h"
 
-I2C i2c(I2C_SDA , I2C_SCL ); 
+I2C i2c(PB_7, PB_6); 
+Serial pc(USBTX, USBRX);
 
 int main() {
-    printf("\nI2C Scanner");
+    pc.baud(115200);
+    pc.printf("\nI2C Scanner");
     
     while(1) {
         int error, address;
         int nDevices;
       
-        printf("Scanning...\n");
+        pc.printf("Scanning...\n");
         
          nDevices = 0;
          
@@ -23,17 +24,17 @@
             i2c.stop();
             if (error == 1)
             {
-              printf("I2C device found at address 0x%X", address); //Returns 7-bit addres
+              pc.printf("I2C device found at address 0x%X", address); //Returns 7-bit addres
               nDevices++;
             }
 
           }
           if (nDevices == 0)
-            printf("No I2C devices found\n");
+            pc.printf("No I2C devices found\n");
           else
-            printf("\ndone\n");
+            pc.printf("\ndone\n");
         
-          wait(5);           // wait 5 seconds for next scan
+          wait(2);           // wait 5 seconds for next scan
           
             }
         }