| | |
| | | #include <RF24.h> |
| | | #include <printf.h> |
| | | |
| | | RF24 radio(22, 21); // CE, CSN |
| | | const byte address[6] = {'R','E','C','V', '1'}; |
| | | //RF24 radio(22, 21); // CE, CSN |
| | | RF24 radio(15,4); // CE, CSN |
| | | |
| | | const byte RXaddress[6] = {'R','E','C','V', '1'}; |
| | | const byte TXaddress[6] = {'L','O','G','G', 'R'}; |
| | | |
| | | char val[4]; |
| | | |
| | | struct PayloadStruct |
| | | { |
| | | uint8_t nodeID; |
| | | unsigned long payloadID; |
| | | float ax; |
| | | float ay; |
| | | float az; |
| | | float wx; |
| | | float wy; |
| | | float wz; |
| | | }; |
| | | |
| | | PayloadStruct payload; |
| | | void setup() { |
| | | // put your setup code here, to run once: |
| | | |
| | | Serial.begin(115200); |
| | | radio.begin(); |
| | | radio.openReadingPipe(0, address); |
| | | radio.openReadingPipe(0, RXaddress); |
| | | radio.openWritingPipe(TXaddress); |
| | | radio.setPALevel(RF24_PA_MIN); |
| | | radio.setDataRate( RF24_250KBPS ); |
| | | radio.setPayloadSize(sizeof(payload)); |
| | | radio.startListening(); |
| | | payload.payloadID=0; |
| | | payload.nodeID=1; |
| | | |
| | | } |
| | | |
| | |
| | | // put your main code here, to run repeatedly: |
| | | |
| | | delay(5); |
| | | radio.startListening(); |
| | | //radio.startListening(); |
| | | if ( radio.available()) { |
| | | while (radio.available()) { |
| | | |
| | | radio.read(&val, sizeof(val)); |
| | | Serial.print("Received = "); |
| | | Serial.println(val); |
| | | radio.stopListening(); // put radio in TX mode |
| | | |
| | | unsigned long start_timer = micros(); // start the timer |
| | | bool report = radio.write(&payload, sizeof(payload)); // transmit & save the report |
| | | unsigned long end_timer = micros(); // end the timer |
| | | if (report) { |
| | | // payload was delivered |
| | | |
| | | Serial.print(F("Transmission of payloadID ")); |
| | | Serial.print(payload.payloadID); // print payloadID |
| | | Serial.print(F(" as node ")); |
| | | Serial.print(payload.nodeID); // print nodeID |
| | | Serial.print(F(" successful!")); |
| | | Serial.print(F(" Time to transmit: ")); |
| | | Serial.print(end_timer - start_timer); // print the timer result |
| | | Serial.println(F(" us")); |
| | | } else { |
| | | Serial.println(F("Transmission failed or timed out")); // payload was not delivered |
| | | } |
| | | payload.payloadID++; // increment payload number |
| | | radio.startListening(); |
| | | } |
| | | } |
| | | |