Hello,
I am trying to send a value of 12 from one arduino to the other using the nRF24L01 long range with the big antenna. So I made my connections and uploaded my sketches. At first i did not receive anything on the receiver side, so I rechecked my connection and here it was a wrong connected pin so I corrected it and I started getting value on my monitor on the receiver side. My problem is that I keep getting 0 and not 12 ! So I need your help please figuring out the problem ?
here is my transmitter sketch:
#include <SPI.h>
#include <RF24.h>
//1st byte is for throttle value from pot
int msgTX[2]; //Message to be transmitted, can contain up to 2 array elements, 2 bytes
int ackMessage[2]; //Acknowledgment message, means the message that will be received from the receiver or the car, 1 element for the moment
//Defining radio object for the RF24 function
RF24 radio(9, 10); // CE, CSN
//const byte address[6] = "00001";
//Defining the radio variables and values
const uint64_t pipe = 0xE8E8F0F0E1LL; //pipe address
const rf24_datarate_e dataRate = RF24_250KBPS; //Data rate defined in the documentations, RF24_250KBPS, RF24_1MBPS or RF24_2MBPS
//Throttle potentiometers
//const byte Throttle = A5;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(dataRate);
//radio.openWritingPipe(address);
radio.enableAckPayload(); //enables receiving data from receiver side
//radio.setPALevel(RF24_PA_MIN); //Power Amplifier (PA) level to one of four levels RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
//radio.stopListening();
}
void loop() {
radio.openWritingPipe(pipe);
msgTX[0] = 12;
radio.write(msgTX, sizeof(msgTX)); //Sends the Data
AcknowledgmentDATA();
}
//DATA Receiving from the Receiver part, Acknowledgment Data
void AcknowledgmentDATA(){
while ( radio.isAckPayloadAvailable() ){
//Serial.println("Ack Available");
radio.read(ackMessage, sizeof(ackMessage));
int value = ackMessage[1];
}
}
and here is my receiver sketch:
#include <SPI.h>
//#include <nRF24L01.h>
#include <RF24.h>
int msgRX[2]; //Message to be transmitted, can contain up to 2 array elements, 2 bytes
int ackMessage[2]; //Acknowledgment message, means the message that will be received from the receiver or the car, 1 element for the moment
RF24 radio(9, 10); // CE, CSN
//const byte address[6] = "00001";
//Defining the radio variables and values
const uint64_t pipe = 0xE8E8F0F0E1LL; //pipe address
const rf24_datarate_e dataRate = RF24_250KBPS; //Data rate defined in the documentations, RF24_250KBPS, RF24_1MBPS or RF24_2MBPS
int Throttle;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS);
//radio.openReadingPipe(0, address);
radio.openReadingPipe(1, pipe);
//radio.setPALevel(RF24_PA_MAX);//Power Amplifier (PA) level to one of four levels RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
radio.enableAckPayload();
radio.startListening();
}
void loop() {
//ackMessage[1] = 200;
//radio.writeAckPayload(1, ackMessage, sizeof(ackMessage));
if (radio.available()) {
radio.read(msgRX, sizeof(msgRX));
Throttle = msgRX[0]; //middle throttle value is 121
Serial.print("Throttle: ");
Serial.println(Throttle);
}
}