How to add an option to VL53L0X module

Posted on
Page
of 2
Prev
/ 2
  • @Gordon
    Here is a version of VL53L0X module with some small additions. It is compiled from a few working parts but not tested (I have no device now). In any case, additions from previous version are very small so I do not think there are too many bugs here.
    Main problem with readRangeSingleMillimeters() - it can not work after setGPIOConfig (1) - GPIO mode set to on when low threshold is crossed.
    I have not checked accurately if performSingleMeasurement() can still work - it waits for another flag in 'while'. May be that flag is better and may be it will be better to change readRangeContinuousMillimeters() to use the flag.


    1 Attachment

  • It looks to be very interesting to change many calls of this.w to some array. But I do not know how to do it well - I am afraid I will use even more memory for arrays.
    Some VL53L0X usage example:


    1 Attachment

  • Try to replace

      this.w(0xFF, 0x01);
      this.w(0x00, 0x00);
    
      this.w(0xFF, 0x00);
      this.w(0x09, 0x00);
      this.w(0x10, 0x00);
      this.w(0x11, 0x00);
    
      this.w(0x24, 0x01);
      this.w(0x25, 0xFF);
      this.w(0x75, 0x00);
    
      this.w(0xFF, 0x01);
      this.w(0x4E, 0x2C);
      this.w(0x48, 0x00);
      this.w(0x30, 0x20);
    
      this.w(0xFF, 0x00);
      this.w(0x30, 0x09);
      this.w(0x54, 0x00);
      this.w(0x31, 0x04);
      this.w(0x32, 0x03);
      this.w(0x40, 0x83);
      this.w(0x46, 0x25);
      this.w(0x60, 0x00);
      this.w(0x27, 0x00);
      this.w(0x50, 0x06);
      this.w(0x51, 0x00);
      this.w(0x52, 0x96);
      this.w(0x56, 0x08);
      this.w(0x57, 0x30);
      this.w(0x61, 0x00);
      this.w(0x62, 0x00);
      this.w(0x64, 0x00);
      this.w(0x65, 0x00);
      this.w(0x66, 0xA0);
    
      this.w(0xFF, 0x01);
      this.w(0x22, 0x32);
      this.w(0x47, 0x14);
      this.w(0x49, 0xFF);
      this.w(0x4A, 0x00);
    
      this.w(0xFF, 0x00);
      this.w(0x7A, 0x0A);
      this.w(0x7B, 0x00);
      this.w(0x78, 0x21);
    
      this.w(0xFF, 0x01);
      this.w(0x23, 0x34);
      this.w(0x42, 0x00);
      this.w(0x44, 0xFF);
      this.w(0x45, 0x26);
      this.w(0x46, 0x05);
      this.w(0x40, 0x40);
      this.w(0x0E, 0x06);
      this.w(0x20, 0x1A);
      this.w(0x43, 0x40);
    
      this.w(0xFF, 0x00);
      this.w(0x34, 0x03);
      this.w(0x35, 0x44);
    
      this.w(0xFF, 0x01);
      this.w(0x31, 0x04);
      this.w(0x4B, 0x09);
      this.w(0x4C, 0x05);
      this.w(0x4D, 0x04);
    
      this.w(0xFF, 0x00);
      this.w(0x44, 0x00);
      this.w(0x45, 0x20);
      this.w(0x47, 0x08);
      this.w(0x48, 0x28);
      this.w(0x67, 0x00);
      this.w(0x70, 0x04);
      this.w(0x71, 0x01);
      this.w(0x72, 0xFE);
      this.w(0x76, 0x00);
      this.w(0x77, 0x00);
    
      this.w(0xFF, 0x01);
      this.w(0x0D, 0x01);
    
      this.w(0xFF, 0x00);
      this.w(0x80, 0x01);
      this.w(0x01, 0xF8);
    
      this.w(0xFF, 0x01);
      this.w(0x8E, 0x01);
      this.w(0x00, 0x01);
      this.w(0xFF, 0x00);
      this.w(0x80, 0x00);
    

    With

    this.i2c.writeTo(this.ad, new Uint8Array([
        0xFF, 0x01, 0x00, 0x00, 0xFF, 0x00, 0x09, 0x00, 0x10, 0x00, 0x11, 0x00, 
        0x24, 0x01, 0x25, 0xFF, 0x75, 0x00, 0xFF, 0x01, 0x4E, 0x2C, 0x48, 0x00,
        0x30, 0x20, 0xFF, 0x00, 0x30, 0x09, 0x54, 0x00, 0x31, 0x04, 0x32, 0x03,
        0x40, 0x83, 0x46, 0x25, 0x60, 0x00, 0x27, 0x00, 0x50, 0x06, 0x51, 0x00,
        0x52, 0x96, 0x56, 0x08, 0x57, 0x30, 0x61, 0x00, 0x62, 0x00, 0x64, 0x00,
        0x65, 0x00, 0x66, 0xA0, 0xFF, 0x01, 0x22, 0x32, 0x47, 0x14, 0x49, 0xFF,
        0x4A, 0x00, 0xFF, 0x00, 0x7A, 0x0A, 0x7B, 0x00, 0x78, 0x21, 0xFF, 0x01,
        0x23, 0x34, 0x42, 0x00, 0x44, 0xFF, 0x45, 0x26, 0x46, 0x05, 0x40, 0x40,
        0x0E, 0x06, 0x20, 0x1A, 0x43, 0x40, 0xFF, 0x00, 0x34, 0x03, 0x35, 0x44,
        0xFF, 0x01, 0x31, 0x04, 0x4B, 0x09, 0x4C, 0x05, 0x4D, 0x04, 0xFF, 0x00,
        0x44, 0x00, 0x45, 0x20, 0x47, 0x08, 0x48, 0x28, 0x67, 0x00, 0x70, 0x04,
        0x71, 0x01, 0x72, 0xFE, 0x76, 0x00, 0x77, 0x00, 0xFF, 0x01, 0x0D, 0x01,
        0xFF, 0x00, 0x80, 0x01, 0x01, 0xF8, 0xFF, 0x01, 0x8E, 0x01, 0x00, 0x01,
        0xFF, 0x00, 0x80, 0x00
    ]));
    

    Or even

    this.i2c.writeTo(this.ad, atob("/wEAAP8ACQAQABEAJAEl/3UA/wFOLEgAMC­D/ADAJVAAxBDIDQINGJWAAJwBQBlEAUpZWCFcwYQ­BiAGQAZQBmoP8BIjJHFEn/SgD/AHoKewB4If8BIz­RCAET/RSZGBUBADgYgGkNA/wA0AzVE/wExBEsJTA­VNBP8ARABFIEcISChnAHAEcQFy/nYAdwD/AQ0B/w­CAAQH4/wGOAQAB/wCAAA=="));
    
  • @PaddeK I guess it's worth a try, but I'm not convinced that works. Usually the first byte is the address and all subsequent bytes just increment the address.

    Try:

    VL53L0X.prototype.wmany = function(a) {
      for (var i=0;i<a.length;i+=2)
        this.i2c['writeTo'](this.ad, a[i], a[i+1]);
    };
    
    this.wmany([
        0xFF, 0x01, 0x00, 0x00, 0xFF, 0x00, 0x09, 0x00, 0x10, 0x00, 0x11, 0x00, 
        0x24, 0x01, 0x25, 0xFF, 0x75, 0x00, 0xFF, 0x01, 0x4E, 0x2C, 0x48, 0x00,
        0x30, 0x20, 0xFF, 0x00, 0x30, 0x09, 0x54, 0x00, 0x31, 0x04, 0x32, 0x03,
        0x40, 0x83, 0x46, 0x25, 0x60, 0x00, 0x27, 0x00, 0x50, 0x06, 0x51, 0x00,
        0x52, 0x96, 0x56, 0x08, 0x57, 0x30, 0x61, 0x00, 0x62, 0x00, 0x64, 0x00,
        0x65, 0x00, 0x66, 0xA0, 0xFF, 0x01, 0x22, 0x32, 0x47, 0x14, 0x49, 0xFF,
        0x4A, 0x00, 0xFF, 0x00, 0x7A, 0x0A, 0x7B, 0x00, 0x78, 0x21, 0xFF, 0x01,
        0x23, 0x34, 0x42, 0x00, 0x44, 0xFF, 0x45, 0x26, 0x46, 0x05, 0x40, 0x40,
        0x0E, 0x06, 0x20, 0x1A, 0x43, 0x40, 0xFF, 0x00, 0x34, 0x03, 0x35, 0x44,
        0xFF, 0x01, 0x31, 0x04, 0x4B, 0x09, 0x4C, 0x05, 0x4D, 0x04, 0xFF, 0x00,
        0x44, 0x00, 0x45, 0x20, 0x47, 0x08, 0x48, 0x28, 0x67, 0x00, 0x70, 0x04,
        0x71, 0x01, 0x72, 0xFE, 0x76, 0x00, 0x77, 0x00, 0xFF, 0x01, 0x0D, 0x01,
        0xFF, 0x00, 0x80, 0x01, 0x01, 0xF8, 0xFF, 0x01, 0x8E, 0x01, 0x00, 0x01,
        0xFF, 0x00, 0x80, 0x00
    ]);
    
  • Hmm could be.. my experience with i2c devices is limited. I hope he tries it though because its so much shorter especially the base64 variation :)

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

How to add an option to VL53L0X module

Posted by Avatar for SergeP @SergeP

Actions