4

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.

  1. Write 0x04 to register 0x00.
  2. Read register 0x01.
  3. Repeat step 2 until bit 0 (LSB) goes low.
  4. 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.

5
  • 1
    Pull-up resistors need to be connected to VCC, not to ground... VCC is up, ground would be down.
    – romkey
    Jun 17, 2023 at 22:03
  • Thank you romkey, I've corrected this. Unfortunately, I get exactly the same results having fixed the pull-up resistors. I have the resistors connected to 3.3V now. Jun 17, 2023 at 22:14
  • According to the Wiring diagram found here: static.garmin.com/pumac/LIDAR-Lite_v3HP_Instructions_EN.pdf The resistors appear to be connected to ground. But it refers to them as pull-up resistors in the reference table. Now I'm uncertain if the resistors should be connected to ground or power...EDIT: SCRATCH THAT! I misread the wiring diagram, they are connected to power. Jun 17, 2023 at 22:17
  • 2
    OH BOY! I solved it. I had to include wire.h and initiate Wire.begin(); in setup. Jun 17, 2023 at 23:10
  • Hey glad you got it working! You figured out the hard part on your own :)
    – romkey
    Jun 18, 2023 at 0:02

1 Answer 1

3

As romkey pointed out, I had the pull-up resistors wired wrong. Pull-up resistors are connected to power, not to ground.

Then I had to include wire.h and initiate Wire.begin(); in setup.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.