I've changed up the code a little and added a part to print the values stored in the array MY_DATA.
I'm getting values out in the serial monitor on the transmitter, but still nothing is coming up on the receiver screen.
I also removed the GPSDATA array, it seemed redundant.
Any idea why the reciever is still only showing "No Radio Available"
The updated Transmitter Program:
/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Wire.h>
SoftwareSerial mySerial(6, 7); // RX, TX
//Attach 20x4 LCD to Analog 4,5 "SDA,SCL"
TinyGPS gps;
void gpsdump(TinyGPS &gps);
float printFloat(double f, int digits = 2);
float mph;
float alt;
long lat, lon;
float flat, flon;
unsigned long age, date, time, chars;
byte month, day, hour, minute, second, hundredths;
int level;
int year;
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int MY_DATA[4];
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
mySerial.begin(9600);
radio.begin();
radio.setPayloadSize(sizeof(MY_DATA));
radio.openWritingPipe(pipe);
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
bool newdata = false;
unsigned long start = millis();
// Every 5 seconds we print an update
while (millis() - start < 5000) {
if (mySerial.available()) {
char c = mySerial.read();
//Serial.print(c); // uncomment to see raw GPS data
if (gps.encode(c)) {
newdata = true;
break; // uncomment to print new data immediately!
}
}
}
if (newdata) {
Serial.println("Acquired Data");
Serial.println("-------------");
gpsdump(gps);
Serial.println("-------------");
Serial.println();
}
MY_DATA[0] = mph;
MY_DATA[1] = alt;
MY_DATA[2] = flon;
MY_DATA[3] = flat;
Serial.println(mph);
Serial.println(alt);
Serial.println(flon);
Serial.println(flat);
radio.write(MY_DATA, sizeof(MY_DATA));
}//--(end main loop )---
void gpsdump(TinyGPS &gps)
{
//long lat, lon;
//float flat, flon;
//unsigned long age, date, time, chars;
//int year;
//byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;
gps.get_position(&lat, &lon, &age);
Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
// On Arduino, GPS characters may be lost during lengthy Serial.print()
// On Teensy, Serial prints to USB, which has large output buffering and
// runs very fast, so it's not necessary to worry about missing 4800
// baud GPS characters.
gps.f_get_position(&flat, &flon, &age);
Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
gps.get_datetime(&date, &time, &age);
Serial.print("Date(ddmmyy): "); Serial.print(date); Serial.print(" Time(hhmmsscc): ");
Serial.print(time);
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/");
Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(static_cast<int>(hour)); Serial.print(":");
Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second));
Serial.print("."); Serial.print(static_cast<int>(hundredths));
Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): ");
Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
Serial.print("Alt(float): "); printFloat(gps.f_altitude()); Serial.print(" Course(float): ");
printFloat(gps.f_course()); Serial.println();
Serial.print("Speed(knots): "); printFloat(gps.f_speed_knots()); Serial.print(" (mph): ");
printFloat(gps.f_speed_mph());
Serial.print(" (mps): "); printFloat(gps.f_speed_mps()); Serial.print(" (kmph): ");
printFloat(gps.f_speed_kmph()); Serial.println();
mph=printFloat(gps.f_speed_mph());
alt=printFloat(gps.f_altitude());
gps.stats(&chars, &sentences, &failed);
Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: ");
Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
}
float printFloat(double number, int digits)
{
// Handle negative numbers
if (number < 0.0) {
Serial.print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
Serial.print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
Serial.print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0) {
remainder *= 10.0;
int toPrint = int(remainder);
Serial.print(toPrint);
remainder -= toPrint;
}
}
The Receiver Program:
/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int MY_DATA[4];
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
lcd.begin(20, 4); // start the library
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.setPayloadSize(sizeof(MY_DATA));
radio.openReadingPipe(1,pipe);
radio.startListening();;
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
if ( radio.available() )
{
// Read the data payload until we've received everything
bool done = false;
while (!done)
{
// Fetch the data payload
done = radio.read( MY_DATA, sizeof(MY_DATA) );
lcd.setCursor(11,2);
lcd.print("Speed");
lcd.setCursor(12,3);
lcd.print(MY_DATA[0]);
lcd.setCursor(17,3);
lcd.print("MPH");
lcd.setCursor(0,2);
lcd.print("Altitude");
lcd.setCursor(2,3);
lcd.print(MY_DATA[1],4);
lcd.setCursor(9,3);
lcd.print("m");
lcd.setCursor(0,0);
lcd.print("Long ");
lcd.print(MY_DATA[2],6);
lcd.setCursor(0,1);
lcd.print("Lat ");
lcd.setCursor(6,1);
lcd.print(MY_DATA[3],6);
}
}
else
{
lcd.println("No radio available");
}
}//--(end main loop )---