commit | author | age
|
b08ee1
|
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 |
|
c6fcd5
|
11 |
#include<WiFi.h> |
SP |
12 |
|
b08ee1
|
13 |
#define IN_TRIGGER 17 |
SP |
14 |
#define OUT_TRIGGER 16 |
c6fcd5
|
15 |
|
b08ee1
|
16 |
|
SP |
17 |
RF24 radio(22, 21); // CE, CSN |
|
18 |
|
|
19 |
const byte address[6] = {'R','E','C','V', '1'}; |
|
20 |
char dataToSend[4] = "TRG"; |
c6fcd5
|
21 |
|
SP |
22 |
void IRAM_ATTR isr() { |
e0a3ca
|
23 |
// detachInterrupt(digitalPinToInterrupt(IN_TRIGGER)); |
SP |
24 |
digitalWrite(OUT_TRIGGER, LOW); |
|
25 |
long time=micros(); |
|
26 |
while(micros()-time<4000); |
|
27 |
digitalWrite(OUT_TRIGGER,HIGH); |
|
28 |
// radio.write( &dataToSend, sizeof(dataToSend) ); |
|
29 |
|
|
30 |
// attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, RISING); |
|
31 |
|
c6fcd5
|
32 |
} |
b08ee1
|
33 |
|
SP |
34 |
|
c6fcd5
|
35 |
|
SP |
36 |
void setup() { |
|
37 |
// put your setup code here, to run once: |
|
38 |
|
|
39 |
WiFi.mode(WIFI_OFF); |
|
40 |
btStop(); |
|
41 |
|
b08ee1
|
42 |
|
SP |
43 |
radio.begin(); |
|
44 |
radio.openWritingPipe(address); |
d6fc89
|
45 |
radio.setPALevel(RF24_PA_MAX); |
e0a3ca
|
46 |
radio.setDataRate( RF24_250KBPS ); |
b08ee1
|
47 |
|
e0a3ca
|
48 |
//pinMode(IN_TRIGGER, INPUT_PULLUP); |
c6fcd5
|
49 |
pinMode(OUT_TRIGGER, OUTPUT); |
e0a3ca
|
50 |
digitalWrite(OUT_TRIGGER,HIGH); |
SP |
51 |
attachInterrupt(digitalPinToInterrupt(IN_TRIGGER), isr, FALLING); |
|
52 |
Serial.begin(115200); |
c6fcd5
|
53 |
|
SP |
54 |
} |
|
55 |
|
|
56 |
void loop() { |
|
57 |
// put your main code here, to run repeatedly: |
e0a3ca
|
58 |
Serial.print(micros()); |
SP |
59 |
Serial.println(": ---> TRG"); |
|
60 |
radio.write( &dataToSend, sizeof(dataToSend) ); |
|
61 |
Serial.print(micros()); |
|
62 |
Serial.println(": TRG--->"); |
|
63 |
delay(5000); |
|
64 |
|
c6fcd5
|
65 |
} |