I am trying to use nrf24l01+pa+lna with Mega2560 and UNO to achieve wireless outgoing.
And I use a buck board to be the power supply to nrf24l01+pa+lna(Just TX).
Uno is transmitter
Mega2560 is receiver
And this is my code:
//Transmitter
#include <SPI.h>
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
RF24 rf24(7, 8);
const uint8_t addr[6]= {'R','x','A','A','A'};
void setup() {
Serial.begin(9600);
rf24.begin();
rf24.setPayloadSize(5);
rf24.setChannel(80);
rf24.openWritingPipe(addr);
rf24.setPALevel(RF24_PA_LOW);
rf24.setDataRate(RF24_250KBPS);
rf24.setRetries(3,5);
rf24.stopListening();
}
void loop() {
char data[5]="RF24";
rf24.write(&data, sizeof(data));
delay(500);
}
//receiver
#include <SPI.h>
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
RF24 rf24(7, 8);
const byte addr[6]= {'R','x','A','A','A'};
void setup() {
Serial.begin(9600);
printf_begin();
rf24.begin();
rf24.setPayloadSize(5);
rf24.setChannel(80);
rf24.openReadingPipe(0, addr);
rf24.setPALevel(RF24_PA_LOW);
rf24.setDataRate(RF24_250KBPS);
rf24.startListening();
rf24.printDetails();
}
void loop() {
if (rf24.available()) {
char data[5]="";
rf24.read(&data, sizeof(data));
Serial.println(data);
}
else{
Serial.println("NO connect");
}
delay(500);
}
Problem
But my serial keep print nothing.... like:
11:13:40.645 ->
11:13:40.645 ->
11:13:45.146 ->
same thing below...
Even when I plug out Uno's power it still print like:
11:13:40.645 ->
11:13:40.645 ->
11:13:45.146 ->
same thing below.....
You've not indicated that you've tried any other sketches. Your best chances of getting your particular code to work, is to start with the tutorials that are provided here:
Introduction
The nRF24L01+ 2.4GHz transceiver modules are cheap and very effective but I have come across a few Threads in which people were having trouble with them so I thought it might be useful to gather together in one place a basic step-by-step sequence for getting them to work.
EDIT 03 Feb 2021 - For this Tutorial install Version 1.1.7 of the RF24 library (available with the Arduino Library Manager). More information in Reply #30.
Edit 29 Aug 2016. I have today downloaded and successfu…
Read the first post and the jump to post #30 to run the connection check sketch on your UNO.
You should also run the same sketch on your 2560, but using the appropriate SPI pins. Away from my bench so I don't have the pins to hand.
Post the serial output from the tests here so we can confirm that the modules are wired correctly.
1 Like
I upload the connection check sketch:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#define CE_PIN 7
#define CSN_PIN 8
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() {
}
And it print:
Mega2560:
// Mega2560
14:58:30.855 -> STATUS = 0x02 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=0
14:58:30.921 -> RX_ADDR_P0-1 = 0x0202020202 0x0202020202
14:58:30.954 -> RX_ADDR_P2-5 = 0x02 0x02 0x02 0x02
14:58:30.986 -> TX_ADDR = 0x0202020202
14:58:31.019 -> RX_PW_P0-6 = 0x02 0x02 0x02 0x02 0x02 0x02
14:58:31.052 -> EN_AA = 0x02
14:58:31.085 -> EN_RXADDR = 0x02
14:58:31.085 -> RF_CH = 0x02
14:58:31.117 -> RF_SETUP = 0x02
14:58:31.117 -> CONFIG = 0x02
14:58:31.150 -> DYNPD/FEATURE = 0x02 0x02
14:58:31.260 -> Data Rate = 1 MBPS
14:58:31.260 -> Model = nRF24L01+
14:58:31.316 -> CRC Length = 8 bits
14:58:31.320 -> PA Power = PA_LOW
14:58:31.320 -> ARC = 2
14:58:31.325 ->14:58:31.325 ->
14:58:31.325 -> AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
14:58:31.361 -> and 250KBPS data rate
14:58:31.366 ->
14:58:31.366 -> SPI Speedz = 10 Mhz
14:58:31.381 -> STATUS = 0x02 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=0
14:58:31.445 -> RX_ADDR_P0-1 = 0x0202020202 0x0202020202
14:58:31.478 -> RX_ADDR_P2-5 = 0x02 0x02 0x02 0x02
14:58:31.511 -> TX_ADDR = 0x0202020202
14:58:31.543 -> RX_PW_P0-6 = 0x02 0x02 0x02 0x02 0x02 0x02
14:58:31.577 -> EN_AA = 0x02
14:58:31.609 -> EN_RXADDR = 0x02
14:58:31.642 -> RF_CH = 0x02
14:58:31.642 -> RF_SETUP = 0x02
14:58:31.674 -> CONFIG = 0x02
14:58:31.674 -> DYNPD/FEATURE = 0x02 0x02
14:58:31.707 -> Data Rate = 1 MBPS
14:58:31.741 -> Model = nRF24L01+
14:58:31.741 -> CRC Length = 8 bits
14:58:31.773 -> PA Power = PA_LOW
14:58:31.773 -> ARC = 2
Uno :
15:36:36.262 -> CheckConnection Starting
15:36:37.861 ->
15:36:37.861 -> FIRST WITH THE DEFAULT ADDRESSES after power on
15:36:37.945 -> Note that RF24 does NOT reset when Arduino resets - only when power is removed
15:36:38.010 -> If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
15:36:38.109 -> communicating with the nRF24
15:36:38.143 ->
15:36:38.143 -> SPI Speedz = 10 Mhz
15:36:38.176 -> STATUS = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
15:36:38.242 -> RX_ADDR_P0-1 = 0x20206060e0 0x00000000c0
15:36:38.276 -> RX_ADDR_P2-5 = 0xe0 0xc0 0xc0 0x80
15:36:38.310 -> TX_ADDR = 0x0000000000
15:36:38.343 -> RX_PW_P0-6 = 0x10 0x00 0x00 0x70 0x00 0x70
15:36:38.399 -> EN_AA = 0xc0
15:36:38.415 -> EN_RXADDR = 0x80
15:36:38.415 -> RF_CH = 0x80
15:36:38.443 -> RF_SETUP = 0x00
15:36:38.443 -> CONFIG = 0x80
15:36:38.477 -> DYNPD/FEATURE = 0x00 0x00
15:36:38.477 -> Data Rate = 1 MBPS
15:36:38.510 -> Model = nRF24L01+
15:36:38.543 -> CRC Length = 8 bits
15:36:38.543 -> PA Power = PA_MIN
15:36:38.577 -> ARC = 0
15:36:38.577 ->
15:36:38.577 ->
15:36:38.577 -> AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
15:36:38.644 -> and 250KBPS data rate
15:36:38.677 ->
15:36:38.677 -> SPI Speedz = 10 Mhz
15:36:38.710 -> STATUS = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
15:36:38.744 -> RX_ADDR_P0-1 = 0x20202020e0 0x00000000c0
15:36:38.811 -> RX_ADDR_P2-5 = 0xe0 0xc0 0xc0 0x80
15:36:38.844 -> TX_ADDR = 0x0000000070
15:36:38.878 -> RX_PW_P0-6 = 0x10 0x00 0x00 0x70 0x00 0x70
15:36:38.911 -> EN_AA = 0xc0
15:36:38.944 -> EN_RXADDR = 0xc0
15:36:38.944 -> RF_CH = 0x80
15:36:38.978 -> RF_SETUP = 0x00
15:36:38.978 -> CONFIG = 0xe0
15:36:39.011 -> DYNPD/FEATURE = 0x00 0x00
15:36:39.011 -> Data Rate = 1 MBPS
15:36:39.044 -> Model = nRF24L01+
15:36:39.087 -> CRC Length = 8 bits
15:36:39.087 -> PA Power = PA_MIN
15:36:39.087 -> ARC = 0
15:36:39.087 ->
Here are the question, why data rate changed to 1 MBPS, I set it at 250KBPS?
system
Closed
January 8, 2023, 7:44am
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.