Im in a the process of making a GPS RC car, with the ability to send new waypoints to the car from a remote, and have the car send back its current coordinates. I've gotten pretty much everything working, with one exception. The numbers I'm trying to send (the gps coordinates) are too large to send. The gps numbers are about 8-9 digits, while in all the research I've done, it looks like the largest number I can send is something like 5 digits (i dont remember the exact number).
Any Idea how to do this?
Everything that prints out on the transmit side comes out correctly, but on the recieve side I get completely different numbers, and much shorter.
Here is the Transmitter code (basic gps and rfm12b code):
#include <JeeLib.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
TinyGPS gps;
SoftwareSerial ss(4, 3);
typedef struct
{
long lat1, long1;
}
payload;
payload test;
long flat, flon;
float lat2, long2;
void setup()
{
Serial.begin(115200);
ss.begin(4800);
rf12_initialize(1, RF12_433MHZ, 33);
Serial.print("Simple TinyGPS library v. ");
Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
}
void loop()
{
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;
}
}
if (newData)
{
unsigned long age;
gps.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);
}
test.lat1 = flat/10;
test.long1 = -flon/10;
int i=0;
lat2 = test.lat1, 5;
long2 = test.long1, 5;
lat2= lat2/100000, 5;
long2 = long2/100000, 5;
while (rf12_canSend() && i<10) {
rf12_recvDone();
i++;
}
rf12_sendStart(0, &test, sizeof test);
Serial.print(" ");
Serial.print(test.lat1);
Serial.print(" ");
Serial.print(test.long1);
Serial.print(" ");
Serial.print(lat2, 5);
Serial.print(" ");
Serial.println(long2, 5);
}
Reciever Code:
#include <JeeLib.h>
typedef struct // create structure - a neat way of packaging data for RF comms
{
int lat1, long1;
}
payload;
payload test;
float lat2, long2;
void setup () {
Serial.begin(115200);
rf12_initialize(1, RF12_433MHZ, 33);
}
void loop () {
if (rf12_recvDone() && rf12_crc == 0) {
Serial.print("OK ");
test=*(payload*) rf12_data;
lat2 = test.lat1;
long2 = test.long1;
lat2= lat2/100000, 5;
long2 = long2/100000, 5;
Serial.print(test.lat1);
Serial.print(" ");
Serial.print(test.long1);
Serial.print(" ");
Serial.print(lat2, 5);
Serial.print(" ");
Serial.println(long2, 5);
delay(100);
}
}