TOF VL53L0X
Posted: Fri Dec 03, 2021 12:21 am
Hello, I wanted to play around with the TOF sensor so I bought THIS ONE. I connected the power to 3v3, ground, SCL and SDA and ran the code below. I get an error:
Traceback (most recent call last):
File "<stdin>", line 17, in <module>
OSError: [Errno 5] EIO
which line 17 is i2c.readfrom_mem_into(addr, 0, data).
Thoughts?
Traceback (most recent call last):
File "<stdin>", line 17, in <module>
OSError: [Errno 5] EIO
which line 17 is i2c.readfrom_mem_into(addr, 0, data).
Code: Select all
from machine import Pin, I2C
i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=100000)
addr = i2c.scan()[0]
data = bytearray(2)
while True:
i2c.readfrom_mem_into(addr, 0, data)
distance = data[0] << 8 | data[1]
print(distance)