Advertisement
hwthinker

LoraReceiver_TDeer-915MHZ

Sep 20th, 2019
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // lora receiverCallBack modified by HwThinker for TTGO Lora T-Deer-915MHz
  2.  
  3. #include <SPI.h>
  4. #include <LoRa.h>
  5.  
  6. #define SCK     13    // GPIO5  -- lora SCK
  7. #define MISO    12   // GPIO19 -- lora MISO
  8. #define MOSI    11   // GPIO27 -- lora MOSI
  9. #define SS      10   // GPIO18 -- lora CS
  10. #define RST     9   // GPIO14 -- RESET (If Lora does not work, replace it with GPIO14)
  11. #define DI0     2   // GPIO26 -- IRQ(Interrupt Request)
  12.  
  13. #define BAND    915E6
  14.  
  15.  
  16. #define LED_EXTERNAL 3
  17. int state = 0;
  18.  
  19. void setup() {
  20.   pinMode(LED_EXTERNAL, OUTPUT);
  21.   Serial.begin(115200);
  22.   while (!Serial);
  23. //  SPI.begin(SCK, MISO, MOSI, SS);
  24.   LoRa.setPins(SS,RST,DI0);
  25.  
  26.   Serial.println("LoRa Receiver Callback");
  27.  
  28.   if (!LoRa.begin(BAND)) {
  29.     Serial.println("Starting LoRa failed!");
  30.     while (1);
  31.   }
  32.  
  33.   Serial.println("LoRa Initial OK! Blinky 1.5 second");
  34.   for (int i=0;i<15;i++) {
  35.     digitalWrite(LED_EXTERNAL, digitalRead(LED_EXTERNAL) ? LOW : HIGH);
  36.     delay(100);
  37.   }
  38.  
  39.   // register the receive callback
  40.   LoRa.onReceive(onReceive);
  41.  
  42.   // put the radio into receive mode
  43.   LoRa.receive();
  44. }
  45.  
  46. void loop() {
  47.   // do nothing
  48. }
  49.  
  50. void onReceive(int packetSize) {
  51.   // received a packet
  52.   Serial.print("Received packet '");
  53.  
  54.   // read packet
  55.   for (int i = 0; i < packetSize; i++) {
  56.     Serial.print((char)LoRa.read());
  57.   }
  58.  
  59.   // print RSSI of packet
  60.   Serial.print("' with RSSI ");
  61.   Serial.println(LoRa.packetRssi());
  62.     digitalWrite(LED_EXTERNAL, (state) ? HIGH : LOW);
  63.   state = !state;
  64.   //or   digitalWrite(LED_EXTERNAL, !digitalRead(LED_EXTERNAL));
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement