Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lora receiverCallBack modified by HwThinker for TTGO Lora T-Deer-915MHz
- #include <SPI.h>
- #include <LoRa.h>
- #define SCK 13 // GPIO5 -- lora SCK
- #define MISO 12 // GPIO19 -- lora MISO
- #define MOSI 11 // GPIO27 -- lora MOSI
- #define SS 10 // GPIO18 -- lora CS
- #define RST 9 // GPIO14 -- RESET (If Lora does not work, replace it with GPIO14)
- #define DI0 2 // GPIO26 -- IRQ(Interrupt Request)
- #define BAND 915E6
- #define LED_EXTERNAL 3
- int state = 0;
- void setup() {
- pinMode(LED_EXTERNAL, OUTPUT);
- Serial.begin(115200);
- while (!Serial);
- // SPI.begin(SCK, MISO, MOSI, SS);
- LoRa.setPins(SS,RST,DI0);
- Serial.println("LoRa Receiver Callback");
- if (!LoRa.begin(BAND)) {
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- Serial.println("LoRa Initial OK! Blinky 1.5 second");
- for (int i=0;i<15;i++) {
- digitalWrite(LED_EXTERNAL, digitalRead(LED_EXTERNAL) ? LOW : HIGH);
- delay(100);
- }
- // register the receive callback
- LoRa.onReceive(onReceive);
- // put the radio into receive mode
- LoRa.receive();
- }
- void loop() {
- // do nothing
- }
- void onReceive(int packetSize) {
- // received a packet
- Serial.print("Received packet '");
- // read packet
- for (int i = 0; i < packetSize; i++) {
- Serial.print((char)LoRa.read());
- }
- // print RSSI of packet
- Serial.print("' with RSSI ");
- Serial.println(LoRa.packetRssi());
- digitalWrite(LED_EXTERNAL, (state) ? HIGH : LOW);
- state = !state;
- //or digitalWrite(LED_EXTERNAL, !digitalRead(LED_EXTERNAL));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement