Go Down

Topic: NACK repeated through serial monitor (Read 377 times) previous topic - next topic

benjaminhoey

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.

jremington

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

benjaminhoey

Ok no problem.

Code: [Select]
/*------------------------------------------------------------------------------
  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));
  }
}

jremington

#3
Feb 16, 2017, 10:40 pm Last Edit: Feb 16, 2017, 10:40 pm by jremington
I would guess that the Arduino and the Lidar-Lite are not communicating.

You forgot to describe the wiring.

benjaminhoey

#4
Feb 18, 2017, 10:13 am Last Edit: Feb 18, 2017, 01:31 pm by benjaminhoey
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.


benjaminhoey

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

Code: [Select]
// 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.


jremington

nack = "negative acknowledge".

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

benjaminhoey


jremington

It is an error message that you can ignore.

benjaminhoey

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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy