Hello,
I'm currently working on my project about GPS data communication using RF433 module. The problem is the RX doesn't receive any GPS data when I print it on serial monitor.
Here is the code
TX
#include <TinyGPS.h>
#include <RH_ASK.h>//including the library
#include <SPI.h>// this is not used but needed to compile
#include <SoftwareSerial.h>
TinyGPS gps;
SoftwareSerial nss(0, 1);
RH_ASK driver(2000, 11, 12, 10, false);
struct dataStruct{
float DATA1 ;
float DATA2;
unsigned long counter;
} myData;
byte tx_buf[sizeof(myData)] = {0};
char gpsdata[26] ;
int led = 13;
long lat, lon;
float flat, flon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
//int year;
//byte month, day, hour, minute, second, hundredths;
void setup()
{
Serial.begin(115200); //PC<---> arduino 115200 baud
nss.begin(9600); //GPS---> arduino at 9600 baud // Debugging only
if (!driver.init())
Serial.println("init failed");
pinMode(led, OUTPUT);
Serial.print("GPS Testing");
myData.DATA1=lat;
myData.DATA2=lon;
//delay(2000);
}
void loop()
{
while (nss.available()) //while gps is connected properly & sending data to arduino
{
int c = nss.read(); //Read the GPS serial port
//Serial.write(c); //Display NMEA data for debugging purpose
if (gps.encode(c)) // Check the GPS data
{
getprint_pos(gps);
//debug_check();
Serial.print("nilai: ");
Serial.println(flat);
}
}
memcpy(tx_buf, &myData, sizeof(myData) );
byte zize=sizeof(myData);
driver.send((uint8_t *)tx_buf, zize);
driver.waitPacketSent();
myData.counter++;
}
void getprint_pos(TinyGPS &gps) //function to check & get valid GPS positional data
{
gps.get_position(&lat, &lon, &fix_age); //TinyGPS function for aquiring positional information
if (fix_age == TinyGPS::GPS_INVALID_AGE ) //Determine the valid data by checking the fix_age
Serial.println("No fix ever detected!");
else if (fix_age > 2000)
Serial.println("Data is getting STALE!");
else{
Serial.println("\nLatitude and longitude valid!");
flat = lat; //put the data into a float integer
flon = lon; //decimal calculations to be done while printing the value
Serial.print(flat/1000000, 6); //print latitude
if(flat>0)
Serial.println("*N");
else
Serial.println("*S");
Serial.print(flon/1000000, 6); //print longitude
if(flon>0)
Serial.println("*E");
else
Serial.println("*W");
}
}
void debug_check() //check n print the data to be sent to RX node for debugging
{
sprintf(gpsdata,"%ld,%ld,%s",lat,lon); //put these values in gpsdata
Serial.println(gpsdata);
}
RX
#include <RH_ASK.h>//including the library
#include <SPI.h>// this is not used but needed to compile
//So arguments are bitrate, receive pin (rx), transmit pin (tx),
//ppt pin, pttInverted. The last 2 are not used.
RH_ASK driver(2000, 11, 12, 10, false);
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
struct dataStruct{
float flat ;
float flon;
}myData;
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; //this is the buffer we use to save the received data
uint8_t buflen = sizeof(buf); //
if (driver.recv(buf, &buflen)) // Non-blocking
{
// Message with a good checksum received, dump it.
//driver.printBuffer("Got:", buf, buflen);
memcpy(&myData, buf, sizeof(myData));
Serial.println("");
Serial.print("Latitude: ");
Serial.print(myData.flat/1000000, 6);
if(myData.flat>0)
Serial.println("*N");
else
Serial.println("*S");
Serial.print(" Longitude: ");
Serial.print(myData.flon/1000000, 6);
if(myData.flon>0)
Serial.println("*E");
else
Serial.println("*W");
delay(2000);
/*
Serial.print("Received: ");
for (byte i = 0; i < buflen; i++)
{
Serial.print(char(buf[i]));
//Serial.print(buf[i]);
//Serial.print(buf[i],HEX);
}
Serial.println("");
*/
}
}
The results on the serial monitor for RX would be like this.
Latitude: 0.00
Longitude: 0.00
I got this code from TinyGPS data parsing & viewing it at the RF433 RX node - Programming Questions - Arduino Forum then I modified it. I am not so good in programming so I am perhaps missing something. Please give me guidance and any help would be appreciated.
Thank you very much!