Samo Penic
2022-05-24 ff462a7ce664a8e224c32d1acbb82f9692c5327f
firmware/trigger_firmware/trigger_firmware.ino
@@ -1,14 +1,37 @@
/* There was a help from these two pages:
https://forum.arduino.cc/t/connect-nrf24l01-to-esp32/678710/4
https://electropeak.com/learn/wireless-communication-w-arduino-and-nrf24l01/
*/
#include <RF24_config.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include<WiFi.h>
#define IN_TRIGGER 18
#define OUT_TRIGGER 19
#define IN_TRIGGER 17
#define OUT_TRIGGER 16
RF24 radio(22, 21); // CE, CSN
const byte address[6] = {'R','E','C','V', '1'};
char dataToSend[4] = "TRG";
void IRAM_ATTR isr() {
    digitalWrite(OUT_TRIGGER, HIGH);
    delay(1);
    digitalWrite(OUT_TRIGGER,LOW);
//    detachInterrupt(digitalPinToInterrupt(IN_TRIGGER));
    digitalWrite(OUT_TRIGGER, LOW);
    long time=micros();
    while(micros()-time<4000);
    digitalWrite(OUT_TRIGGER,HIGH);
//        radio.write( &dataToSend, sizeof(dataToSend) );
//    attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, RISING);
}
void setup() {
  // put your setup code here, to run once:
@@ -16,13 +39,27 @@
  WiFi.mode(WIFI_OFF);
  btStop();
  pinMode(IN_TRIGGER, INPUT_PULLUP);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate( RF24_250KBPS );
  //pinMode(IN_TRIGGER, INPUT_PULLUP);
  pinMode(OUT_TRIGGER, OUTPUT);
  attachInterrupt(IN_TRIGGER, isr, RISING);
  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");
radio.write( &dataToSend, sizeof(dataToSend) );
Serial.print(micros());
Serial.println(": TRG--->");
    delay(5000);
}