Basically I am using one Arduino as transmitter to send latitude and longitude data from one Arduino to another wirelessly. From transmitter I am outputting data in this format: 12223,123232. Longitude and latitude separated by coma. The code below saves these values into an array I want to merge this code with the gps code. So that I can add the value from transmitter to the value I have from gps which is connected to Arduino which is acting as receiver.
Code: Select all
#include <SoftwareSerial.h>
SoftwareSerial xbee(8, 9);
void setup() {
xbee.begin(9600);
}
void loop() // run over and over again
{
const int NUMBER_OF_FIELDS = 2; // how many comma-separated fields we expect
int fieldIndex = 0; // the current field being received
double values[NUMBER_OF_FIELDS]; // array holding values for all the fields
if (xbee.available()) {
for(fieldIndex = 0; fieldIndex < 2; fieldIndex ++)
{
values[fieldIndex] = xbee.parseFloat(); // get a numeric value
}
Serial.println(values[0],7);
Serial.println(values[1],7);
fieldIndex = 0; // ready to start over
}
if (Serial.available()) {
xbee.print((char)Serial.read());
}
delay(100);
}
Code: Select all
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO false
void setup()
{
Serial.begin(115200);
delay(5000);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
}
uint32_t timer = millis();
void loop()
{
char c = GPS.read();
if ((c) && (GPSECHO))
Serial.write(c);
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) /
return;
}
if (timer > millis()) timer = millis();
if (millis() - timer > 2000) {
timer = millis(); /
if (GPS.fix) {
float new_lat = GPS.latitude + value[0]; // this is how I want to use array to add the 2 values
float new_long = GPS.longitude + value[1];
Serial.print("Location: ");
Serial.print(new_long, 4); Serial.print(GPS.lon);
Serial.print(", ");
Serial.print(new_lat, 4); Serial.println(GPS.lat);
}
}
}