From 5e844b869fd9f96f333f712311974984da758443 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Wed, 18 May 2022 22:18:50 +0000 Subject: [PATCH] Camera trigger code cleanup and moving radio transmission to ISR --- firmware/accelerometer_nrf24/accelerometer_nrf24.ino | 32 +++++++------------------------- 1 files changed, 7 insertions(+), 25 deletions(-) diff --git a/firmware/accelerometer_nrf24/accelerometer_nrf24.ino b/firmware/accelerometer_nrf24/accelerometer_nrf24.ino index fce3224..0f2ee39 100644 --- a/firmware/accelerometer_nrf24/accelerometer_nrf24.ino +++ b/firmware/accelerometer_nrf24/accelerometer_nrf24.ino @@ -14,61 +14,43 @@ #define OUT_TRIGGER 16 -//RF24 radio(2, 4); // CE, CSN +//RF24 radio(2, 4); // CE, CSN // This is for alternative wiring. RF24 radio(22, 21); // CE, CSN -const byte address[6] = {'R','E','C','V', '1'}; +const byte address[6] = {'R','E','C','V', '1'}; // Do not change this address. char dataToSend[4] = "TRG"; void IRAM_ATTR isr() { -// detachInterrupt(digitalPinToInterrupt(IN_TRIGGER)); digitalWrite(OUT_TRIGGER, LOW); + radio.write( &dataToSend, 4 ); long time=micros(); - while(micros()-time<4000); - digitalWrite(OUT_TRIGGER,HIGH); -// radio.write( &dataToSend, sizeof(dataToSend) ); - -// attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, RISING); - + while(micros()-time<5000); + digitalWrite(OUT_TRIGGER,HIGH); } void setup() { // put your setup code here, to run once: - WiFi.mode(WIFI_OFF); btStop(); - - radio.begin(); radio.openWritingPipe(address); radio.setPALevel(RF24_PA_MAX); radio.setDataRate( RF24_1MBPS ); radio.setRetries(1,0); // delay, count - //pinMode(IN_TRIGGER, INPUT_PULLUP); pinMode(OUT_TRIGGER, OUTPUT); digitalWrite(OUT_TRIGGER,HIGH); attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, FALLING); Serial.begin(115200); - } void loop() { // put your main code here, to run repeatedly: -//Serial.print(micros()); -//Serial.println(": ---> TRG"); -//unsigned long start_timer = micros(); - +//To send the code every 5--6 ms, uncomment this code +/* radio.write( &dataToSend, 4 ); long time=micros(); while(micros()-time<5000); -//Serial.print(micros()); -//Serial.println(": TRG--->"); -/* -unsigned long end_timer = micros(); -Serial.print(F(" Time to transmit: ")); - Serial.print(end_timer - start_timer); // print the timer result - Serial.println(F(" us")); */ } -- Gitblit v1.9.3