Or in other words - post the latest version of your code. Don't overwrite the existing one.
srnet:
But you cant have removed all the gps. function calls, the compiler is saying you have not.And tells you the ones you have not removed are on lines 19 and 21.
srnet:
But you cant have removed all the gps. function calls, the compiler is saying you have not.And tells you the ones you have not removed are on lines 19 and 21.
The GPS on lines 19 and 21 belong to
BLYNK_WRITE(V2)
{
GpsParam gps(param);
Serial.println("Received remote GPS: ");
Serial.print(gps.getLat(), 7);
Serial.print(", ");
Serial.println(gps.getLon(), 7);
}
Latest Version of code:
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
#include <TinyGPS++.h>
#include <math.h>
#include "TinyGPS++.h" /* try to remove these 2 includes */
#include "SoftwareSerial.h"
#define TxD 8
#define RxD 9
SoftwareSerial serial_connection(0,1);
SoftwareSerial bluetoothSerial(TxD, RxD);
TinyGPSPlus arduino;
float lat2 = gps.getLat();
float lat1 = arduino.location.lat();
float lon2 = gps.getLon();
float lon1 = arduino.location.lng();
double latR1;
double latR2;
double lonR1;
double lonR2;
double dlon;
double dlat;
double a;
double e;
double d;
double R = 6371.00;
double toDegrees = 57.295779;
char sb[10];
char auth[] = "b3a6efffe4424417b71b3184fc24c61b";
BLYNK_WRITE(V2)
{
GpsParam gps(param);
Serial.println("Received remote GPS: ");
Serial.print(gps.getLat(), 7);
Serial.print(", ");
Serial.println(gps.getLon(), 7);
}
void setup()
{
Serial.begin(9600);
bluetoothSerial.begin(9600);
Blynk.begin(bluetoothSerial, auth);
serial_connection.begin(9600);
Serial.println("GPS Start");
}
void loop()
{
Blynk.run();
while(serial_connection.available())
{
Serial.println("There is connection to GPS!");
arduino.encode(serial_connection.read());
}
if(arduino.location.isUpdated())
{
Serial.println("Satellite Count:");
Serial.println(arduino.satellites.value());
Serial.println("Latitude:");
Serial.println(arduino.location.lat(), 6);
Serial.println("Longitude:");
Serial.println(arduino.location.lng(), 6);
Serial.println("Speed MPH:");
Serial.println(arduino.speed.mph());
Serial.println("Altitude Feet:");
Serial.println(arduino.altitude.feet());
Serial.println("");
}
}
void calcDist()
{
Serial.begin(9600);
float delLat = abs(lat1-lat2)*111194.9;
float delLong = 111194.9*abs(lon1-lon2)*cos(radians((lat1+lat2)/2));
float distance = sqrt(pow(delLat,2)+pow(delLong,2));
Serial.print("Distance to destination(KM): ");
Serial.println(distance,7);
lonR1 = lon1*(PI/180);
lonR2 = lon2*(PI/180);
latR1 = lat1*(PI/180);
latR2 = lat2*(PI/180);
dlon = lonR2 - lonR1;
dlat = latR2 - latR1;
double x = cos(latR2)*sin(lonR2-lonR1);
double y = cos(latR1)*sin(latR2)-sin(latR1)*cos(latR2)*cos(lonR2-lonR1);
float brRad = atan2(x, y);
float reqBear = toDegrees*brRad;
Serial.print("Bearing(°): ");
Serial.println(reqBear, 7);
}
What do you mean, "/* try to remove these 2 includes */"? They don't look like they belong there. Did you try? What happened?
aarg:
What do you mean, "/* try to remove these 2 includes */"? They don't look like they belong there. Did you try? What happened?
Oh just ignore that part sorry.
Back to the error, which is:
GPS_final3:19: error: 'gps' was not declared in this scope
float lat2 = gps.getLat();
^
GPS_final3:21: error: 'gps' was not declared in this scope
float lon2 = gps.getLon();
^
exit status 1
'gps' was not declared in this scope
VanillaUnicorn:
Oh just ignore that part sorry.
Are you sure the compiler is ignoring it?
BLYNK_WRITE(V2)
{
GpsParam gps(param);
gps is declared inside the scope of BLYNK_WRITE(), so it's undefined outside it.
aarg:
BLYNK_WRITE(V2)
{
GpsParam gps(param);
gps is declared inside the scope of BLYNK_WRITE(), so it's undefined outside it.
I put it outside and now it shows:
error: 'param' was not declared in this scope GpsParam gps(param);
Maybe it's yet another, local use of "gps". Put it back and find out where the global gps object is defined.
aarg:
Maybe it's yet another, local use of "gps". Put it back and find out where the global gps object is defined.
Sorry I don't understand
VanillaUnicorn:
Sorry I don't understand
Do you understand any of the code?
Sorry I'm abit new but I know all the code and what it does.
I don't understand how I can find out where the global gps object is defined.
VanillaUnicorn:
Sorry I'm abit new but I know all the code and what it does.
Did you write it ?
Did you test the individual bits of code before glueing it all togerther ?
srnet:
Did you write it ?Did you test the individual bits of code before glueing it all togerther ?
I did not write it. I got the code from other websites.
I had individual bits of code that was able to work perfectly alone.
The errors began when I glued the codes together.
So any ways to fix the error in post#24?
VanillaUnicorn:
Latest Version of code:#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
#include <TinyGPS++.h>
#include <math.h>
#include "TinyGPS++.h" /* try to remove these 2 includes */
#include "SoftwareSerial.h"
#define TxD 8
#define RxD 9
SoftwareSerial serial_connection(0,1);
SoftwareSerial bluetoothSerial(TxD, RxD);
TinyGPSPlus arduino;
float lat2 = gps.getLat();
float lat1 = arduino.location.lat();
float lon2 = gps.getLon();
float lon1 = arduino.location.lng();
double latR1;
double latR2;
double lonR1;
double lonR2;
double dlon;
double dlat;
double a;
double e;
double d;
double R = 6371.00;
double toDegrees = 57.295779;
char sb[10];
char auth[] = "b3a6efffe4424417b71b3184fc24c61b";
BLYNK_WRITE(V2)
{
GpsParam gps(param);
Serial.println("Received remote GPS: ");
Serial.print(gps.getLat(), 7);
Serial.print(", ");
Serial.println(gps.getLon(), 7);
}
void setup()
{
Serial.begin(9600);
bluetoothSerial.begin(9600);
Blynk.begin(bluetoothSerial, auth);
serial_connection.begin(9600);
Serial.println("GPS Start");
}
void loop()
{
Blynk.run();
while(serial_connection.available())
{
Serial.println("There is connection to GPS!");
arduino.encode(serial_connection.read());
}
if(arduino.location.isUpdated())
{
Serial.println("Satellite Count:");
Serial.println(arduino.satellites.value());
Serial.println("Latitude:");
Serial.println(arduino.location.lat(), 6);
Serial.println("Longitude:");
Serial.println(arduino.location.lng(), 6);
Serial.println("Speed MPH:");
Serial.println(arduino.speed.mph());
Serial.println("Altitude Feet:");
Serial.println(arduino.altitude.feet());
Serial.println("");
}
}
void calcDist()
{
Serial.begin(9600);
float delLat = abs(lat1-lat2)111194.9;
float delLong = 111194.9abs(lon1-lon2)*cos(radians((lat1+lat2)/2));
float distance = sqrt(pow(delLat,2)+pow(delLong,2));
Serial.print("Distance to destination(KM): ");
Serial.println(distance,7);
lonR1 = lon1*(PI/180);
lonR2 = lon2*(PI/180);
latR1 = lat1*(PI/180);
latR2 = lat2*(PI/180);
dlon = lonR2 - lonR1;
dlat = latR2 - latR1;
double x = cos(latR2)*sin(lonR2-lonR1);
double y = cos(latR1)*sin(latR2)-sin(latR1)*cos(latR2)*cos(lonR2-lonR1);
float brRad = atan2(x, y);
float reqBear = toDegrees*brRad;
Serial.print("Bearing(°): ");
Serial.println(reqBear, 7);
}
The error is:
GPS_final3:19: error: 'gps' was not declared in this scope
float lat2 = gps.getLat();
^
GPS_final3:21: error: 'gps' was not declared in this scope
float lon2 = gps.getLon();
^
exit status 1
'gps' was not declared in this scope
However, I needed the gps to make the code work here.
BLYNK_WRITE(V2)
{
GpsParam gps(param);
Serial.println("Received remote GPS: ");
Serial.print(gps.getLat(), 7);
Serial.print(", ");
Serial.println(gps.getLon(), 7);
}
BTW this part of the code finds the GPS coordinates of the phone using Blynk as seen in
How am I supposed to declare it? This code works if it is played alone, but now there are errors when I combine it with other codes.
Anyone knows how to overcome this error? Please I need help.
It looks to me like your code has multiple problems:
-
The function 'calcDist()' is never called.
-
These statements aren't inside any function:
float lat2 = gps.getLat();
float lat1 = arduino.location.lat();
float lon2 = gps.getLon();
float lon1 = arduino.location.lng();
- You're trying to access objects out of scope.
The last of these might be solved as suggested in Replies #9 and #15.
See:
https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/
gfvalvo:
It looks to me like your code has multiple problems:
The function 'calcDist()' is never called.
These statements aren't inside any function:
float lat2 = gps.getLat();
float lat1 = arduino.location.lat();
float lon2 = gps.getLon();
float lon1 = arduino.location.lng();
* You're trying to access objects out of scope. The last of these might be solved as suggested in Replies #9 and #15. See: https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/ https://www.arduino.cc/en/Tutorial/Variables
When I try to call the function, I get this:
error: expected constructor, destructor, or type conversion before ';' token calcDist();
Why is it necessay to put the statements inside a function?
The code shows that I am trying to access objects out of scope because when I put it in the correct scope, errors pop up.
I need help in making gps.getLat() and gps.getLon() in the correct scope so that I am able to access it without errors coming up.
Anybody knows how to do that?
VanillaUnicorn:
Why is it necessay to put the statements inside a function?
Because you get compiler errors if you do ?
The program has quite a few errors, and needs a considerable amount of re-writing.
However, it would really need someone with the particular hardware (and libraries) to test, to check if changes made actually worked.
I also have my doubts as to whether the individual bits of code have actually been tested, the GPS read routine looks plain wrong to me;
while(serial_connection.available())
{
Serial.println("There is connection to GPS!");
gps.encode(serial_connection.read());
}
With Serial and the GPS working at 9600, you read one character from the GPS, then print 28, by which time you will inevitably have missed a whole pile of characters from the GPS, unless you have infinite size buffers.