Acquiring data from LeddarVu8 Lidar using Arduino - arduino-uno

I'm working on a room visualization project, similar to this (taken from this video):
Im using LeddarVu8 from leddartech (see image below), arduino uno (with rs485shield):
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?

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.

Related

Why SIM900 with ATMEGA328PU give different Result when given inputs from different PC's Arduino Serial Monitor?

I have Connected SIMCOM900 with ATMEGA328PU on a breadboard. It is giving correct outputs when inputs are given by one PC's Arduino Serial Monitor but with another PC's Arduino serial monitor's input (with the same circuit )it is not even responding. What is the reason behind? (Outputs are attached)
#include <SoftwareSerial.h>
//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 10
//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 11
//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
void setup()
{
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
//Being serial communication witj Arduino and SIM800
serialSIM800.begin(9600);
delay(1000);
Serial.println("Setup Complete!");
}
void loop()
{
//Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available())
{
serialSIM800.write(Serial.read());
}
}
Non Working Output -->
Setup Complete!
ATATAT
Working Output -->
Setup Complete!
AT
OK
AT+CENG?
+CENG: 0,0
OK
AT+CNETSCAN
Operator:"405803",MCC:405,MNC:803,Rxlev:62,Cellid:51A5,Arfcn:702
Operator:"405803",MCC:405,MNC:803,Rxlev:51,Cellid:51A7,Arfcn:709
Operator:"405803",MCC:405,MNC:803,Rxlev:45,Cellid:35D6,Arfcn:703
Operator:"405803",MCC:405,MNC:803,Rxlev:37,Cellid:51A6,Arfcn:707
Operator:"Airtel",MCC:404,MNC:45,Rxlev:30,Cellid:08EC,Arfcn:53
Operator:"Airtel",MCC:404,MNC:45,Rxlev:28,Cellid:08E9,Arfcn:55
Operator:"Airtel",MCC:404,MNC:45,Rxlev:25,Cellid:08EA,Arfcn:103
Operator:"Airtel",MCC:404,MNC:45,Rxlev:18,Cellid:AF79,Arfcn:59
Operator:"Airtel",MCC:404,MNC:45,Rxlev:22,Cellid:186B,Arfcn:60
Operator:"Airtel",MCC:404,MNC:45,Rxlev:30,Cellid:08EB,Arfcn:61
Operator:"Hutch-Kamataka",MCC:404,MNC:86,Rxlev:51,Cellid:11B5,Arfcn:725
Operator:"Hutch-Kamataka",MCC:404,MNC:86,Rxlev:51,Cellid:11B4,Arfcn:666
Operator:"Spice Telecom",MCC:404,MNC:44,Rxlev:37,Cellid:0A5D,Arfcn:22
Operator:"Spice Telecom",MCC:404,MNC:44,Rxlev:34,Cellid:0A5B,Arfcn:25
Operator:"Spice Telecom",MCC:404,MNC:44,Rxlev:33,Cellid:0A5C,Arfcn:17
Operator:"Bharat Karnataka",MCC:404,MNC:71,Rxlev:21,Cellid:DB93,Arfcn:76
It might be that you are not sending NL and CR.
Make sure that Both NL & CR are selected for line ending.

Arduino Uno + ESP8266 12E + Blynk + Relay

I started adventure with arduino and programming 2 months ago.So, I am new in this topics.
Until now I realized few projects including Blynk connected with arduino. The last one was similar to one described in topic but I used the ENC28j60 instead of ESP8266 module and then it worked fine.
The problem started with ESP module.
Short description of project:
The main idea is to control AC light with Blynk App support.
First of all I made a connection according to picture below:
As power source I used the USB phone charger connected with step by voltage converter to get in final the 3.3V source.
I additionally connected the Arduino Uno with relay module like this:
Arduino ====> Relay module
5V ====> VCC
GND ====> GND
Pin 5 ====> IN1
Everythink you can see in pictures below (sorry for quality)
And for now I did almost every step (with so many problems). Here I mean:
1. I checked if arduino is connected with ESP module by serial port -> system report "ready" status.
2. I upload the below (template) Arduino IDE sketch for my project:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";
void setup()
{
// Debug console--
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
And finally I started the New project in Blynk. I set the Arduino uno as a hardware model and WiFi as connection type. Then I added the Button and set the Output to D5.
And now (close to the end of project) I met with a problem. After pushing the connect button (in up-right corner) I receive the information that device is connected (Online). Then when I try to push the button to Active Relay - nothing happens.
Whats more. I tried with different pins on Arduino with the same results. And I don't know why (probably because I have still small knowladge) but when I set the Button output value to D2 - after connection when I push it then the diode on ESP module Turn OFF and Turn ON.
I tried to find solution on this forum and in many other places for last 3 days but without any results. That's why I decided to ask You for help. Do you know what did I wrong or what should I add to project to make connection between the Blynk and relay work correct?
Write if you will need some more or detailed information from my side.
Why are you using both the uno and the esp? You can just use the esp instead of the combo, will make your project less power hungry and smaller. If you wonder about using just the esp, you can use the nodemcu boards (which can be found for less that 4€ per unit in China).
I've some example sketches for this (with temperature and humidity), if you want to take a look at those.
When looking at the pictures and code you have postet, it seems that you have flashed the ESP with a Arduino sketch. This is fine if you would like to activate the relay directly with the ESP (without the Arduino UNO).
Then you just have to connect the relay to the ESP instead of to the Arduino. Unfortunately not all relay boards can operate with the 3.3V logic that the ESP supplies, but maybe you'r lucky.
On the other hand, if you would like to use the Arduino UNO with the ESP as Wi-Fi, then you would have to reflash the ESP with the original AT firmware. Then you could connect it to the Arduino and use a sketch that looks something like this.
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3);
// pin 3 connected to ESP RX and pin 2 connected to ESP TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
Blynk.run();
}
And you should remove the connection between RST and GND on the Arduino

