//modified lora library by Sandeep Mistry for TTGO ESP32 Lora
// lora Sender
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
// GPIO5 -- SX1278's SCK
// GPIO19 -- SX1278's MISO
// GPIO27 -- SX1278's MOSI
// GPIO18 -- SX1278's CS
// GPIO14 -- SX1278's RESET
// GPIO26 -- SX1278's IRQ(Interrupt Request)
#define SS 18
#define RST 14
#define DI0 26
#define BAND 433E6
int counter = 0;
int state = 0;
// Initialize the OLED display using Wire library
SSD1306Wire display(0x3c, OLED_SDA, OLED_SCL); // OLED_SDA=4, OLED_SCL=15
void setup() {
// START aktivas Oled
pinMode(LED_BUILTIN, OUTPUT);
pinMode(16, OUTPUT);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high、
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
// clear the display
display.clear();
// aktivasi Oled END
pinMode(25, OUTPUT); //Send success, LED will bright 1 second
Serial.begin(115200);
while (!Serial); //If just the the basic function, must connect to a computer
SPI.begin(5, 19, 27, 18);
LoRa.setPins(SS, RST, DI0);
// Serial.println("LoRa Sender");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initial OK!");
}
void loop() {
display.setFont(ArialMT_Plain_24);
display.drawString(0, 0, "HwThinker");
display.display();
display.setFont(ArialMT_Plain_16);
display.drawString(0, 24, "Lora Sender");
display.display();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 45, "Sending packet : " + String(counter));
display.display();
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(25, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
delay(3000);
digitalWrite(LED_BUILTIN, (state) ? HIGH : LOW);
state = !state;
//or digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
display.clear();
}
Comments