We are trying to receive GPS data to arduino and transfer it to laptop via bluetooth.
By testing separately, both GPS and Bluetooth work, but when we connect them both to arduino and try to run, we cannot receive GPS data.
We need to turn on receiving data when number 1 is pressed. Later on, we will need to change this '1' to value given by other sensors.
Any help would be nice and appreciated
This is the code
Also using Tera Term program on laptop. When testing only bluetooth with LED, Tera Term shows that everything works.
#include "TinyGPS++.h"
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(10, 11); //tx RX
SoftwareSerial serial_connection(5, 6);
TinyGPSPlus gps;
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
serial_connection.begin(9600);
Genotronex.begin(9600);
Genotronex.println("GPS Start");
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Genotronex.listen();
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,HIGH);
Genotronex.println("LED On D13 ON ! ");
serial_connection.listen();
while(serial_connection.available())//While there are characters to come from the GPS
{
gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
}
if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
{
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
Genotronex.println("Satellite Count:");
Genotronex.println(gps.satellites.value());
Genotronex.println("Latitude:");
Genotronex.println(gps.location.lat(), 6);
Genotronex.println("Longitude:");
Genotronex.println(gps.location.lng(), 6);
Genotronex.println("Speed MPH:");
Genotronex.println(gps.speed.mph());
Genotronex.println("Altitude Feet:");
Genotronex.println(gps.altitude.feet());
Genotronex.println("");
}}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,LOW);
Genotronex.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
I would suggest putting the BT on Serial (pins 0 & 1) and the GPS on AltSoftSerial (pins 8 & 9). Be sure to read about connecting the GPS device safely.
Then you can test with the Serial Monitor window. Enter the '0' or '1' commands and press Send. If the GPS is connected correctly, you should be able to get the sketch working.
Then try sending the commands through the BT. It should work the same.
You will have to disconnect pin 0 to upload new sketches over USB. Some people put a switch in that wire so it's easier.
#include <NMEAGPS.h>
const float FEET_PER_METER = 3.28084;
#include <AltSoftSerial.h>// import the serial library
AltSoftSerial gpsPort; // RX is 8 (to GPS tx), TX is 9 (to GPS rx)
#define Genotronex Serial // just an "alias" for Serial to make the code more readable
NMEAGPS gps; // the parser
gps_fix fix; // the struct with all the parsed values
const int LED_PIN=13; // led on D13 will show blink on / off
void setup() {
//Serial.begin(9600); // not needed if Genotronex *is* Serial
gpsPort.begin(9600);
Genotronex.begin(9600);
Genotronex.println("GPS Start");
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(LED_PIN,OUTPUT);
}
void loop() {
if (gps.available( gpsPort)) {
fix = gps.read(); // get the latest GPS info (all in one struct)
}
if (Genotronex.available()){
char BluetoothData=Genotronex.read();
if (BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(LED_PIN,HIGH);
Genotronex.println("LED On D13 ON ! ");
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
Genotronex.println("Satellite Count:");
Genotronex.println( fix.satellites );
Genotronex.println("Latitude:");
Genotronex.println( fix.latitude(), 6);
Genotronex.println("Longitude:");
Genotronex.println( fix.longitude(), 6);
Genotronex.println("Speed MPH:");
Genotronex.println( fix.speed_mph() );
Genotronex.println("Altitude Feet:");
Genotronex.println( fix.altitude() * FEET_PER_METER );
Genotronex.println();
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(LED_PIN,LOW);
Genotronex.println("LED On D13 Off ! ");
}
}
}
AltSoftSerial and NeoGPS are available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.