From 652221b10999170b5ebbc7268810d0da1d721f45 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Wed, 18 May 2022 11:12:52 +0000 Subject: [PATCH] Miha's accelerometer --- firmware/debug_receiver/receiver/receiver.ino | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 47 insertions(+), 4 deletions(-) diff --git a/firmware/debug_receiver/receiver/receiver.ino b/firmware/debug_receiver/receiver/receiver.ino index 478a842..5466d12 100644 --- a/firmware/debug_receiver/receiver/receiver.ino +++ b/firmware/debug_receiver/receiver/receiver.ino @@ -3,18 +3,40 @@ #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; } @@ -22,13 +44,34 @@ // 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(); } } -- Gitblit v1.9.3