collapse

Author Topic: Investigating the VL53L0X Laser Rangefinder  (Read 24 times)

BaldwinK

  • Member
  • ****
  • B
  • Posts: 22
Investigating the VL53L0X Laser Rangefinder
« on: December 04, 2019, 05:35:57 PM »
VL53LOX.jpg
*VL53LOX.jpg (9.75 kB . 225x225 - viewed 7 times)

This complex component is made by European chip maker STMicroelectronics. No real detail or register map is published but you can download a zip file containing their application program interface.

In exchange for my email address I did this and pasted all code segments into one Word document to make following links easier. The total was 209 pages and 10,910 lines of c code! This is a significant corporate investment but was it to achieve “added value” or obfuscation?

Adafruit and Pololu provide library routines based on the API, cleaned up and suitable for c++. I must have messed up the Adafruit version as the compiler claimed insufficient memory. Pololu worked first time and I was able to see range values streaming down the screen.

The interface is i2c, so simple to read the 256 register initial values after power up. Matching up the verbose given-names is manageable using a spreadsheet. Writing all 1s or all 0s to each register provides a clue as to what might be read-only or masked in some way. Impossible to tell if writing a bit causes some hidden action but the “mask pattern” is now known.

There is a section in the API concerning loading back tuning parameters and a long list of registers is written to. When this list is added to the register map it becomes apparent that sections of read-only memory are included and certain registers are written twice with different values.

The use of Reg 0xFF is very weird as it toggles through this list. I have named it SIMON_SAYS and can show that it is a not_write_enable. When Reg 0xFF is set to 1 then no following writeReg instruction will work. So the read-only sections and duplicate areas are NOT written to.

Reg 0x00 is labelled SYSRANGE_START and bit 0 must be set to 1 to trigger the chip cycle although it won’t read back. The API sequence is surrounded by SIMON_SAYS so looks more impressive.

I did not dig too deeply into the calibration routines because my aim was to see what the chip would do without any of the clever bits. Anyone interested in greater accuracy etc could use the register map and investigate more. I can’t see much difference myself and would have been happy with measurements in cm.

Anyway I have arrived at the conclusion that the chip can be used much more simply and offer this code example:

#include <Wire.h>
  uint8_t address = 0x29;
  uint8_t last_status; 
 
void setup() {
 
  //for testing the chip from initial conditions to be sure
  //there is nothing held over, we power it down from pin D2
 
  pinMode (2, OUTPUT);       //VL53L0X power
  pinMode (13, OUTPUT);      //LED 
  digitalWrite (2, LOW);     //chip off 
  digitalWrite (13, HIGH);   //LED on
 
  Serial.begin(38400);
  Serial.println ("ToF testing");
 
  Wire.begin();

  delay(300);
  digitalWrite (2, HIGH);    //chip on
  digitalWrite (13, LOW);    //LED off 
  delay(300); 

  Serial.print ("ID ");      //this shows if i2c is working
  Serial.println (readReg(0xC0)); //should show 238 (0xEE)   

  }                          //end of setup

void loop () {
 
  writeReg(0x00, 0x01);      //re-arm
   
  Serial.print (millis());
  Serial.print ("  ");
  Serial.println (readReg16Bit(0x1E));
  delay (200);
 
  }                          //end of loop
 
// Write an 8-bit register
void writeReg(uint8_t reg, uint8_t value) {
  Wire.beginTransmission(address);
  Wire.write(reg);
  Wire.write(value);
  last_status = Wire.endTransmission();
  }

// Read an 8-bit register
uint8_t readReg(uint8_t reg) {
  uint8_t value;

  Wire.beginTransmission(address);
  Wire.write(reg);
  last_status = Wire.endTransmission();

  Wire.requestFrom(address, (uint8_t)1);
  value = Wire.read();

  return value;
  }

// Read a 16-bit register
uint16_t readReg16Bit(uint8_t reg) {
  uint16_t value;

  Wire.beginTransmission(address);
  Wire.write(reg);
  last_status = Wire.endTransmission();

  Wire.requestFrom(address, (uint8_t)2);
  value  = (uint16_t)Wire.read() << 8; // value high byte
  value |=           Wire.read();      // value low byte

  return value;
  }

The chip seems to be ready with a range value almost instantly and I couldn’t find a believable flag.

Application

I want to retro-fit these devices to scale models for collision sensing and progressive braking .  Picaxe 14M2 microcontrollers currently control speed and direction. The HC-SR04 ultrasonic units are far too big. The reduced c++ instructions above can be handled in BASIC:

   ;14M2 VL53L0X Demonstration
   ;i2c interface pin9 SDA, pin10 SCL

init: hi2csetup i2cmaster, 82, i2cfast, i2cbyte

   sertxd ("ToF Test ",cr,lf)
   
   ;read product ID at 0xC0 to prove i2c working   
   ;should show 238,170,16 (0xEE,0xAA,0x10)

   hi2cin 0xC0,(b3,b4,b5)   
   sertxd (#b3," ",#b4," ",#b5,cr,lf)
   
main: hi2cout 0x00,(0x01)    ;re-arm
   
   pause 200               ;demo cycle time
   
   ;read the range in mm from 0x1E
   hi2cin 0x1E,(b3,b2) 
     w2 = b3
     w2 = w2 * 256
     w2 = w2 | b2    
     
   sertxd (#time,"  ",#w2,cr,lf)
   
     goto main
      
   end

Video Clip

Poor quality but included for verification.


Register Map

*Register Map.doc


 

* Search


* Recent Topics

Time of Flight >>> Rounded Corners !!! by BaldwinK
[December 04, 2019, 05:46:08 PM]


Investigating the VL53L0X Laser Rangefinder by BaldwinK
[December 04, 2019, 05:35:57 PM]


The unnamed (yet) quatruped spider project by maelh
[December 04, 2019, 08:38:58 AM]


American Civil War Robot by kingart3
[November 27, 2019, 06:39:47 PM]


2D Side Scroller Cyberpunk themed by Killer Angel
[November 12, 2019, 07:56:15 AM]


Ebot SL by erco
[October 31, 2019, 04:27:36 PM]


Discord anyone? by tinhead
[October 20, 2019, 05:35:59 AM]


MKS Gen L 1.0 by lllloydo
[October 06, 2019, 01:24:26 AM]


Saturn pics anyone by viswesh
[September 28, 2019, 11:55:53 PM]


Hello Robot Rebels by Passixs
[September 15, 2019, 10:19:10 PM]


All Ya'll. And me. by James
[September 09, 2019, 10:35:19 PM]


MSD - Motorized solder dispenser (Work in progress) by James
[September 09, 2019, 08:45:29 PM]


It may be dangerous to work in the virtual realm by ZeroMax
[September 05, 2019, 05:55:16 PM]


"1984 Nixie Time" by Gareth
[August 25, 2019, 12:21:58 PM]


Just wanted to say Hi. by ErwinCanto
[August 18, 2019, 10:11:28 PM]

* Recent Posts

Re: Time of Flight >>> Rounded Corners !!! by BaldwinK
[December 04, 2019, 05:46:08 PM]


Investigating the VL53L0X Laser Rangefinder by BaldwinK
[December 04, 2019, 05:35:57 PM]


Re: The unnamed (yet) quatruped spider project by maelh
[December 04, 2019, 08:38:58 AM]


Re: The unnamed (yet) quatruped spider project by Nemesis
[November 28, 2019, 12:58:18 PM]


Re: The unnamed (yet) quatruped spider project by tinhead
[November 28, 2019, 10:09:46 AM]


Re: The unnamed (yet) quatruped spider project by Bajdi
[November 28, 2019, 08:44:38 AM]


Re: The unnamed (yet) quatruped spider project by Nemesis
[November 28, 2019, 05:17:04 AM]


American Civil War Robot by kingart3
[November 27, 2019, 06:39:47 PM]


Re: 2D Side Scroller Cyberpunk themed by Killer Angel
[November 12, 2019, 07:56:15 AM]


Re: The unnamed (yet) quatruped spider project by tinhead
[November 09, 2019, 05:58:16 AM]


Re: The unnamed (yet) quatruped spider project by Nemesis
[November 09, 2019, 03:29:02 AM]


Re: Ebot SL by erco
[October 31, 2019, 04:27:36 PM]


Re: 2D Side Scroller Cyberpunk themed by Killer Angel
[October 31, 2019, 09:57:48 AM]


Re: 2D Side Scroller Cyberpunk themed by Killer Angel
[October 31, 2019, 06:01:53 AM]


Re: 2D Side Scroller Cyberpunk themed by maelh
[October 30, 2019, 03:06:28 AM]