Written by 2bndy5 in 2020
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.
20RF24 radio(CE_PIN, CSN_PIN);
23uint8_t address[][6] = {
"1Node",
"2Node" };
48 Serial.println(F(
"radio hardware is not responding!!"));
53 Serial.println(F(
"RF24/examples/GettingStarted"));
56 Serial.println(F(
"Which radio is this? Enter '0' or '1'. Defaults to '0'"));
57 while (!Serial.available()) {
60 char input = Serial.parseInt();
61 radioNumber = input == 1;
62 Serial.print(F(
"radioNumber = "));
63 Serial.println((
int)radioNumber);
66 Serial.println(F(
"*** PRESS 'T' to begin transmitting to the other node"));
75 radio.setPayloadSize(
sizeof(payload));
78 radio.openWritingPipe(address[radioNumber]);
81 radio.openReadingPipe(1, address[!radioNumber]);
85 radio.stopListening();
87 radio.startListening();
102 unsigned long start_timer = micros();
103 bool report = radio.write(&payload,
sizeof(
float));
104 unsigned long end_timer = micros();
107 Serial.print(F(
"Transmission successful! "));
108 Serial.print(F(
"Time to transmit = "));
109 Serial.print(end_timer - start_timer);
110 Serial.print(F(
" us. Sent: "));
111 Serial.println(payload);
114 Serial.println(F(
"Transmission failed or timed out"));
124 if (radio.available(&pipe)) {
125 uint8_t bytes = radio.getPayloadSize();
126 radio.read(&payload, bytes);
127 Serial.print(F(
"Received "));
129 Serial.print(F(
" bytes on pipe "));
131 Serial.print(F(
": "));
132 Serial.println(payload);
136 if (Serial.available()) {
139 char c = toupper(Serial.read());
140 if (c ==
'T' && !role) {
144 Serial.println(F(
"*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
145 radio.stopListening();
147 }
else if (c ==
'R' && role) {
151 Serial.println(F(
"*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
152 radio.startListening();
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.