Hi All,
I have been playing around with the RF24L01 modules to make a radio controlled robot.
I have been able to send and receive data signals backwards and forwards using ints and everything is working well.
I then decided it would be useful to send GPS Lat and Long, time and date info from the robot to the controller. Time and date data was easy but as the lat/long contains data to 6 decimal places. I am having brain ache trying to work out how to do this!
I understand that Arduino is not great at sending decimal places but was wondering if there is a work around by sending the lat as a character array or even multiplying by 100000 sending it and dividing at the receiver end by 100000 but am not having much luck.
I am relatively new to chars, ints, long, strings etc, it is a minefield to me!
Please go easy on me I am 62 yo and sometimes reading detailed info just looks like gobbledegook.
Below is the code I have for the transmitter. This successfully extracts the Lat data and prints it out on the monitor. It's the format for radio.write that is proving to be a problem.
[code]
/*
* Sketch to read the lat value from
* GPS unit and Tx via RF20L01 to Rx board
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
//char Lat;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop() {
delay(5);
radio.stopListening();
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
String Lat = String {gps.location.lat(),6} ;
Serial.print ( " Lat = " );
Serial.println (Lat);
radio.write(&Lat, sizeof(Lat));
}
}
}
[/code]