erco-laser range finder

erco

Senior Member
#2
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
#3
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
#4
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
#6
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
#7
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
#8
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
#9
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
#12
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!
 
Top