How do I read serial data from an arduino uno with batch on windows 10?

I'm trying, more specifically, to hibernate my computer with an infrared remote using arduino. I already have it set up so that the arduino registers the button on said infrared remote, and can then trigger an action. What I'm trying to code on my computer is a batch script that will constantly run and listen for serial data from the arduino. The theory is that when the arduino gets the infrared signal, it will blast a letter through serial, or 'o'. Then, the batch script on the computer will see that, and proceed to hibernate the computer. I have already tried
MODE COM6:9600,N,8,1 >NUL
type COM6 > sample.txt
to test whether or not windows could read the serial data, but the arduino just starting broadcasting a '1' for a tenth of a second every second. Once I ran this, and a text file was generated that was completely blank. Here is the arduino code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write("Hello!");
delay(1000);
}

UART RX Interrurpt fired too early

I'm doing a small project, where I want to transmit a text via a cable to my Atmega328p.
I first created the project on an Arduino Uno (with pure C), where the transmission works.
Now I switched to a standalone 328p and tried it there.
But now the Problem is, that my RX-Complete Interrupt is fired too early. In fact it is even fired, when nothing has been transmitted. It will fired when I just touched the cable (the isolated parts) .
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/setbaud.h>
void setup(void){
CLKPR = 0;
//Set Output
DDRC |= (1 << PC0) | (1 << PC1) |(1 << PC2) |(1 << PC3) |(1 << PC4) | (1 << PC5);
DDRD |= (1 << PD6) | (1 << PD7);
// Interrupts
sei();
// Init UART
// Set baud
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= (1 << U2X0);
#else
UCSR0A &= ~(1 << U2X0);
#endif
// Enable UART Receive and Receivecomplete Interrupt
UCSR0B = (1<<RXEN0) | (1 << RXCIE0);
// Set frameformat to 8 Data and 1 Stopbit
UCSR0C = ((1<<UCSZ00)|(1<<UCSZ01));
}
int main(void){
setup();
while(1){
}
return 0;
}
ISR(USART_RX_vect){
// Enable some LEDs
}
Edit: Picture of my Setup:
I use the Arduiono just for Powering my Breadboard. 5V and GND are connected.
The AVR MKII ISP is Connected via some Pins to flash the µC. The two cables are used for UART RX.
The Pushbutton is just for RESET
Edit 2: I just tried to power it via an external source and a raspberrypi. There is the same effect everywhere
Of course. RXC flag is set when there are unread data in the receive buffer.
This flag is used to generate the RX interrupt.
Since you never read UDR inside your interrupt, this flag remains set, and, therefore just after interrupt routine is completed, it is starts again. And again. And again....
The Rx line should not be floating. Its a high impedance input and should be driven to a specific level. Your cables act like an antenna and if you touch the cable it gets worse because there is capacitive coupling between the cable and your body. This may result in high frequency noise on your input which may trigger the Rx interrupt.
Further make sure that the 328p local power supply is properly decoupled. I don't see any capacitors near the controller on your breadboard. Check GND connection between Arduino and 328p (mandatory).
Without looking at your setup it's hard to tell what's going wrong, but if you're touching an isolated cable and getting a response from the processor, then I would check common grounds between the devices if you're powering the ATMega via a battery, make sure the battery ground is touching the device that's receiving and transmitting, as any potential difference in power levels could cause the little magnetic field that you give off to be amplified into something that the core registers as a high bit.If possible, post a picture of your setup!
Also when programming with ATMel chips, burning the arduino bootloader and going the simple(r) C code way never hurt.

How to pass an integer from an Arduino to a C application on Mac OS X

What is the standard method to read values on an Arduino from a C application?
I have an accelerometer and a few poentiometers which I would like to bind to Cocoa controls, an NSSlider for example.
My arduino is currently connected to: /dev/cu.usbmodem26431 and I can read the values printed by the AnalogReadSerial code sample in the Serial Monitor.
How do I read from /dev/cu.usbmodem26431 ?
Cocoa Serial (Edit)
Three methods of interfacing with Objective C are presented here
http://arduino.cc/playground/Interfacing/Cocoa
Arduino Serial
If you know how to establish a Serial/USB connection then you can send the values as either string or binary to the Arduino.
In the setup() method on the Arduino you establish as Serial connection like this.
nb: using 115200 baud/speed for this example
Serial.begin(115200);
In the loop() method on the Arduino you can read data from the c application. here is a full Arduino example including how to send data back to the c application using Serial.print()
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(115200); // opens serial port, sets data rate to 115200 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
Source http://arduino.cc/en/Serial/read
The example above is very crude, you can use Serial.available() to see how much data is waiting to be read.
For strings you might want to use a \n line terminator or other type of terminator as an indicator for the end of a packet (to know when it has been fully received).
It is a good idea to design your own header and check sum to ensure data integrity but I don't bother with check sums for simple unimportant projects.
As an example, gps systems often send sentences when in string/text mode. If you look up the Arduino library called tinyGPS, you will see one way to read an entire sentence into different variables within an Arduino program.
This is an NMEA GPS sentence, do not use the same header in your projects, instead, design your own. This is just an example of how you might transmit multiple values (int, string, float etc) to an Arduino
$GPBWC,081837,,,,,,T,,M,,N,*13
http://aprs.gids.nl/nmea/

Resources