You are reading a single comment by @MaBe and its replies. Click here to read the full conversation.
  • changes:

    • include last id in scan
    • change if clause
    • add I2C1.setup() sample for Espruino boards

      function isDeviceOnBus(i2c,id) {
        try {
          return i2c.readFrom(id,1);
        }
        catch(err) {
          return -1;
        }
      }
      
      function detect(i2c,first, last) {
        first = first | 0;
        last = last | 0x77;
        var idsOnBus = Array();
        for (var id = first; id <= last; id++) {
          if ( isDeviceOnBus(i2c,id) != -1) {
            idsOnBus.push(id);
          }
        }
        return idsOnBus;
      }
      
      // Espruino boards
      // I2C1.setup( {scl: B8, sda: B9} );
      
      // ESP8266 
      I2C1.setup({sda: D2, scl: D4} );
      
      console.log('I2C detect as array:',detect(I2C1));
      
      
About

Avatar for MaBe @MaBe started