13 Replies Latest reply on Feb 16, 2018 3:15 PM by user_391105768

    LIDAR Lite I2C project

    danescu.andrei

      Hello, 

         

      I am working on a project for a LIDAR Lite scanner - this unit has an I2C interface and seems capable of the range and accuracy I need. ( http://www.robotshop.com/media/files/pdf/operating-manual-llm20c132i500s011.pdf  ) 

         

      However, I cannot seem to get it running on the PSOC. I got the sample code working with Arduino(so the sensor is ok) but no luck on the PSOC5lp. 

         

      The main problems I have is that the I2C is still a bit confusing for me - I got it running for accelerometers and gyros but I'm still not 100% sure on how everything works. I get the gist but stil find the datasheet a bit confusing. 

         

      So, my main question is how I send a specific value to a specific register. And how do I read a specific register from the unit? -I suppose I am doing the right thing in my code but...

         

      I am quite confused as I used the same code that's working for my gyro and accelerometers with no luck on this LIDAR. Attached the code in the text file. 

         

      Thank you for the help!

        • 1. Re: LIDAR Lite I2C project
          user_14586677

          There are several I2C example projects, PSOC Creator, "Find Example Projects" link on

             

          start page, that you can take a look at.

             

           

             

          Make sure your signaling levels correct with scope, that you have not doubled up

             

          on pullups on I2C clk and data lines.

             

           

             

          Regards, Dana.

          • 2. Re: LIDAR Lite I2C project
            danescu.andrei

            I did... It seems they are using similar code. 

               

            The sensor also works well with the MiniProg3 sending this command: w 62 0 4 p [DELAY=8] w 62 8f  [DELAY=8] r 62 @Res1 @Res2 @Res3 @Res4 p [DELAY=8] 

               

            If I  don't use the Delays it freezes up and disappears from the bus - something I didn't have a problem with before. 

               

             

               

            Some details on the protocol here: http://kb.pulsedlight3d.com/support/solutions/articles/5000548631-i2c-protocol-summary

            • 3. Re: LIDAR Lite I2C project
              user_14586677

              Unless someone else has some thoughts consider filing a CASE -

                 

               

                 

              To create a technical or issue case at Cypress -

                 

               

                 

              www.cypress.com

                 

              “Support”

                 

              “Technical Support”

                 

              “Create a Case”

                 

               

                 

              You have to be registered on Cypress web site first.

                 

               

                 

              Regards, Dana.

              • 4. Re: LIDAR Lite I2C project
                bob.marlowe

                That code you provided will not work when you try to read from a sensor's register. The "I2C_MODE_COMPLETE_XFER" will release the bus after the transfer has taken place, but your transaction is not ready yet: you need to issue a restart after sending the register address.

                   

                I was mostly successful when starting with the more basic I2C functions that send or receive single bytes and always checking the returned fuction results for errors.

                   

                 

                   

                Bob

                • 5. Re: LIDAR Lite I2C project
                  danescu.andrei

                  Aha... I see - I got stuff working with this code but will follow your advice Bob. Do you have any snippet of how the structure should be for a read/ write? 

                     

                  I am thinking it would be a good idea to just make 2 functions I have more control over ( and understand better :))  ) so any help would be great :) 

                  • 6. Re: LIDAR Lite I2C project
                    danescu.andrei

                    Aha... I see - I got stuff working with this code but will follow your advice Bob. Do you have any snippet of how the structure should be for a read/ write? 

                       

                    I am thinking it would be a good idea to just make 2 functions I have more control over ( and understand better :))  ) so any help would be great :) 

                    • 7. Re: LIDAR Lite I2C project
                      bob.marlowe

                      Take the attached project and look at the sensor.c, there you find my I2C interfaces...

                         

                       

                         

                      Bob

                      • 8. Re: LIDAR Lite I2C project
                        danescu.andrei

                        Thanks Bob. I like your quad project - how did it fly? 

                        • 9. Re: LIDAR Lite I2C project
                          bob.marlowe

                          Project was developed for a customer  and was not designed to move in air. The remaining parts were completed at the customer's site, so no chance to openly post anything more here.

                             

                          Project was finished successfully.

                             

                           

                             

                          Bob

                          • 10. Re: LIDAR Lite I2C project
                            danescu.andrei

                            Hi Bob... I am trying the I2C functions like your code shows without much luck. 

                               

                            Can you confirm this is similar to what you have? 

                               

                             

                               

                            It should be a matter of following the I2C comms protocol: 

                               

                            I2C_MasterSendStart(LIDARLite_ADDRESS, I2C_WRITE);

                               

                            I2C_MasterWriteByte(0x00);

                               

                            I2C_MasterWriteByte(0x04);

                               

                            I2C_MasterSendStop();

                               

                                CyDelay(100);

                               

                            I2C_MasterSendStart(LIDARLite_ADDRESS, 0x01);

                               

                            I2C_MasterWriteByte(0x8f);

                               

                            I2C_MasterSendRestart(LIDARLite_ADDRESS, I2C_READ);

                               

                                

                               

                            datalow = I2C_ReadByte(I2C_ACKslave);

                               

                            datahigh = I2C_ReadByte(I2C_NAKslave);

                               

                             

                               

                            I2C_MasterSendStop();

                               

                            Intermed = (datahigh << 8) | datalow;

                               

                             

                               

                             Any idea why this might not work? I'm running out of things to test here. 

                               

                            The previous code snippet from my text file works to some extent. No luck getting both bytes though. 

                               

                            I can confirm the sensor is working as I have it hooked up to an arduino  and read without any issues. 

                               

                            The Arduino code is here: 

                               

                            https://github.com/PulsedLight3D/LIDARLite_StateMachine/blob/master/LIDARLite_StateMachine/LIDARLite_StateMachine.ino

                               

                             

                               

                            Maybe you can spot something relevant I am missing on my code. 

                               

                            Thanks! 

                            • 11. Re: LIDAR Lite I2C project
                              bob.marlowe

                              I would suggest that you (at least in the beginning) use the returned value of all the I2C_Masterxxx() functions and check them for legal values, usually non-zero means an error and the bit-patterns are #defined in the appropiate .h files.

                                 

                              At second sight I found a wrong mode parameter in your communication. see changed project attached.

                                 

                               

                                 

                              Happy coding

                                 

                              Bob

                              • 12. Re: LIDAR Lite I2C project
                                danescu.andrei

                                Thanks a lot Bob... the low level functions work well now - Write not Read :)) 

                                   

                                However I can't get rid of those delays. As soon as I remove them it stops working. I did some more tests and noticed that the device seems very sensible to transmission speed and I2C clock setup. 

                                   

                                Not sure why, I am blaming the Lidar I2C implementation at the moment. 

                                   

                                 

                                   

                                Thanks for the help, 

                                   

                                Andrei

                                • 13. Re: LIDAR Lite I2C project
                                  user_391105768

                                  guys,

                                  I found your thread after having problems myself. 

                                  This thread about Raspberry Pi says don't use a restart with the Lidar-Lite v3.

                                  Lidar-Lite v3 return always zero with raspberry pi 3 - RobotShop Forum

                                   

                                  I took mine out and now everything works fine. 

                                  good luck,

                                  Johann

                                   

                                  // start a read   

                                   

                                  reply[replyCnt++]=I2C_MasterSendStart(0x62,I2C_WRITE_XFER_MODE );

                                      // write 0x04 to register 0x00

                                      reply[replyCnt++]=I2C_MasterWriteByte(0x00);

                                      reply[replyCnt++]=I2C_MasterWriteByte(0x04);

                                      reply[replyCnt++]=I2C_MasterSendStop();        

                                   

                                  // wait or read the status register

                                   

                                  // read the result, 2 bytes from register 0x8f

                                      reply[replyCnt++]=I2C_MasterSendStart(0x62,I2C_WRITE_XFER_MODE);

                                      reply[replyCnt++]=I2C_MasterWriteByte(0x8f);

                                      reply[replyCnt++]=I2C_MasterSendStop();        

                                      reply[replyCnt++]=I2C_MasterSendStart(0x62,I2C_READ_XFER_MODE);

                                      lidarData[0]=I2C_MasterReadByte(I2C_ACK_DATA);

                                      lidarData[1]=I2C_MasterReadByte(I2C_NAK_DATA);

                                      reply[replyCnt++]=I2C_MasterSendStop();