I2C address scanner - Scans I2C bus on specified pins and prints all addresses where a active responder is found.

Dependencies:   mbed

Find address for I2C device

Scans all addreses on a I2C bus and reports those it is able to sucessfully communicate with.

One problem with I2C is that sometimes we receive chips without proper documentation and can not determine what address we should use ot communicate with that chip. This library seeks to identify the chips by attempting to communicate with each address and if it suceeds it assumes there is a chip present.

I have tested this with a clock chip, temperature sensor, OLED device and FRAM chip. It worked for all of them but there is a chance that some chips will not respond without a specific API call so there may be some chips it could not locate.

Revision:
6:02a058f2ec6f
Parent:
5:a4fddd74263c
Child:
7:5962e77516ac
--- a/main.cpp	Mon Mar 21 04:09:15 2016 +0000
+++ b/main.cpp	Mon Mar 21 04:17:13 2016 +0000
@@ -1,10 +1,9 @@
 /* Scan I2C bus on specified pins and prints out
-* the all address where a active responder
-* is found. 
+* the all address where an active device responds.
 *
 * By Joe Elsworth CTO of A2WH
 * Free use for all but no warranty, no promises.
-* Don't forget 3K pullup sda,scl 
+* Don't forget 3K pull-up resistors on sda,scl 
 * 
 * I tested this by soldering in a I2C chip known to respond at
 * address dec=120 hex=70 and the utility got the ack as expected.
@@ -13,7 +12,6 @@
 
 #include "mbed.h"
 
-
 Serial pc(USBTX, USBRX);
 
  #define D_SDA                  PB_7 
@@ -26,8 +24,8 @@
 DigitalOut myled(LED1);
  
 int ack;   
+int address;  
 void scanI2C() {
-  int address;  
   for(address=1;address<127;address++) {    
     ack = i2c.write(address, "11", 1);
     if (ack == 0) {