Hello,
I am trying to connect one Arduino uno to transmit GPS coordinates through nRF24L01 modules. As of right now, i have a steady communication between them but it is sending only one coordinate. I am receiving the first coordinate but after the first, it will not update when GPS is moved. I am using the BN-220 GPS module.
These are the current codes.
Transmitter code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
SoftwareSerial ss(4, 3);
RF24 radio(7,8); // CE, CSN
byte addresses[][6] = {"1Node", "2Node"};
struct dataStruct{
double latitude;
double longitude;
}gpsData;
void setup() {
Serial.begin(115200);
ss.begin(9600);
Serial.println("Setting up radio");
// Setup transmitter radio
radio.begin();
radio.openWritingPipe(0xF0F0F0F0E1LL);
radio.setChannel(0x76);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_2MBPS);
radio.stopListening();
radio.enableDynamicPayloads();
radio.powerUp();
Serial.println("Starting to send");
}
void loop() {
while (ss.available() > 0){
if (gps.encode(ss.read())){
if (gps.location.isValid()){
gpsData.longitude = gps.location.lng();
gpsData.latitude = gps.location.lat(); }
else{
gpsData.longitude = 0.0;
gpsData.latitude = 0.0; }
radio.write(&gpsData, sizeof(gpsData));
}
}
}
Receiver Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8); // CE, CSN
byte addresses[][6] = {"1Node","2Node"};
struct dataStruct{
double latitude;
double longitude;
}gpsData;
/*double fixedlat = 45.536968;
double fixedlong = -73.770729;
double lat1 = radians(fixedlat);
double long1 = radians(fixedlong);
*/
void setup() {
Serial.begin(115200);
// Setup receiver radio
radio.begin();
radio.openReadingPipe(1, 0xF0F0F0F0E1LL);
radio.setChannel(0x76);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_2MBPS);
radio.startListening();
radio.enableDynamicPayloads();
radio.powerUp();
}
void loop() {
if (radio.available()) {
radio.read(&gpsData, sizeof(gpsData));
Serial.print("Location: ");
Serial.print(radians(gpsData.latitude), 6);
Serial.print(", ");
Serial.print(radians(gpsData.longitude), 6);
Serial.println();
// Serial.println(lat1,6);
// Serial.println(long1,6);
}
}