Advertisement
hwthinker

LoraSender_ESP32-915MHZ

Aug 28th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // lora Sender for TTGO ESP32 915 Mhz modified by HwThinker
  2. #include <SPI.h>
  3. #include <LoRa.h>
  4. #define LED_BUILTIN 2
  5.  
  6. #define SCK     5    // GPIO5  -- lora SCK
  7. #define MISO    19   // GPIO19 -- lora MISO
  8. #define MOSI    27   // GPIO27 -- lora MOSI
  9. #define SS      18   // GPIO18 -- lora CS
  10. #define RST     12   // GPIO14 -- RESET (If Lora does not work, replace it with GPIO14)
  11. #define DI0     26   // GPIO26 -- IRQ(Interrupt Request)
  12.  
  13. #define BAND    915E6
  14.  
  15. int counter = 0;
  16. int state = 0;
  17.  
  18. void setup() {
  19.   // START aktivas Oled
  20.   pinMode(LED_BUILTIN, OUTPUT);
  21.  
  22.   Serial.begin(115200);
  23.   while (!Serial); //If just the the basic function, must connect to a computer
  24.  
  25.   SPI.begin(SCK, MISO, MOSI, SS);
  26.   LoRa.setPins(SS, RST, DI0);
  27.   //  Serial.println("LoRa Sender");
  28.  
  29.   if (!LoRa.begin(BAND)) {
  30.     Serial.println("Starting LoRa failed!");
  31.     while (1);
  32.   }
  33.  
  34.  
  35.   Serial.println("LoRa Initial OK! Blinky 1.5 second");
  36.   for (int i=0;i<15;i++) {
  37.     digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? LOW : HIGH);
  38.     delay(100);
  39.   }
  40.  
  41.  
  42. }
  43.  
  44. void loop() {
  45.  
  46.   Serial.print("Sending packet: ");
  47.   Serial.println(counter);
  48.  
  49.   // send packet
  50.   LoRa.beginPacket();
  51.   LoRa.print("hello ");
  52.   LoRa.print(counter);
  53.   LoRa.endPacket();
  54.  
  55.   counter++;
  56.   digitalWrite(LED_BUILTIN, (state) ? HIGH : LOW);
  57.   delay(1000);
  58.   state = !state;
  59.   //or   digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement