Original code found in a PICAXE forum based on a PICAXE 14M2. This version of the code slightly modified for a demo with a PICAXE 08M2+.
Photos
Photo is for illustrative purposes only. Please refer to the description.
Code Sample
To copy code: Hover over the right top corner of the code panel. Click COPY button, the code will be COPIED to the clipboard.
; time-of-flight original code from picaxe forum
; 14m2 vl53l0x demonstration
; i2c interface pin9 sda, pin10 scl
; not much modified for picaxe 08m2+ rhb.20221008
; i2c interface pin5 sda, pin6 scl
init: hi2csetup i2cmaster, 82, i2cfast, i2cb yte
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) ; start and re-arm
pause 25 0
low c.4
; read the range in mm from 0x1e
hi2cin 0x1e,(b3,b2)
w2 = b3
w2 = w2 * 256
w2 = w2 | b2
; only output when object closer than 150mm
if w2 > 21 and w2 < 150 then
sertxd (#time," ",#w2,cr,lf)
high c.4
endif
goto main
end