Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    LoPy and LIDAR-Lite v2 I2C

    Scheduled Pinned Locked Moved LoPy
    lopyi2c
    5 Posts 3 Posters 1.9k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kingj
      last edited by

      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)
      time.sleep(1)        
      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
      print(data)
      distance = (data[0] << 8) + data[1]
      print(distance)
      

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

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @kingj
        last edited by livius

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

        think about people first, then computers

        K 1 Reply Last reply Reply Quote 0
        • RobTuDelftR Offline
          RobTuDelft
          last edited by

          Probably a good idea to read the status register (0x01) in a loop until the first bit is "0".

          Without data you're just another person with an opinion.
          Hackster | About me

          1 Reply Last reply Reply Quote 0
          • K Offline
            kingj @livius
            last edited by kingj

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

            L 1 Reply Last reply Reply Quote 0
            • L Offline
              livius @kingj
              last edited by

              @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

              i2c.writeto_mem(addr,0x00,bytes([0x00]))
              

              think about people first, then computers

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom