I have recently tried to communiacte between an arduino UNO and a Rock 4C+ using two NRF24L01 modules. When turning AutoAck off, the Arduino returns true after sening a message. Though, it doesn’t return true if AutoAck is on and the Rock 4C+ never returns true from the available() function.
The Arduino UNO is transmitting and have the following settings:
- PALevel: LOW
- Channel: 76
- Adress: 0x65646f4e31
- AutoAck: Disabled
- DataRate: 1MBPS
The Rock 4C+ is receiving and have the following settings:
- PALevel: LOW
- Channel: 76
- Adress: 0x65646f4e31
- AutoAck: Disabled
- DataRate: 1MBPS
Since all theese settings are the same, and the begin() function on both sides returns true, it should be working, but it doesn’t.
The fact tht the begin() fucntion returns true on both sides, should indicate that there is no hardware problem. Though, there might be an issue with the CE-pin, since the begin() function seems to return true, even if that one is not even plugged in; this is not the case for MISO, MOSI and CLK. Another thing that seems wierd, is that the documentation says that you should input the number for the CSN-pin when you define an instance of the RF24 class on the Rock 4C+. Though, in reality it’s not the pin number, but rather a integer which it later is used to find the right SPI-port, which for me is “/dev/spidev1.0”.
This is my code on the Arduino UNO side:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
// Define CE and CSN pins for NRF24
#define CE_PIN 9
#define CSN_PIN 10
// Initialize the RF24 radio object
RF24 radio(CE_PIN, CSN_PIN);
// Define the address; must match the receiver on the Rock 4C+
// const byte address[6] = b"1Node"; // Address (5 bytes) must match receiver’s address
void setup() {
// Begin Serial Communication
Serial.begin(9600);
while (!Serial) {
// Wait for serial connection if USB is used
}
// Initialize the radio
if (!radio.begin()) {
Serial.print("Radio hardware not responding");
while(1);
}
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_1MBPS);
radio.setChannel(76);
radio.setAutoAck(false);
radio.openWritingPipe(0x65646f4e31);
radio.setAutoAck(false);
radio.stopListening(); // Ensure the radio is in TX mode
Serial.println("Transmitter ready...");
}
void loop() {
// Define the message to send
const char text[] = "Hello from Arduino!";
// Send the message
if (radio.write(&text, sizeof(text))) {
Serial.println("Message sent successfully.");
} else {
Serial.println("Message failed to send.");
}
// Wait 1 second before sending the next message
delay(1000);
}
This is my code on the Rock 4C+ side:
import time
from pyrf24 import RF24
import pyrf24
CE_PIN = 16 # The actual pin number for the physical pin
RF24.RF24_DRIVER = ‘SPIDEV’
radio = RF24(CE_PIN, 10) # 10 get converted to /dev/spidev1.0
if radio.begin():
print(“Success”)
else:
print(“Failed”)
exit()
radio.setChannel(76)
radio.setPALevel(1) # PALevel LOW
radio.setDataRate(pyrf24.rf24_datarate_e.RF24_1MBPS)
radio.enableDynamicPayLoads()
radio.setAutoAck(False)
radio.open_rx_pipe(1, 0x6564f4e31)
print("Listening for incoming messages… ")
try:
if radio.available(): # This never returns true
received_message = radio.read(radio.getDynamicPayloadSize()).decode(“utf-8”)
print(f"Received message: {received_message}")
time.sleep(0.01)
except KeyboardInterrupt:
print("Receiver stopped. ")
What I have mentioned are really the only things I think can be the cause of the problem, since the hardware otehrwise seems to be working. The settings that should match do match, unless there are other settings that also need to match. If that is the case, I can give you all the settings I get from running radio.print_details().
The documenation for the library I’m using on the Rock 4C+ isn’t really that great, especially since it don’t seem to work in the way it says it should work. I would be really glad if someone with more experience on this could help.
Thanks in advance.