Hi guys! I’m working on using VL53L0X V2 laser ToF on the Microbit to measure distance. But I don’t know how to get it working. references I’ve found were mostly on Arduino boards. Could anyone help me out please?
I found under → extensions / ToF
–>range-vI53I0x
Tinkercademy Makecode Package
for the VL53LOX Time-of-Flight
Under the new Category “rangefinder” I found “initialise” and " distance (in cm)"
But an Error acourt by “initialise”
I could not find an solution…
Hi
Did you make a correct connection ?
SCL → pin 19 (Micro:bit)
SDA → pin 20
VDD → 3V
GND → 0V
XSHUT - > 3V
INT → Not connected
Julien
Hello. I am testing a VL53L0X module with a micro:bit V2 using MakeCode Python.
Connections: VIN–3V, GND–GND, SCL–P19, SDA–P20 and XSHUT–P0. The program resets XSHUT LOW and then keeps it HIGH. USB serial output works, but registers 0xC0, 0xC1 and 0xC2 all return zero from address 0x29, including when using a repeated-start transaction.
Has anyone successfully used this sensor with micro:bit V2 and MakeCode Python? Could this result be related to the I²C transaction, pull-up resistors, logic levels or power supply?
I use it with microPython and micro:bit V2. Maybe you can translate this to Typescript.
from microbit import *
from micropython import const
I2C_ADDR = const(0x29)
def init_laser_rangefinder():
init_sequence = [
(0x88, 0x00),
(0x80, 0x01),
(0xFF, 0x01),
(0x00, 0x00),
(0x91, 0x3C),
(0x00, 0x01),
(0xFF, 0x00),
(0x80, 0x00),
(0x0A, 0x04),
]
for register, value in init_sequence:
write_register(register, value)
def read_register(register):
i2c.write(I2C_ADDR, bytes([register]))
return i2c.read(I2C_ADDR, 1)[0]
def read_16bits(register):
i2c.write(I2C_ADDR, bytes([register]))
data = i2c.read(I2C_ADDR, 2)
return (data[0] << 8) | data[1]
def write_register(register, value):
i2c.write(I2C_ADDR, bytes([register, value]))
def laser_rangefinder():
write_register(0x00, 0x01)
sleep(50)
distance = read_16bits(0x14 + 10)
write_register(0x0B, 0x01)
return distance - 35