Lidar Light v3

Hi
I am using the Lidar light v3 in the I2C with the Arduino mega.
I downloaded the manual.
the manual tells me that the Blue wire is SDA and the Green wire is SCL.

the connection diagram shows that I only need 5 VDC and ground for power.

so I have 5vdc from the Arduino and the ground hooked up
I am using the sda pin20 to the sda blue wire
I have scl pin 21 to the scl green wire.

I ran the example and get " >nack" scrolling.

> nack
> nack
> nack
> nack
> nack
> nack

I'm not sure what I'm doing wrong

here is the test code

/*------------------------------------------------------------------------------

  LIDARLite Arduino Library
  v3/GetDistanceI2c

  This example shows how to initialize, configure, and read distance from a
  LIDAR-Lite connected over the I2C interface.

  Connections:
  LIDAR-Lite 5 Vdc (red) to Arduino 5v
  LIDAR-Lite I2C SCL (green) to Arduino SCL
  LIDAR-Lite I2C SDA (blue) to Arduino SDA
  LIDAR-Lite Ground (black) to Arduino GND

  (Capacitor recommended to mitigate inrush current when device is enabled)
  680uF capacitor (+) to Arduino 5v
  680uF capacitor (-) to Arduino GND

  See the Operation Manual for wiring diagrams and more information:
  http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf

------------------------------------------------------------------------------*/

#include <Wire.h>
#include <LIDARLite.h>

LIDARLite myLidarLite;

void setup()
{
  Serial.begin(115200); // Initialize serial connection to display distance readings

  /*
    begin(int configuration, bool fasti2c, char lidarliteAddress)

    Starts the sensor and I2C.

    Parameters
    ----------------------------------------------------------------------------
    configuration: Default 0. Selects one of several preset configurations.
    fasti2c: Default 100 kHz. I2C base frequency.
      If true I2C frequency is set to 400kHz.
    lidarliteAddress: Default 0x62. Fill in new address here if changed. See
      operating manual for instructions.
  */
  myLidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz

  /*
    configure(int configuration, char lidarliteAddress)

    Selects one of several preset configurations.

    Parameters
    ----------------------------------------------------------------------------
    configuration:  Default 0.
      0: Default mode, balanced performance.
      1: Short range, high speed. Uses 0x1d maximum acquisition count.
      2: Default range, higher speed short range. Turns on quick termination
          detection for faster measurements at short range (with decreased
          accuracy)
      3: Maximum range. Uses 0xff maximum acquisition count.
      4: High sensitivity detection. Overrides default valid measurement detection
          algorithm, and uses a threshold value for high sensitivity and noise.
      5: Low sensitivity detection. Overrides default valid measurement detection
          algorithm, and uses a threshold value for low sensitivity and noise.
    lidarliteAddress: Default 0x62. Fill in new address here if changed. See
      operating manual for instructions.
  */
  myLidarLite.configure(0); // Change this number to try out alternate configurations
}

void loop()
{
  /*
    distance(bool biasCorrection, char lidarliteAddress)

    Take a distance measurement and read the result.

    Parameters
    ----------------------------------------------------------------------------
    biasCorrection: Default true. Take aquisition with receiver bias
      correction. If set to false measurements will be faster. Receiver bias
      correction must be performed periodically. (e.g. 1 out of every 100
      readings).
    lidarliteAddress: Default 0x62. Fill in new address here if changed. See
      operating manual for instructions.
  */

  // Take a measurement with receiver bias correction and print to serial terminal
  Serial.println(myLidarLite.distance());

  // Take 99 measurements without receiver bias correction and print to serial terminal
  for(int i = 0; i < 99; i++)
  {
    Serial.println(myLidarLite.distance(false));
  }
}

How did you make the connections between the Lidar and the Arduino? Please post a clear, well focused photo of your setup. Hookup tutorial here.

Have you checked continuity of the connections? You can also run the I2C scanner program to determine whether a valid device/connection is present on the I2C bus.

Any pull-up resistors on your I2C bus?

I am using the sda pin20 to the sda green wire
I have scl pin 21 to the scl green wire.

One of these has to be blue and connected to SDA.

I changed the original post to reflect the correct color of the wire going to pin 20 on the mega.
I will get the pic's posted when I get home from work

I am using the sda pin20 to the sda blue wire

