Hello guys,
i've a problem with the nRF24L01 modules. In this project i'm currently using two Arduino (nano and Uno). Each one is connected to the nrf24l01 adapter powered by the 5v on the Arduino. I followed the circuit from this link Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum. I just added a servo module on the receiver and a joystick on the transmitter.
The problem is the following : the servo works for about 10 secs but later it doesn't move anymore(i see that on the receiver code, radio.avaiable() return always false).
I noticed that removing the servo.write(), all works properly without stopping.
I'm struggling so much in these days, so thank you to anyone who could help with this.
The nrf24l01 adapter
RX code:
// SimpleRx - the slave or the receiver
#include <Servo.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define pinServo 3
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
Servo servo ;
int dataReceived ;[color=#dcddde][/color]
bool newData = false;
//===========
void setup() {
Serial.begin(9600);
Serial.println("SimpleRx Starting");
servo.attach(pinServo) ;
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
}
//=============
void loop() {
getData();
showData();
}
//==============
void getData() {
if ( radio.available() ) {
radio.read( &dataReceived, sizeof(dataReceived) );
newData = true;
}
}
void showData() {
if (newData == true) {
Serial.print("Data received ");
Serial.println(dataReceived);
servo.write(dataReceived) ;
delay(5) ;
newData = false;
}
}
TX code:
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte slaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
int dataToSend ;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 100; // send once per second
void setup() {
Serial.begin(9600);
Serial.println("SimpleTx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setPALevel(RF24_PA_HIGH) ;
radio.setRetries(3,5); // delay, count
radio.openWritingPipe(slaveAddress);
}
//====================
void loop() {
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
prevMillis = millis();
}
}
//====================
void send() {
bool rslt;
rslt = radio.write( &dataToSend, sizeof(dataToSend) );
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
Serial.print("Data Sent ");
Serial.print(dataToSend);
if (rslt) {
Serial.println(" Acknowledge received");
updateMessage();
}
else {
Serial.println(" Tx failed");
}
}
//================
void updateMessage() {
// so you can see that new data is being sent
[color=#dcddde][/color]
dataToSend = analogRead(A0) ;
dataToSend = map(dataToSend , 0 , 1023 , 0, 180) ;
delay(10) ;
}
I'm using the following library: GitHub - nRF24/RF24: OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices
