Hello guys, I am quite new top programming but I need the following project to work so I was wondering if anyone can help.
I am trying to receive the coordinates to my phone using the blueterm app, I want it to send me an error message is the gps shield can not receive the coordinates. I have also added in a bit about boundaries so I will be notified when the device goes too far.
I have my circuit correctly set up and I can see a clear connection between my BlueSmirf Bluetooth shield and the Blueterm app.
Here is my code, its not correctly annotated yet.
#include <TinyGPS.h>
//This program is designed to send gps coordinates to a mobile phone via bluetooth,
//it should show some sort of indication when the gps sheild con not receive any coordinates
//and when the device travels outside a certain boundary.
#include <SoftwareSerial.h> // import the serial library
TinyGPS gps;
SoftwareSerial ss
(10, 11); // RX, TX
void setup() {
// this is the main code that will run once
Serial.begin(115200);
}
void loop()
{
// this is the main code that will run repeatedly
delay(5000);
if (Serial.available()){
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
char c = ss.read();
Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
//displays the coordinates
if (newData)
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print("LAT=");
Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(" LON=");
Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(" SAT=");
Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
Serial.print(" PREC=");
Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
if
// Sets the boundries
(flat > 53.471623);
Serial.print("Lost Connection - High!");
(flon > -2.240617);
Serial.print("Lost Connection - Right!");
(flat < 53.471555);
Serial.print("Lost Connection - Low!");
(flon < -2.241046);
Serial.print("Lost Connection - Left!");
}
//displays an error when the gpd shield can not receive the coordinates
gps.stats(&chars, &sentences, &failed);
Serial.print(" CHARS=");
Serial.print(chars);
Serial.print(" SENTENCES=");
Serial.print(sentences);
Serial.print(" CSUM ERR=");
Serial.println(failed);
if (chars == 0)
Serial.println("** No satellites connected **");
}
}
Thank You
Roy