Hello
First, sorry for my poor English cuz I'm Iranian
A few days ago I was working on a nrf24 Arduino 10 channel Radio control. Actually the problem that my NRF24 Module's weren't working and I thought the problem is from NRF24 Module's So I changed that nRF24 Module for 4 times and everytime my project failed.( Of course one time worked really nice for just 2 days )
Then I stopped that damn project
Today I saw a test code in YouTube that show's me how to test NRF24 Module's Working or no ( without 2 nrf24 for receiving and Transmitter )
"https://youtu.be/yVif9ks9Wqw?si=mgCTIxM1uoZpXmcb"
I tested nrf24 Module's that I bought when I thought they all not working . First I saw 4 number of them ( I have 5 nrf24 ), are working
It was really interesting and I tested with my other Arduino Nano and I saw they all not working with that, so I understood the problem from Arduino
Actually my Arduino is working fully in everything like blink or servo testing .
I just wanted to be sure should I buy a new Arduino or I can fix it ?
Of course I'm using nrf24 adapter that using AMS1117 3.3 regular and I'm using Arduino 5v output
Also the output voltage of 3.3 pin is 3.34 and 5 is 5.04 .
Again sorry for poor English. Thank you so much
We need to see your programs for transmitting and receiving
and wiring diagrams for both showing how each are connected to their respective Nano and how they are powered.
Almost all the necessary information is available here, also to power the transmitter I used its VIN pin and connected a 9V adapter. The receiver is also powered by a 7.4 volt battery On VIN Pin. Also, all modules use the 3.3 V AMS 1117 regulator
Welcome! You'll find many helpers here will not download external content, for varying reasons.
Surely, inserting one or two schematics and two code blocks in a follow-on post shouldn't be too much to ask?
Yes you right, I'm sorry for this. Thank you in advance. This is the schematic photo of the transmitter and the receiver, which I used VIN Pin instead of using the 5V input in the receiver.
And also this is the code that I test my NRF24s
/*
If your serial output has these values same then Your nrf24l01 module is in working condition :
EN_AA = 0x3f
EN_RXADDR = 0x02
RF_CH = 0x4c
RF_SETUP = 0x03
CONFIG = 0x0f
This code is under public domain
Last updated on 21/08/28
https://dhirajkushwaha.com/elekkrypt
*/
#include <SPI.h>
#include <RF24.h>
#include <printf.h>
RF24 radio(8, 9);
byte addresses[][6] = {"1Node", "2Node"};
void setup() {
radio.begin();
radio.setPALevel(RF24_PA_LOW);
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
radio.startListening();
Serial.begin(9600);
printf_begin();
radio.printDetails();
}
void loop() {
// empty
}
This is the code of receiver :
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define SIGNAL_TIMEOUT 500 // This is signal timeout in milli seconds. We will reset the data if no signal
const uint64_t pipeIn = 0xF9E8F0F0E1LL;
RF24 radio(8, 9);
unsigned long lastRecvTime = 0;
struct PacketData
{
byte lxAxisValue;
byte lyAxisValue;
byte rxAxisValue;
byte ryAxisValue;
byte lPotValue;
byte rPotValue;
byte switch1Value;
byte switch2Value;
byte switch3Value;
byte switch4Value;
};
PacketData receiverData;
Servo servo1; //Pin D2
Servo servo2; //Pin D3
Servo servo3; //Pin D4
Servo servo4; //Pin D5
Servo servo5; //Pin D6
Servo servo6; //Pin D7
int led1 = A0;
int led2 = A1;
int led3 = A2;
int led4 = A3;
//Assign default input received values
void setInputDefaultValues()
{
// The middle position for joystick. (254/2=127)
receiverData.lxAxisValue = 127;
receiverData.lyAxisValue = 127;
receiverData.rxAxisValue = 127;
receiverData.ryAxisValue = 127;
receiverData.lPotValue = 0;
receiverData.rPotValue = 0;
receiverData.switch1Value = LOW;
receiverData.switch2Value = LOW;
receiverData.switch3Value = LOW;
receiverData.switch4Value = LOW;
}
void mapAndWriteValues()
{
servo1.write(map(receiverData.lxAxisValue, 0, 254, 0, 180));
servo2.write(map(receiverData.lyAxisValue, 0, 254, 0, 180));
servo3.write(map(receiverData.rxAxisValue, 0, 254, 0, 180));
servo4.write(map(receiverData.ryAxisValue, 0, 254, 0, 180));
servo5.write(map(receiverData.lPotValue, 0, 254, 0, 180));
servo6.write(map(receiverData.rPotValue, 0, 254, 0, 180));
digitalWrite(led1, receiverData.switch1Value);
digitalWrite(led2, receiverData.switch2Value);
digitalWrite(led3, receiverData.switch3Value);
digitalWrite(led4, receiverData.switch4Value);
}
void setup()
{
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1,pipeIn);
radio.startListening(); //start the radio receiver
servo1.attach(2);
servo2.attach(3);
servo3.attach(4);
servo4.attach(5);
servo5.attach(6);
servo6.attach(7);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
setInputDefaultValues();
mapAndWriteValues();
}
void loop()
{
// Check if RF is connected and packet is available
if(radio.isChipConnected() && radio.available())
{
radio.read(&receiverData, sizeof(PacketData));
lastRecvTime = millis();
}
else
{
//Check Signal lost.
unsigned long now = millis();
if ( now - lastRecvTime > SIGNAL_TIMEOUT )
{
setInputDefaultValues();
}
}
mapAndWriteValues();
}
And for the transmitter:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeOut = 0xF9E8F0F0E1LL; //IMPORTANT: The same as in the receiver 0xF9E8F0F0E1LL
RF24 radio(8, 9); // select CE,CSN pin
struct PacketData
{
byte lxAxisValue;
byte lyAxisValue;
byte rxAxisValue;
byte ryAxisValue;
byte lPotValue;
byte rPotValue;
byte switch1Value;
byte switch2Value;
byte switch3Value;
byte switch4Value;
};
PacketData data;
void setup()
{
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipeOut);
radio.stopListening(); //start the radio Transmitter
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(4,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
}
//This function is used to map 0-1023 joystick value to 0-254. hence 127 is the center value which we send.
//It also adjust the deadband in joystick.
//Jotstick values range from 0-1023. But its center value is not always 511. It is little different.
//So we need to add some deadband to center value. in our case 500-530. Any value in this deadband range is mapped to center 127.
int mapAndAdjustJoystickDeadBandValues(int value, bool reverse)
{
if (value >= 530)
{
value = map(value, 530, 1023, 127, 254);
}
else if (value <= 500)
{
value = map(value, 500, 0, 127, 0);
}
else
{
value = 127;
}
if (reverse)
{
value = 254 - value;
}
return value;
}
void loop()
{
data.lxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(A0), false);
data.lyAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(A1), false);
data.rxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(A2), false);
data.ryAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(A3), false);
data.lPotValue = map(analogRead(A4), 0, 1023, 0, 254);
data.rPotValue = map(analogRead(A5), 0, 1023, 0, 254);
data.switch1Value = !digitalRead(2);
data.switch2Value = !digitalRead(3);
data.switch3Value = !digitalRead(4);
data.switch4Value = !digitalRead(5);
radio.write(&data, sizeof(PacketData));
}