LoPy and LIDAR-Lite v2 I2C
I've recently purchased a LoPy and am trying to interface with a Lidar-Lite version 2 over I2C. I'm able to find the peripheral on the bus and successful send comments but reading from memory returns only 0x00 or 0x04 an unexpected result. The I2C protocol can be found here. I've verified with an arduino that the sensor is functional and that the power supply is stable enough for measurements. The arduino library can be found here. While the sensor requires 5v for operation the I2C is at 3.3v. I've also tried adding 4.7k pullups to SDA and SCL (P9 and 10 on the LoPy) with no change in the behavior.
I initialize as follows:
from machine import I2C import time i2c = I2C(0) i2c = I2C(0, I2C.MASTER) time.sleep(1) i2c.init(I2C.MASTER, baudrate=100000) addr = i2c.scan()
addr becomes 98, as expected for the address of 0x62. According to the register definitions, a meansuremnet is taken by writing 0x04 to 0x00
i2c.writeto_mem(addr,0x00,bytes([0x04])) #take measurement
The write command returns and 1. The LSB of register 0x01 can then be polled to check the sensor status where 0 indicates its not busy:
data = i2c.readfrom_mem(addr,0x01, 1) dataLSB = data & 1
This returns only 0x00 or 0x04 which I believe to be erroneous. Finally the measurement can be read back from 0x8f as two bytes:
data = i2c.readfrom_mem(addr,0x8f, 2) #Read 2 bytes from measrement register print(data) distance = (data << 8) + data print(distance)
Again, only returns 0x00 or 0x04. Stuck on this one and appreciate any help or past experiences that the community might have.
first change your init to only one line - i do not suppose that this matter but...
i2c = I2C(0, I2C.MASTER, baudrate=100000)
and try to add first default config
I tried using using a level shiftier but the result was the same. The returned data is only 0x00.
Probably a good idea to read the status register (0x01) in a loop until the first bit is "0".
First in your situation i will be adding 2x 2N7000 or BSS138 or any 3V3 to 5V e.g.
and try again.