You are reading a single comment by @MaBe and its replies. Click here to read the full conversation.
  • on ESP you can use this with the latest build

    I2C1.setup({sda: D4, scl: D5} );
    
    function isDeviceOnBus(i2c, addr) {
      try {  
        return i2c.readFrom(addr,1);
      } 
      catch(err) { 
        return -1;
      }
    }
    
    function i2cdetect( i2c, first, last ) {
      if (typeof first === "undefined") first = 0x03;
      if (typeof (last) === "undefined") last = 0x77;
    
      print( "     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f" );
      for (var upper = 0; upper < 8; ++upper) {
        var line = upper + "0: ";
        for (var lower = 0; lower < 16; ++lower) {
          var address = (upper << 4) + lower;
          // Skip unwanted addresses
          if ((address < first) || (address > last)) {
            line += "   ";
            continue;
          }
          if ( ! isDeviceOnBus(i2c,address) ){
            line += (address + 0x100).toString( 16 ).substr( -2 )+" ";
          } else 
            line += "-- ";
        }
        print( line );
      }
    }
    
    i2cdetect( I2C1, 0x03, 0x77);
    
    /* sample output for  a connected PCA9635 
    
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: 70 -- -- -- -- -- -- --
    
    */
    
    
    
About

Avatar for MaBe @MaBe started