Hi there! I've been researching around how to work out a serial communication between two Arduinos. I've tried out loads of tutorials from YouTube, but was also recommended this tutorial here on the Arduino forums by Robin2.
However, whatever tutorial I do, none of it seems to establish connection. Let's try to look at the one by Robin2 and my methodology in debugging my system.
I am also currently using the base module recommended by ArduinoInfo so that I don't need to worry about the 3.3V or 5V/Capacitor issue.
Hoping that someone out there also experienced an issue like this and is willing to share their solution!
SimpleRX I copied off of his tutorial
// 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'};
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;
}
}
SimpleTX I copied off of his tutorial
// 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'};
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 of COM ports:
Hypothesis 1: Checking for known IDE compatiblity issues
First, I took note of my IDE version, which is currently Arduino 1.8.16. I didn't see any issues with the version as far as I know. Please do inform me, however, if there is a known issue that I am now aware of!
Hypothesis 2: Checking for known library compatiblity issues
The next thing I did was a fresh-install of the TMRh20 version of the RF24 library via Github, which I manually placed into my libraries folder.
When a connection was still not established, I instead uninstalled and re-installed the Arduino IDE so that I could use the TMRh20 version from the built in Arduino Library Manager. Though, the issue still persisted.
Hypothesis 3: Wire connections between the modules
I made sure if I experienced errors, I would do a clean up of my Arduinos; I removed each and every connection and put them back together. If no connection was established, I would switch components (hey, what's the harm in that, am I right?). Still, nothing.
Then I bought extra jumper cables, because it might have been a continuity issue. Nevertheless, still a no-go on new cables.
I also made sure that my CN, CSE, etc. wiring was based off of Robin2's tutorial, so that I have a point of reference.
Hypothesis 4: Voltage, maybe?
Currently using the base module recommended by ArduinoInfo. I'm not sure if that would mean I might experience any issue, but if it does, please do inform me!
Hypothesis 5: Is this a hardware-related issue?
Last, but certainly not the least: it could be that my antennas are broken. I bought three (the one is an extra), and switched them up, and none of them are still able to establish a connection, so I'm not sure with that. I wanted to get a second opinion, however, on whether or not this could be a hardware-related issue.
I tried out Robin2's CheckConnection.ino as well, so here is the output I got:
Using Antenna 1
13:12:58.804 -> CheckConnection Starting
13:12:58.851 ->
13:12:58.851 -> FIRST WITH THE DEFAULT ADDRESSES after power on
13:12:58.897 -> Note that RF24 does NOT reset when Arduino resets - only when power is removed
13:12:58.989 -> If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
13:12:59.081 -> communicating with the nRF24
13:12:59.129 ->
13:12:59.129 -> SPI Speedz = 10 Mhz
13:12:59.129 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:12:59.174 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
13:12:59.219 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
13:12:59.266 -> TX_ADDR = 0xe7e7e7e7e7
13:12:59.313 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
13:12:59.359 -> EN_AA = 0x3f
13:12:59.359 -> EN_RXADDR = 0x03
13:12:59.359 -> RF_CH = 0x4c
13:12:59.406 -> RF_SETUP = 0x01
13:12:59.406 -> CONFIG = 0x0e
13:12:59.406 -> DYNPD/FEATURE = 0x00 0x00
13:12:59.452 -> Data Rate = 1 MBPS
13:12:59.500 -> Model = nRF24L01+
13:12:59.500 -> CRC Length = 16 bits
13:12:59.500 -> PA Power = PA_MIN
13:12:59.546 -> ARC = 0
13:12:59.546 ->
13:12:59.546 ->
13:12:59.546 -> AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
13:12:59.593 -> and 250KBPS data rate
13:12:59.639 ->
13:12:59.639 -> SPI Speedz = 10 Mhz
13:12:59.639 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:12:59.731 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
13:12:59.778 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
13:12:59.823 -> TX_ADDR = 0xe7e7e7e7e7
13:12:59.823 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
13:12:59.870 -> EN_AA = 0x3f
13:12:59.870 -> EN_RXADDR = 0x03
13:12:59.917 -> RF_CH = 0x4c
13:12:59.917 -> RF_SETUP = 0x21
13:12:59.965 -> CONFIG = 0x0e
13:12:59.965 -> DYNPD/FEATURE = 0x00 0x00
13:13:00.011 -> Data Rate = 250 KBPS
13:13:00.011 -> Model = nRF24L01+
13:13:00.011 -> CRC Length = 16 bits
13:13:00.057 -> PA Power = PA_MIN
13:13:00.057 -> ARC = 0
13:13:00.102 ->
13:13:00.102 ->
Using Antenna 2
13:13:03.140 -> CheckConnection Starting
13:13:03.187 ->
13:13:03.187 -> FIRST WITH THE DEFAULT ADDRESSES after power on
13:13:03.233 -> Note that RF24 does NOT reset when Arduino resets - only when power is removed
13:13:03.326 -> If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
13:13:03.371 -> communicating with the nRF24
13:13:03.417 ->
13:13:03.417 -> SPI Speedz = 10 Mhz
13:13:03.463 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:13:03.510 -> RX_ADDR_P0-1 = 0x4141417852 0x4141417852
13:13:03.556 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
13:13:03.602 -> TX_ADDR = 0x4141417852
13:13:03.602 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
13:13:03.649 -> EN_AA = 0x3f
13:13:03.695 -> EN_RXADDR = 0x03
13:13:03.695 -> RF_CH = 0x4c
13:13:03.695 -> RF_SETUP = 0x01
13:13:03.742 -> CONFIG = 0x0e
13:13:03.742 -> DYNPD/FEATURE = 0x00 0x00
13:13:03.789 -> Data Rate = 1 MBPS
13:13:03.789 -> Model = nRF24L01+
13:13:03.835 -> CRC Length = 16 bits
13:13:03.835 -> PA Power = PA_MIN
13:13:03.882 -> ARC = 5
13:13:03.882 ->
13:13:03.882 ->
13:13:03.882 -> AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
13:13:03.928 -> and 250KBPS data rate
13:13:03.975 ->
13:13:03.975 -> SPI Speedz = 10 Mhz
13:13:03.975 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
13:13:04.022 -> RX_ADDR_P0-1 = 0x4141417852 0x4141417852
13:13:04.068 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
13:13:04.114 -> TX_ADDR = 0x4141417852
13:13:04.159 -> RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
13:13:04.206 -> EN_AA = 0x3f
13:13:04.206 -> EN_RXADDR = 0x03
13:13:04.252 -> RF_CH = 0x4c
13:13:04.252 -> RF_SETUP = 0x21
13:13:04.252 -> CONFIG = 0x0e
13:13:04.299 -> DYNPD/FEATURE = 0x00 0x00
13:13:04.299 -> Data Rate = 250 KBPS
13:13:04.346 -> Model = nRF24L01+
13:13:04.346 -> CRC Length = 16 bits
13:13:04.393 -> PA Power = PA_MIN
13:13:04.393 -> ARC = 5
13:13:04.393 ->
13:13:04.393 ->
They both use the same code:
// 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() {
}