You are reading a single comment by @MaBe and its replies. Click here to read the full conversation.
  • now using a version that returns an array of ids

    var isDevice = function isDeviceOnBus(i2cBus,id) {
          try {
              return i2cBus.readFrom(id,1);
          }
          catch(err) {
              return -1;
          }
    };
    
    var detect = function(i2c,first, last) {
          first = first | 0;
          last = last | 0x77;
          var idsOnBus = Array();
          for (var id = first; id < last; id++) {
              if ( ! isDevice(i2c,id) ) {
                  idsOnBus.push(id);
              }
          }
          return idsOnBus;
    };
    
    
    I2C1.setup({sda: D4, scl: D5} );
    console.log(detect(I2C1));
    
    
About

Avatar for MaBe @MaBe started