am having two GPS modules getting GPS coordinates of where they are placed on the ground. I want to send the two coordinates to another Arduino via the Bluetooth slave master module. I have the two coordinates each of them combined into their own structures(struct GeoTurn and struct GeoStop)
I am confused about how I could send the two sets of coordinates with start and end makers and how to add an identifier on each set of coordinates.
Is it also appropriate to send the structure or it won't work out in structure form?
My GPS modules code is below. Please check and advice which part I could include in the Bluetooth to send the coordinates
//Connect with pin 18 and 19
#include <TinyGPS++.h>
//long lat,lon; // create variable for latitude and longitude object
float lat,lon;
TinyGPSPlus gps; // create gps object
struct GeoTurn{
float lat;
float lon;
};
struct GeoStop{
float lat;
float lon;
};
void setup(){
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor
Serial2.begin(9600); // connect gps sensor
}
void loop(){
GeoTurn checkGPS() {
unsigned long start = millis();
while (millis() - start < GPS_UPDATE_INTERVAL) {
// If we recieved new location then take the coordinates and pack them into a struct
if (feedgps())
return gpsdump();
}
GeoLoc waypointLoc;
waypointLoc.lat = 0.0;
waypointLoc.lon = 0.0;
return waypointLoc;
}
// Get and process GPS data
GeoTurn gpsdump() {
GeoLoc waypointLoc;
waypointLoc.lat = gps.location.lat();
waypointLoc.lon = gps.location.lng();
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat, 7);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon, 7);
return waypointLoc;
}
// Feed data as it becomes available
bool feedgps() {
while (Serial1.available() > 0) {
if (gps.encode(Serial1.read()))
return true;
}
return false;
}
GeoStop checkGPS() {
unsigned long start = millis();
while (millis() - start < GPS_UPDATE_INTERVAL) {
// If we recieved new location then take the coordinates and pack them into a struct
if (feedgps())
return gpsdump();
}
GeoLoc destinationLoc;
destinationLoc.lat = 0.0;
destinationLoc.lon = 0.0;
return destinationftLoc;
}
// Get and process GPS data
GeoStop gpsdump() {
GeoLoc destinationLoc;
destinationLoc.lat = gps.location.lat();
destinationLoc.lon = gps.location.lng();
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat, 7);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon, 7);
return destinationLoc;
}
// Feed data as it becomes available
bool feedgps()
{
while (Serial2.available() > 0) {
if (gps.encode(Serial2.read()))
return true;
}
return false;
}
}
The precision of a standard GPS is something like 10 meters. Plot the coordinates reported from a steady GPS and You will see that the GPS is almost "all over the place", varying more than most people think.
Using Bluetooth forces the 2 GPS to quite close to the Arduino and thereby to each other in order to make BT work.
Plotting the postions of the 2 GPS You will see them dancing around each other.
The Serial Input Basics forum post/tutorial explains how to use start and end markers for serial data transmission. They can be as simple as "<" and ">".
jremington:
Structures are of little or no use for this.
Structs actually make it super easy.
You can pass the struct to SerialTransfer.h for easy transfer of data from one Arduino to the other. You can install the library via the Arduino IDE's Libraries Manager.
Does SerialTransfer.h contain blocking code at least for the receiver?
115200 baud takes just under 87 micros per char, just under 1389 cycles. I hate to waste so many cycles just for some lame library to wait for a few bytes.
jremington:
The Serial Input Basics forum post/tutorial explains how to use start and end markers for serial data transmission. They can be as simple as "<" and ">".
Structures are of little or no use for this.
So which part do you prefer added to the start and end makers while sending?
Usually it's start marker byte followed by data bytes (like your two structs) followed by a CRC (circular redundancy check) made from the data bytes and then the end marker.
BTW by the old convention known as ASCII, start and end markers are STX = 2 and ETX = 3.
alexmunala:
So which part do you prefer added to the start and end makers while sending?
I can't make sense of the program in your Original Post because it is so poorly formatted - I find it impossible to see where parts begin and end. Please use the Auto Format tool to indent it consistently and re-post it in your next Reply.
If you want to send two values to be compatible with the style in the 3rd example in Serial Input Basics then do it like this
Serial.print('<');
Serial.print(waypointLoc.lat);
Serial.print(','); // a comma
Serial.print(waypointLoc.lon);
Serial.println('>');
Robin2:
I can't make sense of the program in your Original Post because it is so poorly formatted - I find it impossible to see where parts begin and end. Please use the Auto Format tool to indent it consistently and re-post it in your next Reply.
If you want to send two values to be compatible with the style in the 3rd example in Serial Input Basics then do it like this
Serial.print('<');
Serial.print(waypointLoc.lat);
Serial.print(','); // a comma
Serial.print(waypointLoc.lon);
Serial.println('>');
You can do the same with SoftwareSerial
...R
that would have been my second issue am having trouble compiling,ive tried auto format but still get the error function definition is not allowed here before '{'
bool feedgps()
{
while (Serial2.available() > 0) {
if (gps.encode(Serial2.read()))
return true;
}
return false;
}
Robin2:
I can't make sense of the program in your Original Post because it is so poorly formatted - I find it impossible to see where parts begin and end. Please use the Auto Format tool to indent it consistently and re-post it in your next Reply.
If you want to send two values to be compatible with the style in the 3rd example in Serial Input Basics then do it like this
Serial.print('<');
Serial.print(waypointLoc.lat);
Serial.print(','); // a comma
Serial.print(waypointLoc.lon);
Serial.println('>');
You can do the same with SoftwareSerial
...R
I have tried to edit and compiled it successfully, but now I am a little confused according to your reply you indicated specifically on which part to add to the start and end makers.
so for this case please check the code below, how can I send the two GPS's coordinates but each has its specific identifier such as waypoint for GPS attached to Serial1 and destination for GPS attached to Serial2.
How do I go about specifically identifying them and sending them separately using start and end makers?
//Connect with pin 18 and 19
#include <TinyGPS.h>
//long lat,lon; // create variable for latitude and longitude object
float lat,lon;
TinyGPS gps; // create gps object
void setup(){
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor
Serial2.begin(9600); // connect gps sensor
}
void loop(){
while(Serial1.available()){ // check for gps data
if(gps.encode(Serial1.read()))// encode gps data
{
gps.f_get_position(&lat,&lon); // get latitude and longitude
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat,6);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon,6);
}
while(Serial2.available()){ // check for gps data
if(gps.encode(Serial2.read()))// encode gps data
{
gps.f_get_position(&lat,&lon); // get latitude and longitude
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat,6);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon,6);
}
}
}
}
alexmunala:
I have tried to edit and compiled it successfully, but now I am a little confused according to your reply you indicated specifically on which part to add to the start and end makers.
I showed how to place start and end markers before and after some data but I did not try to show where in the program the code for sending the data should go, simply because I do not know what you are trying to achieve.
The code you posted in Reply #9 is still not properly formatted. Use the AutoFormat tool all the time. As well as making code easier to read it helps to find the cause of the sort of problem you mentioned in Reply #8
function definition is not allowed here before '{'
Robin2:
I showed how to place start and end markers before and after some data but I did not try to show where in the program the code for sending the data should go, simply because I do not know what you are trying to achieve.
The code you posted in Reply #9 is still not properly formatted. Use the AutoFormat tool all the time. As well as making code easier to read it helps to find the cause of the sort of problem you mentioned in Reply #8
...R
I am sorry, I've tried the autoformat.but to no success..I cant identify the problem.
Please advise appropriately what the problem could be. I'll appreciate
alexmunala:
I am sorry, I've tried the autoformat.but to no success
The auto-format does not itself give you success. But if you post the code after using Auto Format I will find it much easier to help you.
The whole point of Auto Format is to make code easier to read.
Also (referring to my Reply #10) you have not explained what you want to achieve so that I can understand where in the program the sending code should go.
Robin2:
The auto-format does not itself give you success. But if you post the code after using Auto Format I will find it much easier to help you.
The whole point of Auto Format is to make code easier to read.
Also (referring to my Reply #10) you have not explained what you want to achieve so that I can understand where in the program the sending code should go.
...R
the program after AutoFormat is here below
//Connect with pin 18 and 19
#include <TinyGPS++.h>
//long lat,lon; // create variable for latitude and longitude object
float lat, lon;
TinyGPSPlus gps; // create gps object
struct GeoTurn {
float lat;
float lon;
};
struct GeoStop {
float lat;
float lon;
};
#define GPS_UPDATE_INTERVAL 1000
void setup() {
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor
Serial2.begin(9600); // connect gps sensor
}
void loop()
{
GeoTurn checkGPS() {
unsigned long start = millis();
while (millis() - start < GPS_UPDATE_INTERVAL) {
// If we recieved new location then take the coordinates and pack them into a struct
if (feedgps())
return gpsdump();
}
GeoLoc waypointLoc;
waypointLoc.lat = 0.0;
waypointLoc.lon = 0.0;
return waypointLoc;
}
// Get and process GPS data
GeoTurn gpsdump()
{
GeoLoc waypointLoc;
waypointLoc.lat = gps.location.lat();
waypointLoc.lon = gps.location.lng();
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat, 7);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon, 7);
return waypointLoc;
}
bool feedgps()
{
while (Serial1.available() > 0) {
if (gps.encode(Serial1.read()))
return true;
}
return false;
}
GeoStop checkGPS()
{
unsigned long start = millis();
while (millis() - start < GPS_UPDATE_INTERVAL) {
// If we recieved new location then take the coordinates and pack them into a struct
if (feedgps())
return gpsdump();
}
GeoLoc destinationLoc;
destinationLoc.lat = 0.0;
destinationLoc.lon = 0.0;
return destinationLoc;
}
GeoStop gpsdump()
{
GeoLoc destinationLoc;
destinationLoc.lat = gps.location.lat();
destinationLoc.lon = gps.location.lng();
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat, 7);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon, 7);
return destinationLoc;
}
// Feed data as it becomes available
//connect pin 16 and 17
// Feed data as it becomes available
bool feedgps()
{
while (Serial2.available() > 0) {
if (gps.encode(Serial2.read()))
return true;
}
return false;
}
}
what I need to achieve:
I need to get the two GPS coordinates ( the GPS modules are attached to one Mega 2560, separated around 5m apart), send them via Bluetooth module to another module to be used as a waypoint and destination on an autonomous car.
//Connect with pin 18 and 19
#include <TinyGPS++.h>
//long lat,lon; // create variable for latitude and longitude object
float lat, lon;
TinyGPSPlus gps; // create gps object
struct GeoTurn {
float lat;
float lon;
};
struct GeoStop {
float lat;
float lon;
};
#define GPS_UPDATE_INTERVAL 1000
void setup() {
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor
Serial2.begin(9600); // connect gps sensor
}
void loop()
{
while (Serial2.available() > 0) {
if (gps.encode(Serial2.read()))
return true;
GeoTurn waypointLoc;
waypointLoc.lat = 0.0;
waypointLoc.lon = 0.0;
return waypointLoc;
// Get and process GPS data
waypointLoc.lat = gps.location.lat();
waypointLoc.lon = gps.location.lng();
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat, 7);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon, 7);
return waypointLoc;
}
while (Serial2.available() > 0) {
if (gps.encode(Serial2.read()))
return true;
GeoStop destinationLoc;
destinationLoc.lat = 0.0;
destinationLoc.lon = 0.0;
return destinationLoc;
destinationLoc.lat = gps.location.lat();
destinationLoc.lon = gps.location.lng();
Serial.print("Position: ");
//Latitude
Serial.print("Latitude: ");
Serial.print(lat, 7);
Serial.print(",");
//Longitude
Serial.print("Longitude: ");
Serial.println(lon, 7);
return destinationLoc;
}
}
I've eliminated the CheckGPS function and done some editings...
Above is a program i have edited..please go through it
i have Auto Formatted and am receiving an error that (return statement with a value, in function returning void [-fpermisive]
what could be the issue?