I have been working on an project on Arduino Nano I have connected Benwake TF02 through Soft Serial port i have interfaced I2c 16X2 LCD to get the Display on LCD it is working fine. now i have connected Emic2 with it after connecting during testing it gives the message once and the program stops the displays is stagnant when i remove // before (//Serial2.begin(9600);//set the Baud rate of Arduino and computer serial port) the display goes blank and nothing works can any one help i am atteching the program i am not clear if this is happening due to usage of two serial ports.
Program
#include<SoftwareSerial.h>// soft serial port header file
SoftwareSerial Serial1(2,3); // define the soft serial port as Serial1, pin2 as RX, and pin3 as TX
#include "EMIC2.h"
SoftwareSerial Serial2(5,6);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,20,4);
const int ledPin = 13;
int dist;// LiDAR actually measured distance value
int strength;// LiDAR signal strength
int check;// check numerical value storage
int i;
int uart[9];// store data measured by LiDAR
const int HEADER=0x59;// data package frame header
EMIC2 emic;
void setup()
{
emic.begin(5,6);
pinMode(ledPin, OUTPUT);
emic.setVoice(8);
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
Serial.begin(9600);//set the Baud rate of Arduino and computer serial port
Serial1.begin(115200);//set the Baud rate of LiDAR and Arduino serial port
//Serial2.begin(9600);//set the Baud rate of Arduino and computer serial port
digitalWrite(ledPin, HIGH);
}
void loop()
{
if (Serial1.available())//check whether the serial port has data input
{
if(Serial1.read()==HEADER)// determine data package frame header 0x59
{
uart[0]=HEADER;
if(Serial1.read()==HEADER)//determine data package frame header 0x59
{
uart[1]=HEADER;
for(i=2;i<9;i++)// store data to array
{
uart*=Serial1.read();*
}
check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
if(uart[8]==(check&0xff))// check the received data as per protocols
{
dist=uart[2]+uart[3]*256;// calculate distance value
strength=uart[4]+uart[5]*256;// calculate signal strength value
Serial.print("dist = ");
Serial.print(dist);// output LiDAR tests distance value
Serial.print('\t');
Serial.print("strength = ");
Serial.print(strength);// output signal strength value
Serial.print('\n');
- lcd.setCursor(0,0);*
_ //dist=dist*256;_ - lcd.print("Dist = ");*
- lcd.print(dist);*
- lcd.print(" Cm ");*
if (dist < 10) { - // turn LED on:*
- digitalWrite(ledPin, LOW);*
emic.speak("Forward Collision Warning ");
emic.speak(dist); - } else {*
- // turn LED off:*
- digitalWrite(ledPin, HIGH);*
- }*
}
}
}
}
}
Lidar_with_emic.ino (2.07 KB)