Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
439 views

Lora Esp32

This document contains code for a LoRa receiver that displays received packet data and signal strength on an OLED display. It initializes the LoRa radio module and OLED display using software SPI and I2C. When a packet is received, it reads the data and RSSI value, displays this information on the OLED, and prints it to the serial monitor. The blue LED is used to indicate reception of a packet.

Uploaded by

Lunatic Avelatto
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
439 views

Lora Esp32

This document contains code for a LoRa receiver that displays received packet data and signal strength on an OLED display. It initializes the LoRa radio module and OLED display using software SPI and I2C. When a packet is received, it reads the data and RSSI value, displays this information on the OLED, and prints it to the serial monitor. The blue LED is used to indicate reception of a packet.

Uploaded by

Lunatic Avelatto
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* Example from Sandeep Mistry

* With mods from AliExpress/LilyGo docs


* For TTGo ESP32 LoRa-OLED board
* http://www.lilygo.cn/down_view.aspx?TypeId=11&Id=78&Fid=t14:11:14
* Based on SX1276 LoRa Radio
* http://www.semtech.com/apps/product.php?pn=SX1276
* RMB 29Nov2017
*/

#include <SPI.h>
#include <LoRa.h> // https://github.com/sandeepmistry/arduino-LoRa
#include <U8g2lib.h> // https://github.com/olikraus/U8g2_Arduino
// #include <U8x8lib.h>

#define OFF 0 // For LED


#define ON 1

// SPI LoRa Radio


#define LORA_SCK 5 // GPIO5 - SX1276 SCK
#define LORA_MISO 19 // GPIO19 - SX1276 MISO
#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI
#define LORA_CS 18 // GPIO18 - SX1276 CS
#define LORA_RST 23 // GPIO14 - SX1276 RST
#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ (interrupt request)

// I2C OLED Display works with SSD1306 driver


#define OLED_SDA 21
#define OLED_SCL 22
#define OLED_RST 23

/* 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
*/

// UNCOMMENT one of the constructor lines below


//U8X8_SSD1306_128X64_NONAME_SW_I2C Display(/* clock=*/ OLED_SCL, /* data=*/
OLED_SDA, /* reset=*/ OLED_RST); // Unbuffered, basic graphics, software I2C
//U8G2_SSD1306_128X64_NONAME_1_SW_I2C Display(U8G2_R0, /* clock=*/ OLED_SCL, /*
data=*/ OLED_SDA, /* reset=*/ OLED_RST); // Page buffer, SW I2C
U8G2_SSD1306_128X64_NONAME_F_SW_I2C Display(U8G2_R0, /* clock=*/ OLED_SCL, /*
data=*/ OLED_SDA, /* reset=*/ U8X8_PIN_NONE); // Full framebuffer, SW I2C

const int blueLED = 25; //25 for v.16 oled, 14 for ttgo beam gps

String rssi = "";


String packet = "";

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);

// Very important for SPI pin configuration!


SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);

// Very important for LoRa Radio pin configuration!


LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);

pinMode(blueLED, OUTPUT); // For LED feedback

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

Serial.print("Received packet '");

digitalWrite(blueLED, ON); // Turn blue LED on

// 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();

digitalWrite(blueLED, OFF); // Turn blue LED off

Serial.println(packet + "' with RSSI " + rssi);


}
}

You might also like