As copied from thread: Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum
As entered in reply #1 to original post in above thread:
Copied as typed in reply, and pasted into a new ino file:
// 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;
}
As copied from thread: Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum
As entered in reply #1 to original post in above thread:
Copied as typed in rely, and pasted into a new ino file:
// 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;
}
}
Method used to copy and paste:
in reply on thread, click "[Select]" link in code block and highlight all. Press CTRL+C on keyboard. Open new ino file in Arduino IDE. In ino file, press CTRL+A on keyboard to select all. Then press CTRL+C to paste code copied from above referenced thread. Do this for SimpleTx.ino and SimpleRx.ino
Results from above sketches running:
Step 4) run SimpleTx.ino on Nano(1).
Step 5) run SimpleRx.ino on Nano(2).
Step 6) open serial monitor on Nano(2). Serial Monitor shows:
SimpleRx Starting
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Step 7) open serial monitor on Nano(1). Serial Monitor shows:
SimpleTx Starting
(pause for comment) - I noticed that according to SimpleRx.ino, the code should have been:
SimpleRx Starting
Data received
{value}
Data received
{value}
or
SimpleRx Starting
Data received {value}
Data received {value}
Did not get this. from what I could tell from the code, it appeared that the Nano(2) thought it was getting data, just nothing there.
Looking at the SimpleTx.ino code, I was supposed to get:
SimpleTx Starting
Data Sent
{value}
Data Sent
{value}
or
SimpleTx Starting
Data Sent {value}
Data Sent {value}
But I was not getting this at all. Just the "SimpleTX Starting".