Hi,
I have been messing with a couple of nrf24l01 devices together with Arduino UNO. I am using this setup example here: Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum
We have a 100 uF capacitor on both devices as well.
I am having a lot of issues that I can't solve. Been browsing the internet a few days now and it is driving me crazy.
This is the code i have for the Rx:
// SimpleRx - the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
//const uint64_t thisSlaveAddress = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;
//===========
void setup() {
Serial.begin(9600);
Serial.println("SimpleRx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setPALevel(RF24_PA_MIN);
radio.enableDynamicPayloads();
//radio.setChannel(119);
//radio.setAutoAck(false);
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);
newData = false;
}
}
and for Tx:
// 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'};
//const uint64_t slaveAddress = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char dataToSend[10] = "Message 0";
char txNum = '0';
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second
void setup() {
Serial.begin(9600);
Serial.println("SimpleTx Starting");
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate( RF24_250KBPS );
radio.enableDynamicPayloads();
//radio.setChannel(119);
//radio.setAutoAck(false);
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("Ack correct:" + radio.isAckPayloadAvailable());
updateMessage();
}
else {
Serial.println(" Tx failed");
}
}
//================
void updateMessage() {
// so you can see that new data is being sent
txNum += 1;
if (txNum > '9') {
txNum = '0';
}
dataToSend[8] = txNum;
}
When I run the verification test i get this:
Device 1:
Device 2:
And what I can tell there they look ok, it's not mostly 0x00 or 0xFF.
When I run the Rx script it spams "Data received" but it does not print any content at all.
When I run the Tx script it stops when it tries to write but sometimes it manage to send and says that it got an act but when I try radio.isAckPayloadAvailable() it does not return anything at all.
I have checked that the everything is connected as the tutorial example many times and I have no clue where to go from here..