• When testing this i2c scanner I figured out that there is a delay of 2sec before next scan.
    A full scan over the 120 id will take about 240 seconds.

    Is there a option to change this delay/timeout?

    function getSSMS() {
      return [Date().getSeconds(),Date().getMilliseco­nds()].join(':');
    }
    
    function isDeviceOnBus(i2c,id) {
          console.log(getSSMS(),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;
    }
    
    SCL = B6; SDA = B7;  // PICO
    I2C1.setup({sda:SDA,scl:SCL});
    
    setTimeout(function(){
      console.log('I2C detect as array:',detect(I2C1));
    },1000);
    
    // output
    53:67 0
    55:67 1
    57:69 2
    59:70 3
    1:71 4
    3:71 5
    5:71 6
    7:70 7
    9:68 8
    11:64 9
    ......
    
  • I'm afraid not. It might make more sense to implement the I2C scanner purely in JavaScript - all you need to do is clock out maybe 10 bits per device?

    Just to add, software I2C (var i2c=new I2C();i2c.setup(...)) might be faster...

  • Wow - Now it is fast as expected!

    SDA = B7; SCL = B6;               // Pico
    i2c = new I2C();
    i2c.setup({sda:SDA,scl:SCL});
    

    Now a i2c.readFrom(0,1) returns a new Uint8Array([255]) shouldn't this throw an exception?

    How to decide if this id is attached or not?

  • This was the change for the ESP8266: "i2c replace jsError() with jsExceptionHere() #868"

  • Software I2C applies across all boards, including ESP8266 - so you should see the same behaviour there if using software I2C.

    It's odd, because there are definitely timeout checks in the I2c implementation

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Pico: How to change the I2C timeout when using a i2c id scanner?

Posted by Avatar for MaBe @MaBe

Actions