Advertisement
hwthinker

Lora32 Sender OLED-915MHz_V2.1_1.6

Feb 4th, 2019 (edited)
503
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 V2.1-1.6
  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     12   // GPIO14 -- RESET (If Lora does not work, replace it with GPIO14)
  14. #define DI0     26   // GPIO26 -- IRQ(Interrupt Request)
  15. #define BAND    915E6
  16.  
  17. //replace default pin  OLED_SDA=4, OLED_SCL=15 with  OLED_SDA=21, OLED_SCL=22
  18. #define OLED_SDA 21
  19. #define OLED_SCL 22
  20. #define OLED_RST 23   //try this, if problem change to 14 or 16
  21.  
  22. #define LED_BUILTIN 25
  23.  
  24. int counter = 0;
  25. int state = 0;
  26.  
  27. // Initialize the OLED display using Wire library
  28. SSD1306Wire  display(0x3c, OLED_SDA, OLED_SCL); // OLED_SDA=4, OLED_SCL=15
  29.  
  30. void setup() {
  31.   // START  Oled ********
  32.   pinMode(LED_BUILTIN, OUTPUT);
  33.   pinMode(OLED_RST, OUTPUT);
  34.   digitalWrite(OLED_RST, LOW);    // set GPIO16 low to reset OLED
  35.   delay(50);
  36.   digitalWrite(OLED_RST, HIGH); // while OLED is running, must set GPIO16 in high、
  37.  
  38.   // Initialising the UI will init the display too.
  39.   display.init();
  40.   display.flipScreenVertically();
  41.   display.setFont(ArialMT_Plain_10);
  42.   // clear the display
  43.   display.clear();
  44.   //  END Oled ********
  45.  
  46.   Serial.begin(115200);
  47.   while (!Serial); //If just the the basic function, must connect to a computer
  48.  
  49.   SPI.begin(SCK, MISO, MOSI, SS);
  50.   LoRa.setPins(SS, RST, DI0);
  51.   Serial.println("LoRa Sender");
  52.  
  53.   if (!LoRa.begin(BAND)) {
  54.     Serial.println("Starting LoRa failed!");
  55.     while (1);
  56.   }
  57.   Serial.println("LoRa Initial OK!");
  58. }
  59.  
  60. void loop() {
  61.   display.setFont(ArialMT_Plain_24);
  62.   display.drawString(0, 0, "HwThinker");
  63.   display.display();
  64.  
  65.   display.setFont(ArialMT_Plain_16);
  66.   display.drawString(0, 24, "Lora Sender");
  67.   display.display();
  68.  
  69.   display.setTextAlignment(TEXT_ALIGN_LEFT);
  70.   display.setFont(ArialMT_Plain_10);
  71.   display.drawString(0, 45, "Sending packet : " + String(counter));
  72.   display.display();
  73.  
  74.   Serial.print("Sending packet: ");
  75.   Serial.println(counter);
  76.  
  77.   // send packet
  78.   LoRa.beginPacket();
  79.   LoRa.print("hello ");
  80.   LoRa.print(counter);
  81.   LoRa.endPacket();
  82.  
  83.   counter++;
  84.   delay(2200);
  85.   //  digitalWrite(LED_BUILTIN, (state) ? HIGH : LOW);
  86.   //  state = !state;
  87.   digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  88.  
  89.   display.clear();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement