commit | author | age
|
652221
|
1 |
#include <RF24_config.h> |
SP |
2 |
#include <nRF24L01.h> |
|
3 |
#include <RF24.h> |
|
4 |
#include <printf.h> |
|
5 |
|
|
6 |
RF24 radio(22, 21); // CE, CSN |
|
7 |
//RF24 radio(15,4); // CE, CSN |
|
8 |
|
|
9 |
const byte address[6] = {'L','O','G','G', 'R'}; |
|
10 |
|
|
11 |
char val[4]; |
|
12 |
|
|
13 |
struct PayloadStruct |
|
14 |
{ |
|
15 |
uint8_t nodeID; |
|
16 |
uint16_t payloadID; |
|
17 |
float ax; |
|
18 |
float ay; |
|
19 |
float az; |
|
20 |
float wx; |
|
21 |
float wy; |
|
22 |
float wz; |
|
23 |
}; |
|
24 |
|
|
25 |
PayloadStruct payload; |
|
26 |
void setup() { |
|
27 |
// put your setup code here, to run once: |
|
28 |
|
|
29 |
Serial.begin(115200); |
|
30 |
radio.begin(); |
|
31 |
radio.openReadingPipe(0, address); |
|
32 |
radio.setPALevel(RF24_PA_MIN); |
|
33 |
radio.setDataRate( RF24_1MBPS ); |
|
34 |
radio.startListening(); |
|
35 |
|
|
36 |
} |
|
37 |
|
|
38 |
void loop() { |
|
39 |
// put your main code here, to run repeatedly: |
|
40 |
|
|
41 |
delay(5); |
|
42 |
//radio.startListening(); |
|
43 |
if ( radio.available()) { |
|
44 |
while (radio.available()) { |
|
45 |
Serial.print(millis()); |
|
46 |
radio.read(&payload, sizeof(payload)); |
|
47 |
/* Serial.print("Received payload ID = "); |
|
48 |
Serial.print((int)payload.payloadID); |
|
49 |
Serial.print(" ax="); |
|
50 |
Serial.println(payload.ax); |
|
51 |
*/ |
|
52 |
|
|
53 |
Serial.print(","); |
|
54 |
Serial.print(payload.nodeID); |
|
55 |
Serial.print(","); |
|
56 |
Serial.print(payload.payloadID); |
|
57 |
Serial.print(","); |
|
58 |
Serial.print(payload.ax); |
|
59 |
Serial.print(","); |
|
60 |
Serial.print(payload.ay); |
|
61 |
Serial.print(","); |
|
62 |
Serial.print(payload.az); |
|
63 |
Serial.print(","); |
|
64 |
Serial.print(payload.wx); |
|
65 |
Serial.print(","); |
|
66 |
Serial.print(payload.wy); |
|
67 |
Serial.print(","); |
|
68 |
Serial.println(payload.wz); |
|
69 |
|
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
} |