commit | author | age
|
9843c5
|
1 |
#include <RF24_config.h> |
SP |
2 |
#include <nRF24L01.h> |
|
3 |
#include <RF24.h> |
|
4 |
#include <printf.h> |
|
5 |
|
652221
|
6 |
//RF24 radio(22, 21); // CE, CSN |
SP |
7 |
RF24 radio(15,4); // CE, CSN |
|
8 |
|
|
9 |
const byte RXaddress[6] = {'R','E','C','V', '1'}; |
|
10 |
const byte TXaddress[6] = {'L','O','G','G', 'R'}; |
|
11 |
|
9843c5
|
12 |
char val[4]; |
SP |
13 |
|
652221
|
14 |
struct PayloadStruct |
SP |
15 |
{ |
|
16 |
uint8_t nodeID; |
|
17 |
unsigned long payloadID; |
|
18 |
float ax; |
|
19 |
float ay; |
|
20 |
float az; |
|
21 |
float wx; |
|
22 |
float wy; |
|
23 |
float wz; |
|
24 |
}; |
|
25 |
|
|
26 |
PayloadStruct payload; |
9843c5
|
27 |
void setup() { |
SP |
28 |
// put your setup code here, to run once: |
|
29 |
|
|
30 |
Serial.begin(115200); |
|
31 |
radio.begin(); |
652221
|
32 |
radio.openReadingPipe(0, RXaddress); |
SP |
33 |
radio.openWritingPipe(TXaddress); |
9843c5
|
34 |
radio.setPALevel(RF24_PA_MIN); |
652221
|
35 |
radio.setDataRate( RF24_250KBPS ); |
SP |
36 |
radio.setPayloadSize(sizeof(payload)); |
9843c5
|
37 |
radio.startListening(); |
652221
|
38 |
payload.payloadID=0; |
SP |
39 |
payload.nodeID=1; |
9843c5
|
40 |
|
SP |
41 |
} |
|
42 |
|
|
43 |
void loop() { |
|
44 |
// put your main code here, to run repeatedly: |
|
45 |
|
|
46 |
delay(5); |
652221
|
47 |
//radio.startListening(); |
9843c5
|
48 |
if ( radio.available()) { |
SP |
49 |
while (radio.available()) { |
|
50 |
|
|
51 |
radio.read(&val, sizeof(val)); |
|
52 |
Serial.print("Received = "); |
|
53 |
Serial.println(val); |
652221
|
54 |
radio.stopListening(); // put radio in TX mode |
SP |
55 |
|
|
56 |
unsigned long start_timer = micros(); // start the timer |
|
57 |
bool report = radio.write(&payload, sizeof(payload)); // transmit & save the report |
|
58 |
unsigned long end_timer = micros(); // end the timer |
|
59 |
if (report) { |
|
60 |
// payload was delivered |
|
61 |
|
|
62 |
Serial.print(F("Transmission of payloadID ")); |
|
63 |
Serial.print(payload.payloadID); // print payloadID |
|
64 |
Serial.print(F(" as node ")); |
|
65 |
Serial.print(payload.nodeID); // print nodeID |
|
66 |
Serial.print(F(" successful!")); |
|
67 |
Serial.print(F(" Time to transmit: ")); |
|
68 |
Serial.print(end_timer - start_timer); // print the timer result |
|
69 |
Serial.println(F(" us")); |
|
70 |
} else { |
|
71 |
Serial.println(F("Transmission failed or timed out")); // payload was not delivered |
|
72 |
} |
|
73 |
payload.payloadID++; // increment payload number |
|
74 |
radio.startListening(); |
9843c5
|
75 |
} |
SP |
76 |
} |
|
77 |
|
|
78 |
} |