Hello, I'm trying to send some NEO-6M coordinates to a label box using the HC-06 Module, but it seems it's not working. Can anyone help me out? I'm also using the Arduino Mega
In this case, I'm using the NEO 6M as Serial2 and HC-06 as Serial3 by the way
#include <TinyGPSPlus.h>
TinyGPSPlus gps;
char x = 0;
int IN1 = 4;
int IN2 = 5;
int IN3 = 6;
int IN4 = 7;
void setup()
{
Serial.begin(115200);
Serial3.begin(9600);
Serial2.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop(){
x = Serial3.read();
if(x=='2'){ //Forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}else if (x=='1'){ //backwards
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}else if (x=='4'){ //right
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}else if (x=='3'){ //left
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}else if (x=='5'){ //stop
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
getGPSData();
}
void getGPSData() {
while (Serial2.available() > 0) {
if (gps.encode(Serial2.read())) {
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(" lll ");
Serial.print(gps.location.lng(), 6);
}else{
Serial.print("Invalid");
}
}
}
return "No GPS data available";
}