Hello everyone,
I was working before with NRF24L01 without an adapter so i had to connect it to the 3.3V on arduino but now I got adapters which will make things easier and they are connected to 5V instead of 3.3V.
I am trying to send potentiometer value from one arduino nano to an arduino uno but nothing is working. It is giving on the monitor : Throttle: 0
my connections are the following on each arduino:
Pins of NRF24L01:
CE to arduino pin 9
CSN to arduino pin 10
SCK to arduino pin pin 13
M0 to arduino pin 11
M1 to arduino pin 12
and here are my codes :
Controller:
#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() {
int ThrottleValue = analogRead(Throttle); // read the value from the sensor
//Serial.print("Throttle : ");
//Serial.println(ThrottleValue);
radio.openWritingPipe(pipe);
msgTX[0] = ThrottleValue;
//msgTX[1] = SteeringValue;
radio.write(msgTX, sizeof(msgTX)); //Sends the Data
AcknowledgmentDATA();
Serial.println(ThrottleValue);
}
//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];
}
}
Receiver:
#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);
}
}