hwthinker

T-BEAM_Lora-915MHz_Receiver

Feb 11th, 2019 (edited)
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //modified lora library by Sandeep Mistry for TTGO T-BEAM LORA ESP32 GPS
  2. // lora receiverCallBack modified by HwThinker
  3.  
  4. #include <SPI.h>
  5. #include <LoRa.h>
  6.  
  7. #define SCK     5    // GPIO5  -- lora SCK
  8. #define MISO    19   // GPIO19 -- lora MISO
  9. #define MOSI    27   // GPIO27 -- lora MOSI
  10. #define SS      18   // GPIO18 -- lora CS
  11. #define RST     23   // GPIO23 -- RESET
  12. #define DI0     26   // GPIO26 -- IRQ(Interrupt Request)
  13. #define BAND    915E6 // 915MHz modifikasi Frekuensi Band lora sesuai dengan Lora anda
  14. //#define BAND    433E6 //433MHz  modifikasi Frekuensi Band lora sesuai dengan Lora anda
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   while (!Serial);
  19.   SPI.begin(SCK, MISO, MOSI, SS);
  20.   LoRa.setPins(SS, RST, DI0);
  21.  
  22.  
  23.   Serial.println("LoRa Receiver Callback");
  24.  
  25.   if (!LoRa.begin(BAND)) {
  26.     Serial.println("Starting LoRa failed!");
  27.     while (1);
  28.   }
  29.  
  30.   // register the receive callback
  31.   LoRa.onReceive(onReceive);
  32.  
  33.   // put the radio into receive mode
  34.   LoRa.receive();
  35. }
  36.  
  37. void loop() {
  38.   // do nothing
  39. }
  40.  
  41. void onReceive(int packetSize) {
  42.   // received a packet
  43.   Serial.print("Received packet '");
  44.  
  45.   // read packet
  46.   for (int i = 0; i < packetSize; i++) {
  47.     Serial.print((char)LoRa.read());
  48.   }
  49.  
  50.   // print RSSI of packet
  51.   Serial.print("' with RSSI ");
  52.   Serial.println(LoRa.packetRssi());
  53. }
Add Comment
Please, Sign In to add comment