I'm trying to get two test sketches to work for the Nrf24l01 PA module with an arduino nano, but for some reason it will not work:
/* Tranmsitter code for the Arduino Radio control with PWM output
* Install the NRF24 library to your IDE
* Upload this code to the Arduino UNO, NANO, Pro mini (5V,16MHz)
* Connect a NRF24 module to it:
Module // Arduino UNO,NANO
GND -> GND
Vcc -> 3.3V
CE -> D9
CSN -> D10
CLK -> D13
MOSI -> D11
MISO -> D12
This code transmits 1 channels with data from pins A0 POTENTIOMETER
Please, like share and subscribe : https://www.youtube.com/c/ELECTRONOOBS
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t my_radio_pipe = 0xE8E8F0F0E1LL; //Remember that this code should be the same for the receiver
RF24 radio(9, 10);
// The sizeof this struct should not exceed 32 bytes
struct Data_to_be_sent {
byte ch1;
};
Data_to_be_sent sent_data;
void setup()
{
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(my_radio_pipe);
sent_data.ch1 = 127;
Serial.begin(9600);
}
/**************************************************/
void loop()
{
/*If your channel is reversed, just swap 0 to 255 by 255 to 0 below
EXAMPLE:
Normal: data.ch1 = map( analogRead(A0), 0, 1024, 0, 255);
Reversed: data.ch1 = map( analogRead(A0), 0, 1024, 255, 0); */
sent_data.ch1 = map( analogRead(A0), 0, 1024, 0, 255);
radio.write(&sent_data, sizeof(Data_to_be_sent));
Serial.println("potentiometer: ");
Serial.print(sent_data.ch1);
}
/* Receiver code for the Arduino Radio control with PWM output
* Install the NRF24 library to your IDE
* Upload this code to the Arduino UNO, NANO, Pro mini (5V,16MHz)
* Connect a NRF24 module to it:
Module // Arduino UNO,NANO
GND -> GND
Vcc -> 3.3V
CE -> D9
CSN -> D10
CLK -> D13
MOSI -> D11
MISO -> D12
This code receive 1 channels and prints the value on the serial monitor
Please, like share and subscribe : https://www.youtube.com/c/ELECTRONOOBS
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeIn = 0xE8E8F0F0E1LL; //Remember that this code is the same as in the transmitter
RF24 radio(9, 10); //CSN and CE pins
// The sizeof this struct should not exceed 32 bytes
struct Received_data {
byte ch1;
};
int ch1_value = 0;
Received_data received_data;
/**************************************************/
void setup()
{
Serial.begin(9600);
//We reset the received values
received_data.ch1 = 127;
//Once again, begin and radio configuration
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipeIn);
//We start the radio comunication
radio.startListening();
}
/**************************************************/
unsigned long last_Time = 0;
//We create the function that will read the data each certain time
void receive_the_data()
{
while ( radio.available() ) {
radio.read(&received_data, sizeof(Received_data));
last_Time = millis(); //Here we receive the data
}
}
/**************************************************/
void loop()
{
//Receive the radio data
receive_the_data();
ch1_value = map(received_data.ch1,0,255,1000,2000);
Serial.println(ch1_value);
}//Loop end
this is what i get in the serial monitor of the transmitter:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
158potentiometer:
and this in the receiver:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

