Lora Esp32
Lora Esp32
#include <SPI.h>
#include <LoRa.h> // https://github.com/sandeepmistry/arduino-LoRa
#include <U8g2lib.h> // https://github.com/olikraus/U8g2_Arduino
// #include <U8x8lib.h>
/* Pick One. Hardware I2C does NOT work! This article helped:
https://robotzero.one/heltec-wifi-kit-32/
* TTGo boards similar to Heltec boards, LED_BUILTIN = 2 instead of pin 25
* Some OLED displays don't handle ACK correctly so SW I2C works better. Thank you
Olikraus!
* TTGo OLED has pin 16 reset unlike other OLED displays
*/
const int blueLED = 25; //25 for v.16 oled, 14 for ttgo beam gps
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
Display.begin();
Display.enableUTF8Print(); // enable UTF8 support for the Arduino print()
function
Display.setFont(u8g2_font_ncenB10_tr);
if (!LoRa.begin(921000000)) {
Serial.println("Starting LoRa failed!");
while (1);
}
// The larger the spreading factor the greater the range but slower data rate
// Send and receive radios need to be set the same
LoRa.setSpreadingFactor(12); // ranges from 6-12, default 7 see API docs
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
// read packet
packet = ""; // Clear packet
while (LoRa.available()) {
packet += (char)LoRa.read(); // Assemble new packet
}
rssi = LoRa.packetRssi();
// Display Info
Display.clearBuffer();
Display.setCursor(0,12); Display.print("LoRa Receiver");
Display.setCursor(0,26); Display.print("Received packet:");
Display.setCursor(0,42); Display.print(" '" + packet + "'");
Display.setCursor(0,58); Display.print("RSSI " + rssi);
Display.sendBuffer();