Advertisement
hwthinker

LoraReceiver-433MHz

Jan 30th, 2019
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //modified lora library by Sandeep Mistry for TTGO ESP32 Lora
  2. // lora receiver modified by HwThinker
  3.  
  4. #include <SPI.h>
  5. #include <LoRa.h>
  6.  
  7. // GPIO5  -- SX1278's SCK
  8. // GPIO19 -- SX1278's MISO
  9. // GPIO27 -- SX1278's MOSI
  10. // GPIO18 -- SX1278's CS
  11. // GPIO14 -- SX1278's RESET
  12. // GPIO26 -- SX1278's IRQ(Interrupt Request)
  13.  
  14. #define SS      18
  15. #define RST     14
  16. #define DI0     26
  17. #define BAND    433E6
  18.  
  19. void setup() {
  20.   Serial.begin(115200);
  21.   while (!Serial); //if just the the basic function, must connect to a computer
  22.   delay(1000);
  23.  
  24.   Serial.println("LoRa Receiver");
  25.  
  26.   SPI.begin(5,19,27,18);
  27.   LoRa.setPins(SS,RST,DI0);
  28.  
  29.   if (!LoRa.begin(BAND)) {
  30.     Serial.println("Starting LoRa failed!");
  31.     while (1);
  32.   }
  33. }
  34.  
  35. void loop() {
  36.   // try to parse packet
  37.   int packetSize = LoRa.parsePacket();
  38.   if (packetSize) {
  39. // received a packet
  40.     Serial.print("Received packet '");
  41.  
  42.     // read packet
  43.     while (LoRa.available()) {
  44.       Serial.print((char)LoRa.read());
  45.     }
  46.  
  47.     // print RSSI of packet
  48.     Serial.print("' with RSSI ");
  49.     Serial.println(LoRa.packetRssi());
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement