I have now tried this code, and I still do not manage to send information.
/*
* See documentation at https://nRF24.github.io/RF24
* See License information at root directory of this library
* Author: Brendan Doherty (2bndy5)
*/
/**
* A simple example of sending data from 1 nRF24L01 transceiver to another.
*
* This example was written to be used on 2 devices acting as "nodes".
* Use the Serial Monitor to change each node's behavior.
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
// instantiate an object for the nRF24L01 transceiver
RF24 radio(8, 9); // using pin 7 for the CE pin, and pin 8 for the CSN pin
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
// Leave open to be the 'ping' transmitter
const short role_pin = 5;
// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL; ///0xCCCECCCECC
uint8_t pipe_number = 1;
// For this example, we'll be using a payload containing
// a single float number that will be incremented
// on every successful transmission
float payload = 0.0;
// The various roles supported by this sketch
typedef enum {
role_sender = 1,
role_receiver
} role_e;
// The debug-friendly names of those roles
const char* role_friendly_name[] = {"invalid", "Sender", "Receiver"};
// The role of the current running sketch
role_e role;
void setup() {
// set up the role pin
pinMode(role_pin, INPUT);
digitalWrite(role_pin, HIGH);
delay(20); // Just to get a solid reading on the role pin
// read the address pin, establish our role
if (digitalRead(role_pin)) {
role = role_sender;
} else {
role = role_receiver;
}
Serial.begin(115200);
printf_begin();
while (!Serial) {
// some boards need to wait to ensure access to serial over USB
}
// print example's introductory prompt
Serial.println(F("RF24/examples/GettingStarted"));
// initialize the transceiver on the SPI bus
if (!radio.begin()) {
Serial.println(F("radio hardware is not responding!!"));
while (1) {} // hold in infinite loop
}
//Check if the module connects to SPI
if (!radio.isChipConnected()) {
Serial.println(F("Chip not connected."));
while (1) {} // hold program in infinite loop to prevent subsequent errors
}
printf("ROLE: %s\n\r", role_friendly_name[role]);
printf("+READY press any key to start\n\r\n\r");
while (!Serial.available()) {}
//What does each module do.
if (role == role_sender){
radio.openWritingPipe(pipe);
}else{
radio.openReadingPipe(pipe_number, pipe);
}
// Start listening
if (role == role_receiver){
radio.startListening();
}
//
// Dump the configuration of the rf unit for debugging
//
radio.printDetails();
/*
if (role == role_receiver){
printf("\n\r+OK ");
}*/
}
void loop() {
if (role == role_sender) {
// This device is a TX node
unsigned long start_timer = micros(); // start the timer
bool report = radio.write(&payload, sizeof(float)); // transmit & save the report
unsigned long end_timer = micros(); // end the timer
if (report) {
Serial.print(F("Transmission successful! ")); // payload was delivered
Serial.print(F("Time to transmit = "));
Serial.print(end_timer - start_timer); // print the timer result
Serial.print(F(" us. Sent: "));
Serial.println(payload); // print payload sent
payload += 0.01; // increment float payload
} else {
Serial.println(F("Transmission failed or timed out")); // payload was not delivered
}
// to make this example readable in the serial monitor
delay(1000); // slow transmissions down by 1 second
} else {
// This device is a RX node
radio.flush_rx();
uint8_t pipe;
if (radio.available(&pipe)) { // is there a payload? get the pipe number that recieved it
uint8_t bytes = radio.getPayloadSize(); // get the size of the payload
radio.read(&payload, bytes); // fetch payload from FIFO
Serial.print(F("Received "));
Serial.print(bytes); // print the size of the payload
Serial.print(F(" bytes on pipe "));
Serial.print(pipe); // print the pipe number
Serial.print(F(": "));
Serial.println(payload); // print the payload's value
}
} // role
} // loop
The receiver module does not print anything, and the emisor module prints the following message:
ROLE: Sender
+READY press any key to start
SPI Speedz = 10 Mhz
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xe8e8f0f0e1 0xc2c2c2c2c2
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xe8e8f0f0e1
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x07
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1 MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX
ARC = 15
Transmission failed or timed out
Transmission failed or timed out
Transmission failed or timed out