Written by 2bndy5 in 2020
A simple example of streaming 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" };
40void makePayload(uint8_t);
54 Serial.println(F(
"radio hardware is not responding!!"));
59 Serial.println(F(
"RF24/examples/StreamingData"));
62 Serial.println(F(
"Which radio is this? Enter '0' or '1'. Defaults to '0'"));
63 while (!Serial.available()) {
66 char input = Serial.parseInt();
67 radioNumber = input == 1;
68 Serial.print(F(
"radioNumber = "));
69 Serial.println((
int)radioNumber);
72 Serial.println(F(
"*** PRESS 'T' to begin transmitting to the other node"));
81 radio.setPayloadSize(SIZE);
84 radio.openWritingPipe(address[radioNumber]);
87 radio.openReadingPipe(1, address[!radioNumber]);
91 radio.stopListening();
93 radio.startListening();
111 uint8_t failures = 0;
112 unsigned long start_timer = micros();
115 if (!radio.writeFast(&buffer, SIZE)) {
122 if (failures >= 100) {
123 Serial.print(F(
"Too many failures detected. Aborting at payload "));
124 Serial.println(buffer[0]);
128 unsigned long end_timer = micros();
130 Serial.print(F(
"Time to transmit = "));
131 Serial.print(end_timer - start_timer);
132 Serial.print(F(
" us with "));
133 Serial.print(failures);
134 Serial.println(F(
" failures detected"));
142 if (radio.available()) {
143 radio.read(&buffer, SIZE);
144 Serial.print(F(
"Received: "));
145 Serial.print(buffer);
146 Serial.print(F(
" - "));
147 Serial.println(counter++);
151 if (Serial.available()) {
154 char c = toupper(Serial.read());
155 if (c ==
'T' && !role) {
160 Serial.println(F(
"*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
161 radio.stopListening();
163 }
else if (c ==
'R' && role) {
167 Serial.println(F(
"*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
168 radio.startListening();
175void makePayload(uint8_t i) {
181 buffer[0] = i + (i < 26 ? 65 : 71);
182 for (uint8_t j = 0; j < SIZE - 1; ++j) {
183 char chr = j >= (SIZE - 1) / 2 + abs((SIZE - 1) / 2 - i);
184 chr |= j < (SIZE - 1) / 2 - abs((SIZE - 1) / 2 - i);
185 buffer[j + 1] = chr + 48;
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.