Hi !!
I´m getting a bit frustrated on the nrf devices..
I´m using an Arduino UNO as Transciver and an 5 to 3.3V adapter for the NRF24 like this:
For reciever i´m using an RF Nano (built in NRF)
I have followed Robin2 example : Simple nRF24L01+ 2.4GHz transceiver demo - #28 by nurulb
I´m running Arduino 1.8.16 and using the 1.1.7 RF24 library.
TX Code:
#include <SPI.h>
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
// UNO
#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
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.setDataRate( RF24_250KBPS );
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
txNum += 1;
if (txNum > '9') {
txNum = '0';
}
dataToSend[8] = txNum;
}
RX Code: `// SimpleRx - the slave or the receiver
#include <nRF24L01.h>
#include <RF24.h>
// RF Nano
#define CE_PIN 10
#define CSN_PIN 9
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
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.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;
}
}
The only thing changed to the code is: // UNO and // Nano to keep track of wich code to wich board, And CE CSN pin to match the board.
When testing the Robin2 : CheckConnection.ino
/ 18 Mar 2018 - simple program to verify connection between Arduino
// and nRF24L01+
// This program does NOT attempt any communication with another nRF24
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#define CE_PIN 10
#define CSN_PIN 9
// UNO CE PIN 9 CSN PIN 10
// NANO CE PIN 10 CSN PIN 9
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;
void setup() {
Serial.begin(9600);
printf_begin();
Serial.println("CheckConnection Starting");
Serial.println();
Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
Serial.println(" Note that RF24 does NOT reset when Arduino resets - only when power is removed");
Serial.println(" If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
Serial.println(" communicating with the nRF24");
Serial.println();
radio.begin();
radio.printDetails();
Serial.println();
Serial.println();
Serial.println("AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1");
Serial.println(" and 250KBPS data rate");
Serial.println();
radio.openReadingPipe(1, thisSlaveAddress);
radio.setDataRate( RF24_250KBPS );
radio.printDetails();
Serial.println();
Serial.println();
}
void loop() {
}
I get the following reply from Serial monitor:
In my eyes that look correct.
But why are the TX and RX code not working ????
In the serial monitor it looks like this:
TX:
RX:
Things i tried so far...
I have tried switching out the NRF24L01 modules // i have 10pcs of them.
I have tried using an regular nano, RFnano and an Nano 33IOT, still gets the check connection program to work.
I tried communicating between the nanos, still no data recieved.
I tried Uninstaling the RF24 1.1.7, reboot computer and installing the latest version 1.4.1 no luck there either.
I removed the power module for the NRF and connected it directly to the 3V uno, no luck.
How is it possible to have connection test ok between arduino and nrf with the connection test but no connection between NRF´s ??
I have tried putting the NRF close togheter and 2m apart, no luck.
Best Regards
Andreas