commit | author | age
|
652221
|
1 |
/* There was a help from these two pages: |
SP |
2 |
https://forum.arduino.cc/t/connect-nrf24l01-to-esp32/678710/4 |
|
3 |
https://electropeak.com/learn/wireless-communication-w-arduino-and-nrf24l01/ |
|
4 |
*/ |
|
5 |
|
|
6 |
#include <RF24_config.h> |
|
7 |
#include <nRF24L01.h> |
|
8 |
#include <RF24.h> |
|
9 |
#include <printf.h> |
|
10 |
|
|
11 |
#include<WiFi.h> |
|
12 |
|
|
13 |
#define IN_TRIGGER 17 |
|
14 |
#define OUT_TRIGGER 16 |
|
15 |
|
|
16 |
|
5e844b
|
17 |
//RF24 radio(2, 4); // CE, CSN // This is for alternative wiring. |
652221
|
18 |
RF24 radio(22, 21); // CE, CSN |
SP |
19 |
|
5e844b
|
20 |
const byte address[6] = {'R','E','C','V', '1'}; // Do not change this address. |
652221
|
21 |
char dataToSend[4] = "TRG"; |
SP |
22 |
|
|
23 |
void IRAM_ATTR isr() { |
|
24 |
digitalWrite(OUT_TRIGGER, LOW); |
5e844b
|
25 |
radio.write( &dataToSend, 4 ); |
652221
|
26 |
long time=micros(); |
5e844b
|
27 |
while(micros()-time<5000); |
SP |
28 |
digitalWrite(OUT_TRIGGER,HIGH); |
652221
|
29 |
} |
SP |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
void setup() { |
|
34 |
// put your setup code here, to run once: |
|
35 |
WiFi.mode(WIFI_OFF); |
|
36 |
btStop(); |
|
37 |
radio.begin(); |
|
38 |
radio.openWritingPipe(address); |
|
39 |
radio.setPALevel(RF24_PA_MAX); |
|
40 |
radio.setDataRate( RF24_1MBPS ); |
|
41 |
radio.setRetries(1,0); // delay, count |
|
42 |
pinMode(OUT_TRIGGER, OUTPUT); |
|
43 |
digitalWrite(OUT_TRIGGER,HIGH); |
|
44 |
attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, FALLING); |
|
45 |
Serial.begin(115200); |
|
46 |
} |
|
47 |
|
|
48 |
void loop() { |
|
49 |
// put your main code here, to run repeatedly: |
5e844b
|
50 |
//To send the code every 5--6 ms, uncomment this code |
SP |
51 |
/* |
652221
|
52 |
radio.write( &dataToSend, 4 ); |
SP |
53 |
long time=micros(); |
|
54 |
while(micros()-time<5000); |
|
55 |
*/ |
|
56 |
} |