EDIT: I have managed to get my code to work, however it is now only returning zeros for anything, including if I read the serial numbers for the device. It seems to be actually communicating over i2c because if I turn power off to the Lidar, I get a timeout error. But I cannot seem to read a non-zero value from the Lidar.
# I2C Control of LIDAR Lite V3 # 1. Write 0x04 to register 0x00 # 2. Read register 0x01. Repeat until bit 0 (LSB) goes low. # 3. Read two bytes from 0x8f (high byte 0x0f then low byte 0x10) to obtain 16 bit measurement in cm # LIDAR LITE V3 DEFAULT I2C ADDRESS IS 0x62 from pyb import I2C import pyb readBuffer = bytearray(2) readHigh=0 readLow=0 dist=0 lidarReady=0xff lidarReadyCheck=bytes() Lidar=I2C(2, I2C.MASTER) #The i2c bus must always be 2. Lidar.init(I2C.MASTER) while(True): Lidar.mem_write(0x04,0x62,0x00) lidarReady=Lidar.mem_read(1,0x62,0x01) if not(lidarReady & lidarReadyCheck): print("reading") #debug print Lidar.mem_read(readBuffer, 0x62,0x96)#read 2 bytes from serial number high 0x16 and low 0x17 #readLow=Lidar.mem_read(1, 0x62,0x17) #dist=readHigh #dist<<=8 #dist|=readLow #readLow=Lidar.mem_read(1,0x62,0x10, timeout = 5000,addr_size = 8) pyb.delay(200) print("Distance:", readBuffer, "\n\r")
What does “OSError: [Errno 5] EIO” mean?
I am having trouble integrating the Lidar Lite V3 lidar sensor from Garmin over I2C.
Here is my code:
from pyb import I2C
readBuffer = bytearray(2)
Lidar=I2C(2, I2C.MASTER) #The i2c bus must always be 2.
Lidar.mem_write(0x04,0x62,0x00,timeout=3000,addr_size = 8)
lidarReady=Lidar.mem_read(1,0x62,0x01,timeout = 5000,addr_size = 8)
if((lidarReady & 0x01) == 0):
print(“reading”) #debug print
readBuffer=Lidar.mem_read(1, 0x62,0x0f, timeout = 5000,addr_size = 8)
readBuffer=Lidar.mem_read(1,0x62,0x10, timeout = 5000,addr_size = 8)