Advertisement
hwthinker

LoraSenderOLED-915Mhz

Feb 3rd, 2019
521
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 Sender 915MHz
  3. // Modified by HwThinker
  4. #include <SPI.h>
  5. #include <LoRa.h>
  6. #include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
  7. #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
  8.  
  9. #define SCK     5    // GPIO5  -- lora SCK
  10. #define MISO    19   // GPIO19 -- lora MISO
  11. #define MOSI    27   // GPIO27 -- lora MOSI
  12. #define SS      18   // GPIO18 -- lora CS
  13. #define RST     14   // GPIO14/12 -- RESET (If Lora does not work, replace it with GPIO14)
  14. #define DI0     26   // GPIO26 -- IRQ(Interrupt Request)
  15. #define BAND    915E6
  16.  
  17.  
  18. //replace default pin  OLED_SDA=4, OLED_SCL=15 with  OLED_SDA=21, OLED_SCL=22
  19. #define OLED_SDA 4
  20. #define OLED_SCL 15
  21. #define OLED_RST 16
  22.  
  23. #define LED_BUILTIN 2
  24.  
  25. int counter = 0;
  26. int state = 0;
  27.  
  28. // Initialize the OLED display using Wire library
  29. SSD1306Wire  display(0x3c, OLED_SDA, OLED_SCL); // OLED_SDA=4, OLED_SCL=15
  30.  
  31. void setup() {
  32.   // START aktivas Oled
  33.   pinMode(LED_BUILTIN, OUTPUT);
  34.   pinMode(OLED_RST, OUTPUT);
  35.   digitalWrite(OLED_RST, LOW);    // set GPIO16 low to reset OLED
  36.   delay(50);
  37.   digitalWrite(OLED_RST, HIGH); // while OLED is running, must set GPIO16 in high、
  38.  
  39.   // Initialising the UI will init the display too.
  40.   display.init();
  41.   display.flipScreenVertically();
  42.   display.setFont(ArialMT_Plain_10);
  43.   // clear the display
  44.   display.clear();
  45.   // aktivasi Oled END
  46.  
  47.   pinMode(LED_BUILTIN, OUTPUT); //Send success, LED will bright 1 second
  48.  
  49.   Serial.begin(9600);
  50.   while (!Serial); //If just the the basic function, must connect to a computer
  51.   SPI.begin(SCK, MISO, MOSI, SS);
  52.   LoRa.setPins(SS, RST, DI0);
  53.   //  Serial.println("LoRa Sender");
  54.  
  55.   if (!LoRa.begin(BAND)) {
  56.     Serial.println("Starting LoRa failed!");
  57.     while (1);
  58.   }
  59.   Serial.println("LoRa Initial OK!");
  60. }
  61.  
  62. void loop() {
  63.   display.setFont(ArialMT_Plain_24);
  64.   display.drawString(0, 0, "HwThinker");
  65.   display.display();
  66.  
  67.   display.setFont(ArialMT_Plain_16);
  68.   display.drawString(0, 24, "Lora Sender");
  69.   display.display();
  70.  
  71.   display.setTextAlignment(TEXT_ALIGN_LEFT);
  72.   display.setFont(ArialMT_Plain_10);
  73.   display.drawString(0, 45, "Sending packet : " + String(counter));
  74.   display.display();
  75.  
  76.   Serial.print("Sending packet: ");
  77.   Serial.println(counter);
  78.  
  79.   // send packet
  80.   LoRa.beginPacket();
  81.   LoRa.print("hello ");
  82.   LoRa.print(counter);
  83.   LoRa.endPacket();
  84.  
  85.   counter++;
  86.   delay(2300);
  87.   //  digitalWrite(LED_BUILTIN, (state) ? HIGH : LOW);
  88.   //  state = !state;
  89.   digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  90.  
  91.   display.clear();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement