erco-laser range finder

erco

Senior Member
Thanks for the heads-up, Stan. Think I got one of those a while back but didn't have a chance to try it out. Can't find it right now. Really looks neat, just to be safe I just ordered this $6 type from China. I gotta get in the game! http://www.ebay.com/itm/262645508970

Please advise your findings!
 

stan74

Senior Member
10-4 Erco. Not sorted yet, back burner brisket, should get 50 ranges a second,better than sharp 180cm range finder which was too slow acquisition time for my robot. sr04 us is hard to beat from all range finding I've tried. How do you implement the data sheet init for stuff like this? The manufacture is better than 3rd party as a rule. I recently got better at trig and robot direction vectors. nice
 

erco

Senior Member
Any luck, Stan? After some Googling, it appears this sensor is complicated to use. Nobody in this forum has posted code. There's an Arduino library only. This same excerpt is posted on several websites:

Sensor configuration and control
In contrast with the information available for many other devices, ST has not publicly released a register map and descriptions or other documentation about configuring and controlling the VL53L0X. Instead, communication with the sensor is intended to be done through ST’s VL53L0X API (STSW-IMG005), a set of C functions that take care of the low-level interfacing. To use the VL53L0X, you can customize the API to run on a host platform of your choice using the information in the API documentation. Alternatively, it is possible to use the API source code as a guide for your own implementation.

Sample Code
We have written a basic Arduino library for the VL53L0X, which can be used as an alternative to ST’s official API for interfacing this sensor with an Arduino or Arduino-compatible controller. The library makes it simple to configure the VL53L0X and read the distance data through I²C. It also includes example sketches that show you how to use the library.
 

erco

Senior Member
Thanks Bill.b, yes, I did see that PDF. Section 3 has the user commands. Still not sure exactly how that translates to Picaxe BASIC.
 

hippy

Technical Support
Staff member
Thanks Bill.b, yes, I did see that PDF. Section 3 has the user commands. Still not sure exactly how that translates to Picaxe BASIC.
The API document describes the high level interface - eg "InitSensor()", "ReadSensor()" etc ( not actual VL53L0X API ).

There is presumably another document somewhere which defines exactly what data transfers and data manipulations occurs for each API entry, or that has been determined by experimentation.

The library code brings the two together allowing the main program to call API routines and doing the things required when those API routines are called.

So to use the sensor one needs to understand the API, what the parameters and return data is for each API routine. And needs to implement that in a manner a PICAXE can use, eg #MACRO commands with calls to subroutines to do what is required.

To interface to the sensor one needs to translate the code library into something the PICAXE understands, which delivers the same functionality as the library in some other language.

High-level code in C might be -

Code:
void main()
  InitSensor();
  while(1) {
    distance = ReadSensor(RANGE_LONG);
    if distance < 100 {
      printf( "Close to wall!\n" );
    }
  }
}
In PICAXE Basic ...

Code:
main:
  InitSensor
  Do
     ReadSensor(distance, RANGE_LONG)
     If distance < 100 Then
       SerTxd( "Close to wall!", CR, LF )
     End If
  Loop
Then you can create appropriate #MACRO templates, perhaps ...

Code:
#Macro InitSensor
  Gosub Do_InitSensor
#EndMacro

#Macro ReadSensor( resultVar, rangeScale )
  b0 = rangeScale
  Gosub Do_ReadSensor
  resultVar = w0
#EndMacro
Then one needs to create "Do_InitSensor:" and "Do_ReadSensor:" routines, perhaps ...

Code:
Do_Init_Sensor:
  HI2cOut $00, ($A5, $AA )
  Return

Do_Read_Sensor:
  HI2cOut $0F, ( b0 )     ; Set range from 'b0'
  HI2COut $10, ( 1 )      ; Do measuring
  HI2cIn  $0C, ( b1, b0 ) ; Read distance msb first into 'w0'
  Return
And, "Bingo!"; if that's all how it should be you're done.

It's really just a long slog of understanding what the API is, which parts you can ignore or need for your own purposes, making that and the implementation PICAXE compatible.

It's a bit like turning a book into a film. At the end of the day they'll be 'exactly the same' in what they convey though obviously different in how they do that.

Perhaps more like translating a foreign book. One needs to understand both languages and their idioms, know how to map things in one language to another to mean the same though different - "Je me lève comme Zeus" can become "I'm on top of the world, ma" for example.
 
Last edited:

erco

Senior Member
And, "Bingo!"; if that's all how it should be you're done.

It's really just a long slog of understanding what the API is, which parts you can ignore or need for your own purposes, making that and the implementation PICAXE compatible.
Therein lies the rub! Hippy, can you build these commands into the next firmware upgrade so using this sensor is as easy as using ULTRA ? :)
 

hippy

Technical Support
Staff member
Therein lies the rub! Hippy, can you build these commands into the next firmware upgrade so using this sensor is as easy as using ULTRA ? :)
And there's the rub's rub! If we knew what the commands needed to do it were; it would be easy enough to say how that would be as simple routines and macros.

It basically needs someone to sit down and look at the API and existing library code and then do the translation, testing and debugging. Unfortunately that takes time, is best done by someone familiar with C and PICAXE, with the motivation to do it, and ideally with hardware to hand.

Can't promise anything but I'll have a read through the datasheets and library to try and get a feel for how easy or hard it is. Presumable just measuring a distance is all that's required to start with ?
 

erco

Senior Member
I'm still amazed that Arduino caught on in spite of its finnicky slashes, semicolons and long-winded code. Even though the libraries hide a lot of the more tedious code, some program listings seem to go on forever to do some very simple things. I love a few lines of clever code that do a lot, and Picaxe usually fills that bill nicely.

Have fun implementing that code, Stan. Good luck and Godspeed!
 

BaldwinK

New Member
Patience is a virtue and you guys have waited long enough (I hope).

I took delivery of a couple of these breakout boards a while back and decided to have a crack at the code.

VL53LOX.jpg

European chip maker STMicroelectronics publishes no real detail or register map 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? It does seem unlikely that a Picaxe could handle this.

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.

Of course I had to use an Arduino Nano for the ‘forensic iconoclasm’. I soon began to suspect the involvement of the Wizard of Oz but it took some weeks to show how things could be behind the curtain. Translating the results for the Picaxe was the final test - I would appreciate others trying this out:

;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) ;and re-arm

pause 200

;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

Poor quality video of a simple range test included for verification:


If this works for you and you need multiple sensors then the chip has a soft address at register 0x8A. When it boots up again it will revert to 0x29 (note the shifted value needed in i2csetup).

The next video clip shows the comparison against the HC-SR04 ultrasonic unit which I have used many times - but it is big and unsightly in some situations. You can see how viewing the tiny laser via an electronic camera shows the cone of pulsed light.


When used to construct a point cloud, there is an accuracy problem that others have reported. This video clip shows one experiment with a humorous but unhappy conclusion.


I began my interest after studying Gareth’s LIDAR project at:

https://www.robotrebels.org/index.php?topic=869.0
 

Hemi345

Senior Member
Excellent! I just stumbled onto one of these in my parts box the other day. I had shelved the idea of using it when I found out STm didn't give up details on the registers and just posted an API. I'll give your test code a shot, thanks for posting.
 

Buzby

Senior Member
Here is my attempt at getting the VL53LOX working with PICAXE.

It was reliable, accurate, and fast, but I gave it up because it just had too many other issues for my project.

YMMV

Cheers,

Buzby

 

erco

Senior Member
Parallax makes a "LaserPING", which is a drop-in replacement for an ultrasonic sensor. No I2C, a Picaxe can read it with PULSIN or probably even ULTRA. I'll add that to my list of turkey projects over break.

 

erco

Senior Member
A "Turkey project" is a guilty pleasure project you sneak off and do after a big Thanksgiving/Christmas meal when everyone else is loosening their belts, cleaning up or watching football games. :)
 

stan74

Senior Member
'hi2cin 0x1E,(b3,b2)
'w2 = b3
'w2 = w2 * 256
'w2 = w2 | b2
Nice work it has been simplified. From a picaxe post by buzby I read 12 bytes from 0x14. The second is an error code,10 and 11 are distance.
If the error was = or 6 it displayed distance.
Anything else been done with this device please?
 
Last edited:

stan74

Senior Member
The hi2c is more bare bones in gcb than picaxe and it's like serial or spi...complicated.
on the other hand graphic lcd is easy. Picaxe would be too slow.
Can not wait to mount on a servo on a tank base from ebay.
Nice to program a uno in basic...just change the #chip at the start to a big list of pics and avr.
#chip mega328p, 16
#option Explicit
#include <glcd.h>
#include <uno_mega328p.h >
#define GLCD_TYPE GLCD_TYPE_ILI9341
'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
#define GLCD_DC DIGITAL_8 ' Data command line
#define GLCD_CS DIGITAL_10 ' Chip select line
#define GLCD_RESET DIGITAL_9 ' Reset line
#define GLCD_DI DIGITAL_12 ' Data in | MISO - Not used therefore not really required
#define GLCD_DO DIGITAL_11 ' Data out | MOSI
#define GLCD_SCK DIGITAL_13 ' Clock Line
#define ILI9341_HardwareSPI
;
#define GLCD_EXTENDEDFONTSET1
GLCDRotate ( Landscape_Rev )
GLCDCLS ILI9341_BLUE
;set up v53l0x
#define HI2C_DATA PORTC.5;sda
#define HI2C_CLOCK PORTC.4 ;scl
#define HI2C_BAUD_RATE 400
HI2CMode Master

dim distance_lo,distance_hi as byte
#define distance distance_hi*256+distance_lo
HI2CStart ;software restart
HI2CSend(0x52)
HI2CSend(0x89)
HI2CSend(0x01)
HI2CStop
wait 200 ms

GLCDfntDefaultsize = 3
GLCDDrawString (0,0,"Distance mm =", ILI9341_WHITE)
do ;------------------------
HI2CStart ;Sys Range Start
HI2CSend(0x52)
HI2CSend(0x00)
HI2CSend(0x01)
HI2CStop
HI2CStart ;read distance
HI2CSend(0x52)
HI2CSend(0x1E)
HI2CReStart
HI2CSend(0x53) ;set the read flag
HI2CReceive distance_hi, ACK
HI2CReceive distance_lo, NACK ;read one byte and conclude
HI2CStop
GLCDDrawString (0,40, str(distance)+" ",ILI9341_WHITE)
loop
 

stan74

Senior Member
Hi Erco. I got the V53L0x rangefinder to work and it is quite good for short distances. In fact Very good. Very narrow beam. Can "see" a pencil.
Here's a video of it working on a robot that uses those cheap geared stepper motors driven by a 2ms interrupt and that drives a counter
that when gets to 20 ie 20ms pulses the servo with it's position in useconds.
They are tidy distance sensors.
 

erco

Senior Member
VERY impressive, young Stan! That's a great robot and an impressive sensor demo. Thanks for sharing. You should submit that as a Picaxe project to Rev-Ed. You will likely win another Picaxe robot!
 

stan74

Senior Member
Erco. It is a nice distance sensor.Great for robot distance sensing.
The steppers save using geared dc motors and hbridge and pwm as they always go too fast :(
The code I use was from picaxe and changed for an arduino cos it's a usb lead and board and still it's basic.
I couldn't resist another system that lets you program arduino uno or tiny in basic not c.
converting back to picaxe would be difficult for me but if you want to see the code it's here.
Someone could convert the subs and logic is basic.
 

Attachments

stan74

Senior Member
on a table. V53L0X sees pen ok.
I have a walker with 16 servos and never got it to work...yet.
how are your projects going? stay well in these times.
 

erco

Senior Member
Nice! I have that sensor, just too busy tro try it out! But I do have a cool project on the bench right now...

 

Buzby

Senior Member
This I'm waiting to see, a self-playing labyrinth !.

Theoretically you could drive the servos over a pre-programmed path, and the ball will follow exactly the same route every time.

But a marble on a tray is very unpredictable. The slightest wrong angle and it's down a hole.

Are you going to have positional feedback from the ball, so that you can do dynamic corrections ?.
 

lbenson

Senior Member
Ingenious. I suppose in theory you could play a winning game with the pots, remembering the steps, and play it back.

Waiting to see you add computer vision ...

Then you can replace the holes with sensors which can be moved so that the track can be changed. This could keep you busy for years.
 

Buzby

Senior Member
@erco, please put this in it's own thread, it's too good to hide here.

@lbenson, just replace the holes with Hall Effect sensors. Then as a ball approaches a 'hole' the servos can do their stuff.

Cheers,

Buzby
 

stan74

Senior Member
I have not seen one of those for years! I like the servo idea!
If you took the voltage from the servo potentiometers, maybe it could be stored and "played back".
Think it would take lots of memory.
interesting idea for a project though.
 

stan74

Senior Member
Use a 2 part 2 hemispheres ball with tiny ball bearings in it and it will roll different.
silly idea...but so is the project...or maybe not. good luck.
 

stan74

Senior Member
This I'm waiting to see, a self-playing labyrinth !.

Theoretically you could drive the servos over a pre-programmed path, and the ball will follow exactly the same route every time.

But a marble on a tray is very unpredictable. The slightest wrong angle and it's down a hole.

Are you going to have positional feedback from the ball, so that you can do dynamic corrections ?.
how to do a pre-defined course. it would be difficult.
the balls momentum and stopping it.
I suggested a ball with a ball bearing inside to make it roll slower to erco.
 

John F

Member
Parallax makes a "LaserPING", which is a drop-in replacement for an ultrasonic sensor. No I2C, a Picaxe can read it with PULSIN or probably even ULTRA. I'll add that to my list of turkey projects over break.

Were you able to get it going with Ultra? It's the ideal sensor for a project I have in mind.
 

stan74

Senior Member
Were you able to get it going with Ultra? It's the ideal sensor for a project I have in mind.
3 times the price around $30. Uses triangulation and 15 samples per second.
Never seen one before.
The idea is it sees the beam reflection as brightest spot and turns off laser to see if it's brightest point then senses the angle and so distance.
1mm accuracy ...? but interesting. Cheers.
 
Last edited:

John F

Member
3 times the price around $30. Uses triangulation and 15 samples per second.
Never seen one before.
The idea is it sees the beam reflection as brightest spot and turns off laser to see if it's brightest point then senses the angle and so distance.
1mm accuracy ...? but interesting. Cheers.
I wonder if there is anyone on the forum who has used one? I'd appreciate some advice on how to get one working.
 

stan74

Senior Member
There must be a video explaining it. Not much code I could find, £30...l8r !
If it was that good there would be a chinese clone for £5 just like their ultrasonic sensors were cloned for £2
 

AllyCat

Senior Member
Hi John,
I wonder if there is anyone on the forum who has used one? I'd appreciate some advice on how to get one working.
Welcome to the forum. You might not get many replies because the first "mistake" you've made is posting in the "Finished Projects" and not the "Active" section of the forum. Also, there might not be much "interest" in a $30 sensor, although I see that's also the price that Parallax ask for their version of the Ultrasonic sensor (which as Stan says can be bought from China for a few $).

But the starting point should be "RTFM". I've quickly Downloaded and "scanned" it and have a couple of comments:

Firstly, although the "resolution" is quoted as 1mm, the accuracy (on page 5) is between +/-7% and +/-15% (or worse). Also the specification for the "Cover Glass" is:
●Material: PMMA, Acrylic
●Spectral transmittance: T< 5% for λ< 770 nm, T> 90% for λ > 820 nm
●Air gap: 100 μm
●Thickness: < 1mm (the thinner, the better)
●Dimensions: larger than 6 x 8 mm

so IMHO it is not as "wonderful" as you might think from the "headline" specification.

Secondly, to use its serial communications, you need to solder (link) pads on the PCB, and then it uses a single pin with Bi-Directional signalling at 9600 baud ("TTL" , idle high). IMHO that's not ideal for a PICaxe, so with its relatively low absolute accuracy, it may be much easier just to use its "PWM" mode.

The PWM mode "should" be very easy to get working, using just PICaxe's PULSIN command and a few lines of code, or perhaps just the ULTRA command directly. BTW, the absolute accuracy of an Ultrasonic sensor is of course dependent on the speed of sound, which is almost NOT dependent on Air Pressure NOR Humidity, but it does vary significantly with Air Temperature. But the temperature of air is easy to measure with a PICaxe, using one of several methods. ;)

Cheers, Alan.
 

John F

Member
Hi John,

Welcome to the forum. You might not get many replies because the first "mistake" you've made is posting in the "Finished Projects" and not the "Active" section of the forum. Also, there might not be much "interest" in a $30 sensor, although I see that's also the price that Parallax ask for their version of the Ultrasonic sensor (which as Stan says can be bought from China for a few $).

But the starting point should be "RTFM". I've quickly Downloaded and "scanned" it and have a couple of comments:

Firstly, although the "resolution" is quoted as 1mm, the accuracy (on page 5) is between +/-7% and +/-15% (or worse). Also the specification for the "Cover Glass" is:
●Material: PMMA, Acrylic
●Spectral transmittance: T< 5% for λ< 770 nm, T> 90% for λ > 820 nm
●Air gap: 100 μm
●Thickness: < 1mm (the thinner, the better)
●Dimensions: larger than 6 x 8 mm

so IMHO it is not as "wonderful" as you might think from the "headline" specification.

Secondly, to use its serial communications, you need to solder (link) pads on the PCB, and then it uses a single pin with Bi-Directional signalling at 9600 baud ("TTL" , idle high). IMHO that's not ideal for a PICaxe, so with its relatively low absolute accuracy, it may be much easier just to use its "PWM" mode.

The PWM mode "should" be very easy to get working, using just PICaxe's PULSIN command and a few lines of code, or perhaps just the ULTRA command directly. BTW, the absolute accuracy of an Ultrasonic sensor is of course dependent on the speed of sound, which is almost NOT dependent on Air Pressure NOR Humidity, but it does vary significantly with Air Temperature. But the temperature of air is easy to measure with a PICaxe, using one of several methods. ;)

Cheers, Alan.
Hi Alan,

Thanks for the tip on where to post - much appreciated. I'll probably have to post something soon - so far I have failed even to get an ultrasonic sensor working. Have tried both the 'official' SRF 005 and the 004 Chinese knockoff.
Thanks too for the information above on the Laser sensor. I need something that can't be confused by loud sounds. Absolute accuracy in distance measuring is not all that important - I am after rate of change of distance to the object being detected.

All the Best

John
 

stan74

Senior Member
The srfo4, I bought a bag of 5 for < £10.
They are brill easy to use and with a resistor only need 1 port for ping and receive.
 
Top