"Any pull-up resistors on your I2C bus?"
no, I am not using them. it was stated that was optional on what I looked at.
I looked again at the operations manual. it only shows " popup resistors" being used if I use PWM (page #3). and I am not

link to manual

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwio0buI-e7bAhUP0FMKHWj1DfYQFggpMAA&url=https%3A%2F%2Fstatic.garmin.com%2Fpumac%2FLIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf&usg=AOvVaw3PrCc40Eql6da7LMwfyTO1

here is a pic of the connections to the mega, it is a bit hard to see the colors but blue is to the left and green to the right in the pic.
I attached the pic. not sure how to post it into the post from my computer. the icon was asking for an URL and it was on my desktop.

fredguthrie:
"Any pull-up resistors on your I2C bus?"
no, I am not using them. it was stated that was optional on what I looked at.

A data sheet may mark them "optional" as they may be somewhere else already. No matter, they're not optional. Without pull-up resistors (1-10k - for a bus with a single device 10k is usually a good value) the I2C bus won't work. One for SDA to Vcc, one for SCL to Vcc.

I am using the Lidar light v3 in the I2C with the Arduino mega.

The Arduino Mega has 10K pullups on the I2C lines.

OP's pic: (sorry, that is useless)

Ah, didn't know that. Very convenient. So that's taken care of then.

Another thing: run an I2C scanner, and see if your device is found (it should report the I2C address 0x62 of the LiDAR device). If it doesn't return the address, there's probably a wiring issue (can be SDA/SCL swapped, no good contact, etc). If it does, the wiring is OK.

How is the LiDAR powered? The device needs 105 mA which may be a bit much for the Mega to power. Separate power supply may help. That big capacitor the manual states is also important (if you don't have 680µF a bit smaller or a bigger one should work as well).

ok, I didn't know about the pop resitors on the Arduino. I googled it and watched a video on it

https://www.baldengineer.com/arduino-internal-pull-up-resistor-tutorial.html

next, i ran the I2C scanner code below.
it found nothing, did a reset on all pins and bent them just a bit in case they where touching.
this seems to have fixed the issue

/**
 * I2CScanner.ino -- I2C bus scanner for Arduino
 *
 * 2009,2014, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called
void scanI2CBus(byte from_addr, byte to_addr, 
                void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, 0);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,DEC);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 8;       // lower addresses are reserved to prevent conflicts with other protocols
byte end_address = 119;       // higher addresses unlock other modes, like 10-bit addressing

// standard Arduino setup()
void setup()
{
    Wire.begin();

    Serial.begin(9600);                   // Changed from 19200 to 9600 which seems to be default for Arduino serial monitor
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,DEC);
    Serial.print(" to ");
    Serial.print(end_address,DEC);
    Serial.println("...");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
    
    // Set pin mode so the loop code works ( Not required for the functionality)
    pinMode(13, OUTPUT);
}

// standard Arduino loop()
void loop() 
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}

scanner output after reset

I2CScanner ready!
starting scanning of I2C bus from 8 to 119...
addr: 8       
addr: 9       	addr: 10       	addr: 11       	addr: 12       
addr: 13       	addr: 14       	addr: 15       	addr: 16       
addr: 17       	addr: 18       	addr: 19       	addr: 20       
addr: 21       	addr: 22       	addr: 23       	addr: 24       
addr: 25       	addr: 26       	addr: 27       	addr: 28       
addr: 29       	addr: 30       	addr: 31       	addr: 32       
addr: 33       	addr: 34       	addr: 35       	addr: 36       
addr: 37       	addr: 38       	addr: 39       	addr: 40       
addr: 41       	addr: 42       	addr: 43       	addr: 44       
addr: 45       	addr: 46       	addr: 47       	addr: 48       
addr: 49       	addr: 50       	addr: 51       	addr: 52       
addr: 53       	addr: 54       	addr: 55       	addr: 56       
addr: 57       	addr: 58       	addr: 59       	addr: 60       
addr: 61       	addr: 62       	addr: 63       	addr: 64       
addr: 65       	addr: 66       	addr: 67       	addr: 68       
addr: 69       	addr: 70       	addr: 71       	addr: 72       
addr: 73       	addr: 74       	addr: 75       	addr: 76       
addr: 77       	addr: 78       	addr: 79       	addr: 80       
addr: 81       	addr: 82       	addr: 83       	addr: 84       
addr: 85       	addr: 86       	addr: 87       	addr: 88       
addr: 89       	addr: 90       	addr: 91       	addr: 92       
addr: 93       	addr: 94       	addr: 95       	addr: 96       
addr: 97       	addr: 98 found!	addr: 99       	addr: 100       
addr: 101       	addr: 102       	addr: 103       	addr: 104       
addr: 105       	addr: 106       	addr: 107       	addr: 108       
addr: 109       	addr: 110       	addr: 111       	addr: 112       
addr: 113       	addr: 114       	addr: 115       	addr: 116       
addr: 117       	addr: 118       	addr: 119       	
done

I then ran the test code pointing at the ceiling
and put my hand at varying distances and saw the output change.

thank you all for your help.

one last request.
i would like to learn more about the popup resistors. to you have a good link you can post?

PULLUP resistors are typically used to set or "pull up" inputs to a defined voltage or HIGH logic level, often to Vcc (5 or 3.3V).

Pulldown resistors accomplish the same task but usually to LOW or ground.