I have searched literally everywhere for a guide, video, or post about how to learn the NRF24L01 library commands.I really want to learn how to use it but i can't since there is no where i can learn the commands.Any help or advice?
Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.
The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work
There is also a connection test program to check that the Arduino can talk to the nRF24 it is connected to.
Ive tried your tutorial multiple times before and after this post, all i get on the rx is "data received" being printed really fast, i checked then checkconnection.ino file you made but it is showing mostly 0s, please i really need help to make this work
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 8
#define CSN_PIN 9
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;
}
OUTPUT:
SimpleTx Starting
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
...
rx CODE
// SimpleRx - the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 8
#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;
}
}
output:
SimpleRx Starting
Data received Message 0
Data received Message 0
Data received Message 0
Data received Message 0
// 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 9
#define CSN_PIN 10
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() {
}
Output:
FIRST WITH THE DEFAULT ADDRESSES after power on
Note that RF24 does NOT reset when Arduino resets - only when power is removed
If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
communicating with the nRF24
The fact that the Data Rate has not changed to 250kbps means that your Arduino is not communicating with its nRF24.
The most likely reason is because the wires are not connected correctly.
Next most likely reason is a bad connection on one of the wires.
And there is also the possibility that the nRF24 is faulty.
Make a simple pencil (or pen) drawing showing in detail how YOU have everything connected and post a photo of the drawing. Please do NOT post a photo of your hardware - it won't tell us anything.
I have just realised you have not told us what Arduino your have. I have been assuming it is an Uno.
and yes i am using an uno but i also use it on a nano aswell, but its not working on that either, and btw thank you for helping me so far, ive honestly been scratching my head 1 month straight on how to get the nrf24l01 working
That does not look like a pencil drawing to me and I can't read the pin labels. Also it seems it is not even correct. Please just draw a diagram as requested, and make sure it is correct before posting.
Help us to help you.
Does your wiring match the diagram in my Tutorial?