LIDAR Lite I2C project

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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!

0 Likes
13 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
Anonymous
Not applicable

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

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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 🙂 

0 Likes
Anonymous
Not applicable

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 🙂 

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

 

   

Bob

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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

   

 

   

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

   

Thanks! 

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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();        

0 Likes