2014 Contribution by tong67
Updated 2020 by 2bndy5 for the SpenceKonde ATTinyCore
The RF24 library uses the ATTinyCore by SpenceKonde
This sketch is a duplicate of the ManualAcknowledgements.ino example (without all the Serial input/output code), and it demonstrates a ATTiny25/45/85 or ATTiny24/44/84 driving the nRF24L01 transceiver using the RF24 class to communicate with another node.
A simple example of sending data from 1 nRF24L01 transceiver to another with manually transmitted (non-automatic) Acknowledgement (ACK) payloads. This example still uses ACK packets, but they have no payloads. Instead the acknowledging response is sent with write()
. This tactic allows for more updated acknowledgement payload data, where actual ACK payloads' data are outdated by 1 transmission because they have to loaded before receiving a transmission.
This example was written to be used on 2 devices acting as "nodes".
1
8
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85#include "SPI.h"
87
88
89#define CE_PIN 3
90#define CSN_PIN 4
91
92
93
94RF24 radio(CE_PIN, CSN_PIN);
95
96
97uint8_t address[][6] = { "1Node", "2Node" };
98
99
100
101
102
103bool radioNumber = 1;
104
105
106bool role = false;
107
108
109
110
111
112struct PayloadStruct {
113 char message[7];
114 uint8_t counter;
115};
116PayloadStruct payload;
117
118void setup() {
119
120
121 payload.message[6] = 0;
122
123
124 if (!radio.begin()) {
125 while (1) {}
126 }
127
128
129
130
132
133
134
135 radio.setPayloadSize(sizeof(payload));
136
137
138 radio.openWritingPipe(address[radioNumber]);
139
140
141 radio.openReadingPipe(1, address[!radioNumber]);
142
143 if (role) {
144
145
146 memcpy(payload.message, "Hello ", 6);
147 radio.stopListening();
148 } else {
149
150
151 memcpy(payload.message, "World ", 6);
152 radio.startListening();
153 }
154}
155
156void loop() {
157
158 if (role) {
159
160
161 bool report = radio.write(&payload, sizeof(payload));
162
163 if (report) {
164
165
166 radio.startListening();
167 unsigned long start_timeout =
millis();
168 while (!radio.available()) {
169 if (
millis() - start_timeout > 200)
170 break;
171 }
172 radio.stopListening();
173
174
175 if (radio.available()) {
176
177 PayloadStruct received;
178 radio.read(&received, sizeof(received));
179 payload.counter = received.counter;
180 }
181 }
182
183
185
186 } else {
187
188
189 if (radio.available()) {
190
191 PayloadStruct received;
192 radio.read(&received, sizeof(received));
193 payload.counter = received.counter + 1;
194
195
196 radio.stopListening();
197
198 radio.writeFast(&payload, sizeof(payload));
199 radio.txStandBy(150);
200
201 radio.startListening();
202 }
203 }
204}
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.