LoPy and LIDAR-Lite v2 I2C

  • Hi All,

    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)
    i2c.init(I2C.MASTER, baudrate=100000) 
    addr = i2c.scan()[0]

    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[0] & 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
    distance = (data[0] << 8) + data[1]

    Again, only returns 0x00 or 0x04. Stuck on this one and appreciate any help or past experiences that the community might have.

  • @kingj
    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


  • @livius and @RobTuDelft thanks for your suggestions I have attempted both. Unfortunately reading the status register always returns 0x00 and therefore a first bit of 0.

    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".

  • @kingj
    First in your situation i will be adding 2x 2N7000 or BSS138 or any 3V3 to 5V e.g.
    alt text

    and try again.

Log in to reply

Pycom on Twitter