#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <RH_NRF24.h>
RH_NRF24 nrf24;
#include <RF24.h>
static const int RXPin = 4, TXPin = 3;// Here we make pin 4 as RX of arduino & pin 3 as TX of arduino
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
// Singleton instance of the radio driver
void setup()
{
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo only
ss.begin(GPSBaud);
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
while (ss.available() > 0)
if (gps.encode(ss.read()))
{
Serial.println("Sending to nrf24_server");
// Send a message to nrf24_server
displayInfo();
}
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
nrf24.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (nrf24.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is nrf24_server running?");
}
delay(400);
}
void displayInfo()
{
uint8_t data[] = "Location: ";
nrf24.send(data, sizeof(data));
if (gps.location.isValid())
{/* ############################# error is for below 2 lines of code#######################*/
float lati= gps.location.lat();
nrf24.send(lati);
/*################### help me solve this to send gps location through nrf#####################*/
}
else
{
uint8_t data1[] = "invalid";
nrf24.send(data1, sizeof(data1));
[color=#500050] }}
[/color]
error:
[color=#500050]Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
[/color]C:\Users\Documents\Arduino\try1_tx\try1_tx.ino: In function 'void displayInfo()':
try1_tx:91:23: error: no matching function for call to 'RH_NRF24::send(float&)'
nrf24.send(lati);
^
In file included from C:\Users\sabar\Documents\Arduino\try1_tx\try1_tx.ino:14:0:
C:\Users\Documents\Arduino\libraries\RadioHead-master/RH_NRF24.h:561:10: note: candidate: virtual bool RH_NRF24::send(const uint8_t*, uint8_t)[color=#500050]
bool send(const uint8_t* data, uint8_t len);
^~~~
RadioHead-master/RH_NRF24.h:561:10: note: candidate expects 2 arguments, 1 provided
[/color]exit status 1[color=#500050]
no matching function for call to 'RH_NRF24::send(float&)'[/color]
Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.
The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work
There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to. If the first example does not work be sure to try the connection test for both of your Arduinos. Nothing will work if the connection test fails.
A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.
If you are using the high-power nRF24s (with the external antenna) it may help to have a distance of about 3 metres between the two nRF24s so that the signal does not overwhelm the receiver. However someone on the Forum has had them working without that separation - I don't have any personal experience with them. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.
now got results on interfacing programming GPS and nrf separately
i made sure that GPS and nrf modules separately work well
=>got coordinates through GPS successfully
=> transmitted and received sample message (string) through
but again when interfacing them together and transmitting GPS value(float) i am getting same problem
i.e I am unable to send float value through nrf
this is tx part
GPS latitude is not getting transmitted
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;// Here we make pin 4 as RX of arduino & pin 3 as TX of arduino
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
#include <SPI.h>
#include <RH_NRF24.h>
#include <RF24.h>
// Singleton instance of the radio driver
RH_NRF24 nrf24;
void setup()
{
ss.begin(GPSBaud);
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo onl
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
while (ss.available() > 0)
if (gps.encode(ss.read()))
{
Serial.println("Sending to nrf24_server");
// Send a message to nrf24_server
displayInfo();
}
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
nrf24.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (nrf24.recv(buf, &len))
{
Serial.print("got reply: ");
Serial.println((char*)buf);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is nrf24_server running?");
}
delay(400);
}
void displayInfo()
{
if (gps.location.isValid())
{
uint8_t lat= gps.location.lat();
nrf24.send(lat,sizeof(lat));
}
else
{
uint8_t data1[] = "invalid";
nrf24.send(data1, sizeof(data1));
}
}
below is rx part
this is working fine
#include <RadioHead.h>
#include <SPI.h>
#include <RH_NRF24.h>
RH_NRF24 nrf24;
void setup()
{
Serial.begin(9600);
while (!Serial)
; // wait for serial port to connect. Needed for Leonardo only
if (!nrf24.init())
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
if (!nrf24.setChannel(1))
Serial.println("setChannel failed");
if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
Serial.println("setRF failed");
}
void loop()
{
if (nrf24.available())
{
// Should be a message for us now
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.recv(buf, &len))
{
Serial.print("receiving latitude...");
Serial.println((char*)buf);
// Send a reply
uint8_t data[] = "v2 received lat successfully";
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
Serial.println("notified to v1");
}
else
{
Serial.println("recv failed");
}
}
}