I am using nRF24L01+ with two Arduino Nanos, one receives analog input and sends the data over to the second Arduino to display on a 20X4 LCD display, but it seems that nothing is being sent on even received as I tried to print the input on the first Arduino on the serial monitor but I got nothing.
is there a problem with my code or the logic used here?
Thanks in advance for the help
Below is my modified codes from HowToMechatronics
Transmitter code
/*
* Arduino Wireless Communication Tutorial
* Example 1 - Receiver Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//Define LSD Inputs
float PosLSD = A0;
float NegLSD = A1;
//Define period Inputs
float PosPer = A6;
float NegPer = A7;
//Define Reg Rod position Input
float RegRod = A2;
struct Data_Package
{
//Setup analog inputs
float PLSD = analogRead(PosLSD);
float NLSD = analogRead(NegLSD);
float PPer = analogRead(PosPer);
float NPer = analogRead(NegPer);
float RRod = analogRead(RegRod);
};
Data_Package data;
//Setup tramitter pins and channel
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001"; //channel
void setup()
{
Serial.begin(9600);
//Setup the transmitter
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
}
//Send the signal
void loop() {
// Send the whole data from the structure to the receiver
radio.write(&data, sizeof(Data_Package));
Serial.print("a: + ");
Serial.print(data.PLSD);
Serial.print(" b: - ");
Serial.print(data.NLSD);
Serial.print(" c: + ");
Serial.print(data.PPer);
Serial.print(" d: - ");
Serial.print(data.NPer);
Serial.print(" e: ");
Serial.print(data.RRod);
delay(2000);
}
Receiver Code
/*
* Arduino Wireless Communication Tutorial
* Example 1 - Receiver Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#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); // Set the LCD I2C address
struct Data_Package
{
float PLSD;
float NLSD;
float PPer;
float NPer;
float RRod;
};
Data_Package data;
//Setup tramitter pins and channel
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001"; //channel
void setup()
{
Serial.begin(9600);
//Setup the transmitter
lcd.begin(20,4);
radio.begin();
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
}
//Send the signal
void loop()
{
// Check whether there is data to be received
if (radio.available())
{
radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure
}
lcd.setCursor(0,0);
lcd.print("PosLSD +");
lcd.setCursor(9,0);
lcd.print(data.PLSD,DEC);
lcd.setCursor(0,1);
lcd.print("NegLSD -");
lcd.setCursor(9,1);
lcd.print(data.NLSD,DEC);
lcd.setCursor(0,2);
lcd.print("PosPer +");
lcd.setCursor(9,2);
lcd.print(data.PPer,DEC);
lcd.setCursor(0,3);
lcd.print("NegPer +");
lcd.setCursor(9,3);
lcd.print(data.NPer,DEC);
Serial.print("a: + ");
Serial.print(data.PLSD);
Serial.print(" b: - ");
Serial.print(data.NLSD);
Serial.print(" c: + ");
Serial.print(data.PPer);
Serial.print(" d: - ");
Serial.print(data.NPer);
Serial.print(" e: ");
Serial.print(data.RRod);
delay(2000);
}