Hello
I am working on a project which includes 3 Lidar-Lite v3 sensors. These should measure distances and print them to serial monitor. I want to use I2C which allows to use multiple sensors and connect them to SCL and SDA. PWM didn't work, I already tried that.
All three sensors have the same standard address which I need to change. I searched the forum, but it didn't work and the provided discussions are already closed. These are the links to the discussions:
Lidar lite V3 - Change i2c address
2 Garmin Lidar-Lite Sensors using I2C
change address of LIDAR-Lite v3
According to one discussion, I need to turn off the sensors, turn one on, change its address and then to the same for the second one, so I don't change the address for all sensors. I tried to do this:
#include <Wire.h>
#include <LIDARLite.h>
LIDARLite lidarLeft;
LIDARLite lidarFront;
LIDARLite lidarRight;
byte serialNumber[2];
const int sensorLeft_EN = 8;
const int sensorFront_EN = 9;
const int sensorRight_EN = 10;
char UNIT_ID_HIGH = 0x16;
char UNIT_ID_LOW = 0x17;
char I2C_ID_HIGH = 0x18;
char I2C_ID_LOW = 0x19;
char I2C_SEC_ADDR = 0x1a;
char I2C_CONFIG = 0x1e;
// LIDAR Sensor addresses
char lidarStd_ADDR = 0x62; // Default address
char lidarLeft_ADDR = 0x63; // New address for left sensor
char lidarFront_ADDR = 0x64; // New address for front sensor
void setup() {
// Define the power source (orange cable) as output to turn on/off the sensors
pinMode(sensorLeft_EN, OUTPUT);
pinMode(sensorFront_EN, OUTPUT);
pinMode(sensorRight_EN, OUTPUT);
// Disable all sensors
digitalWrite(sensorLeft_EN, LOW);
digitalWrite(sensorFront_EN, LOW);
digitalWrite(sensorRight_EN, LOW);
Serial.begin(115200); // Initialize serial connection
Wire.begin(); // Connect to the I2C bus
// Read serial number Left
digitalWrite(sensorLeft_EN, HIGH); // enable the left sensor
uint8_t serialHigh, serialLow; // 1. read the two byte serial number
Wire.beginTransmission(lidarStd_ADDR);
Wire.write(0x96);
Wire.endTransmission(false); // Don't release the bus
Wire.requestFrom(lidarStd_ADDR, 2); // Request 2 bytes
if (Wire.available() >= 2) {
serialHigh = Wire.read();
serialLow = Wire.read();
}
// Write serial number to new address
Wire.beginTransmission(lidarLeft_ADDR);
Wire.write(0x18); // Address to write high byte
Wire.write(serialHigh);
Wire.write(0x19); // Address to write low byte
Wire.write(serialLow);
Wire.write(0x1A); // Address to write new desired I2C address
Wire.write(lidarLeft_ADDR);
Wire.write(0x1E); // Address to disable default address
Wire.write(0x08); // Value to disable default address
Wire.endTransmission();
digitalWrite(sensorLeft_EN, LOW); // disable the left sensor
// Read serial number Front
digitalWrite(sensorFront_EN, HIGH); // enable the front sensor
Wire.beginTransmission(lidarStd_ADDR);
Wire.write(0x96);
Wire.endTransmission(false); // Don't release the bus
Wire.requestFrom(lidarStd_ADDR, 2); // Request 2 bytes
if (Wire.available() >= 2) {
serialHigh = Wire.read();
serialLow = Wire.read();
}
// Write serial number to new address
Wire.beginTransmission(lidarFront_ADDR);
Wire.write(0x18); // Address to write high byte
Wire.write(serialHigh);
Wire.write(0x19); // Address to write low byte
Wire.write(serialLow);
Wire.write(0x1A); // Address to write new desired I2C address
Wire.write(lidarFront_ADDR);
Wire.write(0x1E); // Address to disable default address
Wire.write(0x08); // Value to disable default address
Wire.endTransmission();
digitalWrite(sensorFront_EN, LOW); // disable the front sensor
// Enable all sensors
digitalWrite(sensorLeft_EN, HIGH);
digitalWrite(sensorFront_EN, HIGH);
digitalWrite(sensorRight_EN, HIGH);
// Set configuration to default and I2C to 400 kHz for all sensors
lidarLeft.begin(0, true);
lidarLeft.configure(0);
lidarFront.begin(0, true);
lidarFront.configure(0);
lidarRight.begin(0, true);
lidarRight.configure(0);
}
void loop() {
// Read and print distance from all sensors
Serial.print(lidarLeft.distance());
Serial.print(",");
Serial.print(lidarFront.distance());
Serial.print(",");
Serial.println(lidarRight.distance());
delay(100);
}
Compiling works, but the monitor only shows 0,0,0
This is the documentation:
User_Manual.pdf (749,7 KB)
What did I do wrong?
Thank you very much that you took your time reading through this and hopefully help me.
All the best!