Hey there Stack community. I'm working with the Particle Boron v4.1.0. I'm connecting a Garmin Lidar Lite V4 on I2C. I'm using the LIDARLite_v4LED.h header file found in the library given for this device, "LIDAR-Lite" and my goal here is to op-check the sensor, by taking readings in the simplest way according to the .h file.
Wiring: I've soldered 22AWG solid wire to each respective pin on the sensor: GND : black, going directly to ground. VCC : red, 3.3V pin on the Particle Boron. I2C SDA : blue, SDA Pin0 on the Particle Boron with a 4.7K ohm pull-up resistor, connected to ground on one end, and running to Pin0 on the Boron. I2C SCL : green, SCL Pin1 on the Particle Boron with a 4.7K ohm pull-up resistor, connected to ground on one end, and running to Pin1 on the Boron.
I've run an I2C scan which confirmed the address at 0x62.
According to the manual at: https://static.garmin.com/pumac/LIDAR-Lite%20LED%20v4%20Instructions_EN-US.pdf
To take a reading you must perform the following actions, which are embedded in the library's .h file functions:
"Obtaining Measurements from the I2C Interface You can obtain measurement results from the I2C interface.
- Write 0x04 to register 0x00.
- Read register 0x01.
- Repeat step 2 until bit 0 (LSB) goes low.
- Read two bytes from 0x10 (low byte 0x10 then high byte 0x11) to obtain the 16-bit measured distance in centimeters."
#include <LIDARLite_v4LED.h>
const int I2CADDRESS = 0X62;
uint16_t distance;
LIDARLite_v4LED L1;
void setup() {
Serial.begin(9600);
}
void loop() {
L1.takeRange(I2CADDRESS);
L1.waitForBusy(I2CADDRESS);
L1.getBusyFlag(I2CADDRESS);
distance = L1.readDistance(I2CADDRESS);
Serial.printf("Distance = %u\n", distance);
}
When I run the code above the Serial Monitor shows 0 continuously for the reading, which is incorrect.
Do you happen to see what I'm doing wrong?
Here is what's happening in each respective function call above:
void LIDARLite_v4LED::takeRange(uint8_t lidarliteAddress)
{
uint8_t dataByte = 0x04;
write(0x00, &dataByte, 1, lidarliteAddress);
} /* LIDARLite_v4LED::takeRange */
void LIDARLite_v4LED::waitForBusy(uint8_t lidarliteAddress)
{
uint8_t busyFlag;
do
{
busyFlag = getBusyFlag(lidarliteAddress);
} while (busyFlag);
} /* LIDARLite_v4LED::waitForBusy */
uint8_t LIDARLite_v4LED::getBusyFlag(uint8_t lidarliteAddress)
{
uint8_t statusByte = 0;
uint8_t busyFlag; // busyFlag monitors when the device is done with a measurement
// Read status register to check busy flag
read(0x01, &statusByte, 1, lidarliteAddress);
// STATUS bit 0 is busyFlag
busyFlag = statusByte & 0x01;
return busyFlag;
} /* LIDARLite_v4LED::getBusyFlag */
uint16_t LIDARLite_v4LED::readDistance(uint8_t lidarliteAddress)
{
uint16_t distance;
uint8_t * dataBytes = (uint8_t *) &distance;
// Read two bytes from registers 0x10 and 0x11
read(0x10, dataBytes, 2, lidarliteAddress);
return (distance);
} /* LIDARLite_v4LED::readDistance */
Thanks in advance for any assistance!
NOTE: The code doesn't show any errors. It's possible I damaged the chip on the sensor when I soldered, as I'm a newb to all of this! However, I've put two sensors together and tried them each separately with the same code, and got the same results in an attempt to rule this out. I did better soldering the second sensor, and find it highly unlikely I damaged them both.