Hello,
I recently tried the program in the documentation for testing the VL53L0x ,but the readings are half of what they should be. If an object is 300 millimeters away, the reading will be about 150 millimeters. If I program the same ESP32 using micropython or arduino then the distance reading are correct.
could there be an issue with the VL53L0x driver in annex or is there something missing from the example program in the documentation.
I am using Annex32 BLE CAN 1.70.52 LFS and documentation :Annex32 WIFI RDS Help Version 1.70.2.
' VL53L0X example program
I2C.SETUP 21, 22
print VL53L0X.init ' will print 1 if the device has been found
VL53L0X.SetAccuracy 2 ' set the refresh rate at 400 msec (max accuracy)
VL53L0X.SetRange 1 ' set the range at 2000 mm ( 2 meters )
for z = 1 to 100000
print VL53L0X.Distance ' get the distance
next z
Thanks
esp32 + VL53L0x
- Starraker
- Posts: 54
- Joined: Tue Sep 03, 2024 1:53 am
- Location: Canberra Australia
- Been thanked: 13 times
- Contact:
Re: esp32 + VL53L0x
Hi,
I do not possess a VL53LOx but I just noticed that you do not have the I2C.BEGIN 0x?? or the VL53LOx.INIT statement in your code. (Where ?? is the address code of your VL53LOx)
Also you could try DISTANCE_N instead of DISTANCE.
I am not sure whether that will make any difference.
Cheers
I do not possess a VL53LOx but I just noticed that you do not have the I2C.BEGIN 0x?? or the VL53LOx.INIT statement in your code. (Where ?? is the address code of your VL53LOx)
Also you could try DISTANCE_N instead of DISTANCE.
I am not sure whether that will make any difference.
Cheers
- PeterN
- Posts: 704
- Joined: Mon Feb 08, 2021 7:56 pm
- Location: Krefeld, Germany
- Has thanked: 316 times
- Been thanked: 391 times
- Contact:
Re: esp32 + VL53L0x
A very long time ago in the ages of Annex32 V1.4x
I played around with this TOF sensor and an M5Stack.
It measured the pretty right correct distance.
Maybe this is usefull for testing
I played around with this TOF sensor and an M5Stack.
It measured the pretty right correct distance.
Maybe this is usefull for testing
Code: [Local Link Removed for Guests]
' TOF Distance-Sensor
' -M5Stack-Hardware with
' -3 pulldown-buttons at pin 37,38,39
' -TOF Sensor VL53LOX via I2C
' Range: 0-200cm
' peter.neufeld@gmx.de
VERSION$ = "V1.0"
'-----TFT-DISPLAY-setup
COL_BACKGROUND = tft.rgb(00,00,0)
COL_TEXT = tft.rgb(00,255,100)
TFT.INIT 1
TFT.FILL COL_BACKGROUND
TFT.TEXT.COL COL_TEXT,COL_BACKGROUND
'-----TOF-Sensor-setup
ACCURACY$=""
RANGE$=""
while not VL53L0X.init ' Test for TOF device
gosub NO_TOF_SENSOR
onhtmlreload NO_TOF_SENSOR
pause 1000
wend
TFT.FILL COL_BACKGROUND
'VL53L0X.SetAccuracy 0 ' set the refresh rate at 33 msec (min accuracy)
VL53L0X.SetAccuracy 1 ' set the refresh rate at 200 msec (med accuracy)
'VL53L0X.SetAccuracy 2 ' set the refresh rate at 400 msec (max accuracy)
'VL53L0X.SetRange 0 ' set the range at 60 mm ( 6o cm )
VL53L0X.SetRange 1
BUTTON_A = 39
BUTTON_B = 38
BUTTON_C = 37
BUTTON_Pressed = 0
DIST$ = ""
X$ = ""
'pin.mode BUTTON_A,input
'pin.mode BUTTON_B,input
'pin.mode BUTTON_C,input
'
' set initial accuracy and range
BUT1_IDX = 2
BUT2_IDX = 0
gosub BUT_1
gosub BUT_2
gosub WebInterface
onhtmlreload WebInterface
onhtmlchange WebInterface
' ----endless MAIN LOOP----
timer1 750, MAIN_PRG
wait
end
' #############################################
MAIN_PRG:
gosub TEST_M5_BUTTON
gosub READ_TOF
gosub PAINT_DISPLAY
return
' #############################################
READ_TOF:
d = VL53L0X.Distance ' get the distance
' suppress all out-of-range values
If (RANGE$ ="60cm") and (d > 660) then d= -1
If (RANGE$ ="200cm") and (d > 2200) then d= -1
DIST$= str$(d,"%4.0f") +"mm "
return
' #############################################
TEST_M5_BUTTON:
if pin(BUTTON_A)+pin(BUTTON_B)+pin(BUTTON_C) <3 then
pause 10 'Press longer than 10ms
if pin(BUTTON_A)= 0 then gosub BUT_1
if pin(BUTTON_B)= 0 then gosub BUT_2
if pin(BUTTON_C)= 0 then gosub BUT_3
else
BUTTON_Pressed=0
end if
return
' #########################################################################
BUT_1:
BUTTON_Pressed = 1
BUT1_IDX= (BUT1_IDX +1) mod 3
IF BUT1_IDX = 0 then ACCURACY$ = "LOW but FAST "
IF BUT1_IDX = 1 then ACCURACY$ = "MEDIUM "
IF BUT1_IDX = 2 then ACCURACY$ = "HIGH but SLOW "
VL53L0X.SetAccuracy BUT1_IDX
'gosub BUTTON_ACTION
return
' #########################################################################
BUT_2:
BUTTON_Pressed = 2
BUT2_IDX= (BUT2_IDX +1) mod 2
If BUT2_IDX = 0 then RANGE$ = "60cm"
If BUT2_IDX = 1 then RANGE$ = "200cm"
VL53L0X.SetRange BUT2_IDX
'gosub BUTTON_ACTION
return
' #########################################################################
BUT_3:
BUTTON_Pressed = 3
'gosub BUTTON_ACTION
return
' #########################################################################
BUT_0:
BUTTON_Pressed = 0
gosub BUTTON_ACTION
return
' #############################################
PAINT_DISPLAY:
' do not forgett to set M5 Display at config-page.
' There seem to be two types of displays in M5Stack.
' Colors may bee inverted with older(?) display
tft.text.size 1
tft.text.pos 80,2
TFT.PRINT "@: HTTP://";WORD$(IP$,1)
tft.text.size 3
tft.text.pos 120,25
tft.print "TOF-"
tft.text.pos 20,50
tft.print "distance-sensor"
tft.text.size 8
tft.text.pos 20,110
tft.print DIST$
tft.text.size 1
tft.text.pos 5,195
tft.print "A C C U R A C Y :"
tft.text.pos 5,210
tft.print ACCURACY$+" "
tft.text.size 1
tft.text.pos 130,195
tft.print "R A N G E :"
tft.text.pos 130,210
tft.print RANGE$+" "
TFT.LINE 000, 190, 320, 190, COL_TEXT
TFT.LINE 110, 190, 110, 240, COL_TEXT
TFT.LINE 210, 190, 210, 240, COL_TEXT
return
' #########################################################################
WebInterface:
cls
autorefresh 800
a$=""
a$ = a$ + "<center><h2>+- - - - - - - - - - - - - - - - - - - - - -+</h1>"
a$ = a$ + "<h3>- TOF-DISTANCE-SENSOR - -</h3>"
a$ = a$ + "<h5>########### "+ VERSION$ + " ###########</h5>"
a$ = a$ + "<br>"
a$ = a$ + TEXTBOX$(DIST$,"cssTB")
a$ = a$ + "<br><br>"
a$ = a$ + TEXTBOX$(ACCURACY$,"cssTB1")
a$ = a$ + TEXTBOX$(RANGE$,"cssTB1")
a$ = a$ + TEXTBOX$(x$,"cssTB1")
a$ = a$ + "<br>"
a$ = a$ + BUTTON$("set ACCURACY", BUT_1,"cssBT")
a$ = a$ + BUTTON$("set RANGE", BUT_2,"cssBT")
a$ = a$ + BUTTON$("-------", BUT_3,"cssBT")
a$ = a$ + "<h2>+- - - - - - - - - - - - - - - - - - - - - -+</h2></center></body></html>"
a$ = a$ + cssid$("cssTB1"," width:110px;height:1.5em; font-size:0.8em; background-color: black; text-align:center; color: white")
a$ = a$ + cssid$("cssTB"," width:300px;height:2em; font-size:4.0em;background-color: black; text-align:right;color: white")
a$ = a$ + cssid$("cssBT"," width:110px;height:1.8em; font-size:0.8em;background-color: grey; color: black; border-radius:1.1em; padding:.2em")
html a$
a$=""
return
' #########################################################################
NO_TOF_SENSOR:
tft.text.size 2
tft.text.pos 30,2
TFT.PRINT "HTTP://";WORD$(IP$,1)
tft.text.size 4
tft.text.pos 0,25
tft.print "NO TOF-SENSOR"
tft.text.pos 50,70
tft.print "FOUND !!!"
cls
a$ = "<h1># NO - T O F - SENSOR FOUND #</h1>"
html a$
return
You do not have the required permissions to view the files attached to this post.
Re: esp32 + VL53L0x
Hello and thanks for the response,[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Mar 12, 2025 8:20 pm Hi,
I do not possess a VL53LOx but I just noticed that you do not have the I2C.BEGIN 0x?? or the VL53LOx.INIT statement in your code. (Where ?? is the address code of your VL53LOx)
Also you could try DISTANCE_N instead of DISTANCE.
I am not sure whether that will make any difference.
Cheers
I use the exact program as in the documentation and I am receiving readings which varies with distance which tells me the I2C.begin and I2C.end is being handled by the annex VL53L0x driver and the VL53LOx.INIT is in the third line. I did try DISTANCE_N instead of DISTANCE, but nothing changed.
Thanks.
- PeterN
- Posts: 704
- Joined: Mon Feb 08, 2021 7:56 pm
- Location: Krefeld, Germany
- Has thanked: 316 times
- Been thanked: 391 times
- Contact:
Re: esp32 + VL53L0x
I can confirm now part of the problem mentioned by scm.[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Mar 12, 2025 10:09 pm A very long time ago in the ages of Annex32 V1.4x
I played around with this TOF sensor and an M5Stack.
It measured the pretty right correct distance.
...
The distance is measured correctly when VL53L0X.SetRange 0 is used to set the low default range of 600 mm.
When set to the 2000 mm range, the reported distance is incorrectly and unstable.
For the test, I reactivated my old setup, but now with Annex32 V1.60.3LFS and V1.70.52LFS .
I can't test whether the higher distance range was reported correctly in version 1.4x, but I suspect that such a problem should have been very obvious and noticeable at the time.
Re: esp32 + VL53L0x
Hi,
Thank you PeterN for researching it further. I changed the range on my setup to 600 mm and the readings are now closer to being correct, I still measure 135 mm when an object is placed 100 mm away.
By the way I loaded annex32 v1.4x and experienced the same issue.
Thanks
Thank you PeterN for researching it further. I changed the range on my setup to 600 mm and the readings are now closer to being correct, I still measure 135 mm when an object is placed 100 mm away.
By the way I loaded annex32 v1.4x and experienced the same issue.
Thanks