/* 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 17
|
#define OUT_TRIGGER 16
|
|
|
//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'}; // Do not change this address.
|
char dataToSend[4] = "TRG";
|
|
void IRAM_ATTR isr() {
|
digitalWrite(OUT_TRIGGER, LOW);
|
radio.write( &dataToSend, 4 );
|
long time=micros();
|
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(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:
|
//To send the code every 5--6 ms, uncomment this code
|
/*
|
radio.write( &dataToSend, 4 );
|
long time=micros();
|
while(micros()-time<5000);
|
*/
|
}
|