NACK repeated through serial monitor

Hi,

What would cause NACK to be repeatedly sent to the serial monitor? Is this just a bug?

To solve the problem I just unplugged the Arduino and then plugged it in again. But I was wondering if it would happen again.

Thanks.

For informed help, please read the post "How to use this forum" and follow the directions carefully.

Ok no problem.

/*------------------------------------------------------------------------------
  LIDARLite Arduino Library
  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));
  }
}

I would guess that the Arduino and the Lidar-Lite are not communicating.

You forgot to describe the wiring.

The wiring is described in the code.

"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"

As described in the original question, it works as its supposed to. But after a random amount of time it displays nack. This is fixed with a reset. None of the wiring is touched during this process.

So I want to know if it will happen again, and why.

Thanks.

Ok, I have now modified my code so that I can output into a text file into two columns.

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

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

The problem now is, every now and then, instead of outputting a distance measurement, it outputs nack.

An example output:

1 285
2 293
3 291
4 287
5 288
6 298
7 289
8 295
9 300
10 285
11 293
12 285
13 289
14 292
15 297
16 >nack
17 292
18 287
19 294
20 296
21 288
22 292
23 291
24 289
25 288
26 294
27 289
28 295
29 291
30 284
31 288
32 289
33 299
34 289
35 285
36 287
37 295
38 291
39 285
40 291
41 289
42 285
43 289
44 >nack
45 292
46 291
47 294
48 291
49 297
50 301
51 294

Does anyone know what nack means?

Thanks.

nack = "negative acknowledge".

The device is refusing to respond. Ignore the nack responses and it will work.

So is that just a string “>Nack” ?

It is an error message that you can ignore.

I am asking how I do that.

Do I use an if statement e.g. if string == ">nack"

Or is it an error code?

I don't have much knowledge in error handling, so you will need to be more specific if you are going to help me.

Thanks.

I'm hoping there has been a solution since the last post here. After a period of successful sensing, I am having the same issue (constant prints of >nack) with the LIDARlite. I have the sensor hooked up to an LED so I can see brightness due to proximity from the LIDAR.

It looks like this error message can't be ignored because nothing is writing to the LED, and the serial plotter doesn't show anything. Have any ideas come up? I found this link that says these strings can be due to poor physical connection, but I have tried to reconnect several times with no success.

I'd appreciate any help!

srgochman: I'm hoping there has been a solution since the last post here. After a period of successful sensing, I am having the same issue (constant prints of >nack) with the LIDARlite. I have the sensor hooked up to an LED so I can see brightness due to proximity from the LIDAR.

It looks like this error message can't be ignored because nothing is writing to the LED, and the serial plotter doesn't show anything. Have any ideas come up? I found this link that says these strings can be due to poor physical connection, but I have tried to reconnect several times with no success.

I'd appreciate any help!

Looks like the solution wast just ignore the message. What happens when you add code to do that?

Paul

Hi Paul,

I'm not exactly sure what you mean by "What happens when you add code to do that?" But it looks like I can't just ignore the >nack message because it is preventing the code I wrote from lighting an LED. Any ideas?

Sam

I’d appreciate any help!

Since you forgot to post your code and the required information about which library you are using, it is unlikely that you can expect help.

Please read and follow the instructions in the “How to use this forum” post.

If you are getting the just nack message, you are not getting distance information.

Sorry about that, jremington. I was working off of the same code as the original poster. But here is the code I am using just in case. I am using the Wired.h and LIDARLite.h libraries. And I have connected my system as described in the Connections part of the code below.

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

  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>

#define bLED 3
#define gLED 5
#define rLED 6

LIDARLite myLidarLite;

void setup()
{
  Serial.begin(9600); // Initialize serial connection to display distance readings
  pinMode(bLED, OUTPUT);
  pinMode(gLED, OUTPUT);
  pinMode(rLED, OUTPUT);

  /*
    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
  int dist = myLidarLite.distance();
  Serial.print(dist);
  Serial.println(" cm");

  int dist_adj = map(dist, 0, 600, 0, 255);

  if(dist_adj>255){
    dist_adj=255;
  }

  analogWrite(bLED, dist_adj);
  analogWrite(gLED, dist_adj);
  analogWrite(rLED, dist_adj);
  Serial.println(dist_adj);
}

Also, I wasn’t always getting the nack message. It was working well and I got distance information with this code, and then when I came back later in the day, it only gave the nack message and no distance information. I hope I provided enough details to be helped. Thanks!

it only gave the nack message

Check your wiring by using the I2C scanner program.

Any ideas?

Through troubleshooting, I also tried removing and reversing the 680uF capacitor on the breadboard, skipping over the breadboard to wire the sensor directly to the Arduino (with no capacitor), and even PWM mode. All trials gave me the same repeated > nack printed to serial, except for trying PWM, which gave intermittent readings between periods of not printing anything. For PWM, I followed the wiring instructions from the manual and used the GetDistancePwm.ino code from the LIDARLite.h library.

I could use some recommendations from people who have more experience than me, as I'm working under a deadline. Thanks!

jremington, sorry, I didn't see your last response. I tried the I2C scanner, and for a while it said there was no device detected. I kept tinkering with the wiring, and then it was detected and the scanner works!

For documentation's sake, I unplugged all other devices from my breadboard to eliminate other things draining power before the power gets to the LIDAR. This in combination with securing the LIDAR's finicky wire connections solved the problem for me.

Also, I added devices back in between the power source and the LIDAR to isolate the specific problem, and I don't think that the problem is devices in between the power and the LIDAR in general; some like an LED breakout still allows the sensor to work, whereas my LaserPING sensor prevented the LIDAR from working. I dont know if that is a function of how much power each requires.

Thanks for the help!

Glad that you have a short term solution, but it sounds like your power supply is inadequate.

Don't try to power the LIDAR from the Arduino 5V output, despite that recommendation from Garmin. The requirement for a 680 uF capacitor is already a warning sign.

While that may work in isolation, adding any other LEDs/modules will very likely overload the Arduino on board voltage regulator, especially if you are attempting to power the Arduino with more than about 7 V.