Hey people …
for my graduation project i want to connect NRF24l01 with gps neo 6m to track children but unfortunately i have issues with receiving lat,long.
This is TR and RX code :
//transmitter
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
static const int RXPin = 3, TXPin = 4;
static const uint32_t GPSBaud = 9600;
SoftwareSerial sGPS(RXPin, TXPin);
TinyGPSPlus gps;
double myLL[2];
// nRF24L01(+) radio attached (CE, CSN)
RF24 radio(9,10);
RF24Network network(radio);
// Channel of our node
const uint16_t channel = 60;
// Address of our node
const uint16_t this_node = 1;
// Address of the base
const uint16_t other_node = 0;
// How many packets have we sent already
unsigned long packets_sent;
// Structure of our payload, limited to 32 bytes
struct payload_t // 32 bytes max
{
unsigned long counter; // 4 bytes
double lat; // 4 bytes
double lng; // 4 bytes
};
void getGPS(); // get GPS data
static void smartDelay(unsigned long); // ensures that the gps object is being "fed".
void sendPayload(); // check if time to send payload
void setup(void)
{
sGPS.begin(GPSBaud);
Serial.begin(115200);
SPI.begin();
radio.begin();
network.begin(channel, this_node);
radio.powerDown();
}
void loop(void){
network.update();
while (sGPS.available() > 0){
if (gps.encode(sGPS.read())){
getGPS();
sendPayload();
smartDelay(2000);
}
}
}
void getGPS(){
if (gps.location.isValid()){
myLL[0] = gps.location.lat();
myLL[1] = gps.location.lng();
Serial.print("lat: ");
Serial.println(myLL[0],7);
Serial.print("lng: ");
Serial.println(myLL[1],7);
}
}
void sendPayload(){
payload_t payload = { packets_sent++, myLL[0], myLL[1]};
RF24NetworkHeader header(other_node);
radio.powerUp();
delay(1);
bool ok = network.write(header,&payload,sizeof(payload));
radio.powerDown();
}
static void smartDelay(unsigned long ms){
unsigned long start = millis();
do
{
while (sGPS.available())
gps.encode(sGPS.read());
} while (millis() - start < ms);
}
//receiver
#include <SoftwareSerial.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// nRF24L01(+) radio attached (CE, CSN)
RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);
// Channel of our node
const uint16_t channel = 60;
// Address of our node
const uint16_t this_node = 0;
// How many packets have we sent already
unsigned long packets_sent;
// Structure of our payload, limited to 32 bytes
struct payload_t // 32 bytes max
{
unsigned long counter; // 4 bytes
double lat; // 4 bytes
double lng; // 4 bytes
};
// packet variables
unsigned long Counter;
double setLL[2];
void getRadioData();
void setup() {
Serial.begin(115200);
SPI.begin();
// Radio setup
radio.begin();
// network.begin(/*channel*/, /*node address*/);
network.begin(channel, this_node);
}
void loop() {
// Pump the radio network regularly
network.update();
// delay(100);
// Is there anything ready for us?
while ( network.available() ){
// If so, grab it and print it out
getRadioData();
}
}
// getRadioData() // get Network data
void getRadioData(){
RF24NetworkHeader header;
payload_t payload;
bool done = false;
while (!done){
done = network.read(header,&payload,sizeof(payload));
Counter = payload.counter;
setLL[0] = payload.lat;
setLL[1] = payload.lng;
Serial.print("Packet #");
Serial.print(Counter);
Serial.print(" Lat: ");
Serial.print(setLL[0],6);
Serial.print(" Lng: ");
Serial.print(setLL[1],6);
}
}