0

I am trying to read data from an XV-11 sensor using the description of the format found here https://xv11hacking.wikispaces.com/LIDAR+Sensor. This is the code I am currently using to communicate with the computer by USB and the sensor with software serial on an arduino uno.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  mySerial.begin(115200);
}

int count = 0;

void loop() 
{ 
    if(mySerial.available())
    {
      byte in = mySerial.read();
      Serial.println(in, HEX);
    }
}

However, the data I am receiving on the computer is inconsistent with what I expect. For example, I am expecting a 0xFA byte every 22 bytes, however this only sometimes happens. Many times extra or fewer bytes appear in the middle of the data. I am using the 5 volt arduino serial communication, however I have heard that it is still compatible with 3.3 V sensor communication, so I doubt it is the problem. I don't thinkthe sensor is broken, as it is new from a working unit.

2
  • 3.3v is "on the edge" of communication with 5v. Also the Ardunoo's TX must go through a level shifter of some form (resistor divider would do) to drop it to the 3.3v of the sensor or you could damage the sensor. Also, you do have the grounds connected together don't you...?
    – Majenko
    Dec 11, 2015 at 10:55
  • I am only receiving data from the sensor so the arduino tx isn't even connected to the sensor. The sensor is connected to the arduino 5V and ground pins Dec 11, 2015 at 12:10

2 Answers 2

1

Soft Serial is totally unreliable. You may have a better error rate at other baud rates, but you will never achieve the same as a hardware based serial connection. I'd switch my debugging connection to the software serial, nd use the hardware serial for the XV-11.

0

The 'Serial' baud rate is too low compared to the baud rate of 'mySerial'. It could be causing you to lose bytes as the Serial buffer overflows, especially if the sensor transmits a lot of values in a relatively short interval. Increase the Serial baud rate to 115200 and see how it goes.

Your Answer

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

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