Search code examples
arduino-unolidar

Acquiring data from LeddarVu8 Lidar using Arduino


I'm working on a room visualization project, similar to this (taken from this video):

image from video

Im using LeddarVu8 from leddartech (see image below), arduino uno (with rs485shield):

Arduino + LeddarVu8 Setup

I've also used the code provided from leddartech of simple16channel (no lcd):

            #include "C:\Program Files (x86)\Arduino\libraries\Leddar.h"
            /*
             Simple Leddar(TM) Example - Without LCD
             Language: Arduino

             This program lists the detections read on the serial port of the Arduino.
             Can be used with Arduino IDE's Serial Monitor.

             Shields used:
             * RS-485 Shield

             Created 01 Jun. 2015
             by Pier-Olivier Hamel

             This example code is in the public domain.
            */
            Leddar16 Leddar1(115200,1);
            //Baudrate = 115200
            //Modbus slave ID = 01

            void setup()
            {
                //Initialize Leddar 
                Leddar1.init();
            }
            void loop()
            {
                char result = Leddar1.getDetections();
                if (result >= 0)
                {
                    for (int i = 0; i < Leddar1.NbDet; i++)
                    {
                        Serial.print("Segment: ");
                        Serial.print(Leddar1.Detections[i].Segment);
                        Serial.print("      Distance: ");
                        Serial.print(Leddar1.Detections[i].Distance);
                        Serial.print("\n");
                    }  
                }
                else
                {
                    Serial.print("Error: "); 
                    Serial.print((int)result);
                    Serial.print("\n");
                }
                delay(50);
            }

(from https://support.leddartech.com/downloads/files/89-leddarsdk3-2-0-pi2-tar-gz)

The problem is that serial monitor of the arduino only outputs a series of ?????. Why is that?


Solution

  • The problem is that serial monitor of the arduino only outputs a series of ?????. Why is that?

    Because you have connected the TX of the LIDAR to the TX of the Arduino. The Serial Monitor window "listens" to the Arduino TX pin (via USB), so the Serial Monitor is actually listening to the LIDAR. The LIDAR serial is running at 115200, but your Serial Monitor is probably set to 9600. When the baud rates don't match, you'll get garbage characters.

    Also notice that you have two serial TX pins connected to each other. This will also corrupt the characters if the Arduino and the LIDAR both try to transmit at the same time.

    You may be able to connect the LIDAR RX to the Arduino TX, and the LIDAR TX to the Arduino RX. This would allow you to see the Leddar library commands on the Serial Monitor window. It would also cause all Serial prints to go to the LIDAR (and the PC). This might be ok if the Leddar command packets have a special format. This would allow the Leddar to ignore your debug prints, because they would not formatted correctly.

    In that configuration, you would have to disconnect Arduino pin 0 to upload new sketches over USB. Some people put a switch in that wire to make it easy to disconnect.