2

I have two Lidar Lites, connected to one APM. I have no issue with getting data from one of them, i use the code below

#include <I2C.h>
#define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite.
#define RegisterMeasure 0x00 // Register to write to initiate ranging.
#define MeasureValue 0x04 // Value to initiate ranging.
#define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call.
void setup(){
 Serial.begin(9600); //Opens serial connection at 9600bps. 
 I2c.begin(); // Opens & joins the irc bus as master
 delay(100); // Waits to make sure everything is powered up before sending or receiving data 
 I2c.timeOut(50); // Sets a timeout to ensure no locking up of sketch if I2C communication fails
}
void loop(){
 // Write 0x04 to register 0x00
 uint8_t nackack = 100; // Setup variable to hold ACK/NACK resopnses 
 while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
 nackack = I2c.write(LIDARLite_ADDRESS,RegisterMeasure, MeasureValue); // Write 0x04 to 0x00
 delay(1); // Wait 1 ms to prevent overpolling
 }
 byte distanceArray[2]; // array to store distance bytes from read function
 // Read 2byte distance from register 0x8f
 nackack = 100; // Setup variable to hold ACK/NACK resopnses 
 while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
 nackack = I2c.read(LIDARLite_ADDRESS,RegisterHighLowB, 2, distanceArray); // Read 2 Bytes from LIDAR-Lite Address and store in array
 delay(1); // Wait 1 ms to prevent overpolling
 }
 int distance = (distanceArray[0] << 8) + distanceArray[1]; // Shift high byte [0] 8 to the left and add low byte [1] to create 16-bit int
 // Print Distance
 Serial.println(distance);
}

i can get the distance fine, now have two connected, as follows

enter image description here

So my noob question is how to i get data from the 2, my guess is the wiring is ok.

I am using the code from https://github.com/PulsedLight3D/LIDARLite_v2_Arduino_Library

any help would be appreciated. thanks.

asked Jan 18, 2016 at 3:23
6
  • 2
    Did you give them distinct addresses? Commented Jan 18, 2016 at 3:24
  • if i run a I2C scanner it only shows one address and one device 0x62 , i can change the address, but it doesn't help as i still don't know whats the address of the 2nd one or if i have access to it. Commented Jan 18, 2016 at 3:30
  • 1
    Then the answer is "no". Commented Jan 18, 2016 at 3:33
  • The change address example sketch looks like giving each LIDAR an individual address is easy... Commented Jan 18, 2016 at 4:10
  • Diagram Multi-sensor PWR_EN Wiring shows each sensor's PWR_EN connected to independent digital outputs, so you should be able to call the changeAddressMultisensor function in your setup(). See Change I2C Address for Single Sensor You may have to use CTRL+F (find on page) "Change I2C Address for Single Sensor" as the href doesn't seem to work right on chrome or firefox. Commented Feb 5, 2016 at 23:37

1 Answer 1

1

Connect one at a time and run the change address sketch mentioned by Yeti.

Naturally change each one (one at a time) to different addresses (ex. 0x62, 0x64, 0x66).

i still don't know whats the address of the 2nd one

The address is what you change it to.

Then connect them all back up again and run the I2C scanner. You should see all 3 addresses.


documents state that address changes will be gone when i power it off

If that is true, save the address for each module in EEPROM. Then use that code to change the module address in setup.


See the address in the code you posted?

#define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite.

If you don't want to save the address in EEPROM just upload three versions of the sketch with a different address in each one. Note that the address must be even (eg. 0x62, 0x64, 0x66).

But it would be very simple just to read from EEPROM in setup and keep the address in a variable rather than a #define.

answered Jan 18, 2016 at 4:44
2
  • documents state that address changes will be gone when i power it off. Commented Jan 18, 2016 at 5:03
  • Then turn off two lidars with transistors, program the first one, turn on the second one, program it, then turn the last one on. That way there are no address conflicts while programming it as all the addresses are different while programming any of them. Commented Feb 5, 2016 at 22:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.