Connected
LoRa receiver
Listens for LoRa radio messages and shows each one with its signal strength. LoRa carries small messages over hundreds of metres with no Wi-Fi and no SIM.
- Hard
- about 80 min
- ESP32-S3
- 6 parts
- 13 wires
- 72 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
LoRa trades speed for distance: a few bytes a second, but through walls and across a field. You need a second LoRa device to send; this pack is the listening half.
Before you start
Always fit the antenna before powering the radio: transmitting without one can destroy the module. In Vietnam, LoRa devices use 920–923 MHz; do not use a 433 MHz module. Check the rules where you live.
What you learn
Wiring an SPI radio, matching radio settings between two devices, and reading signal strength.
How it works
input
LoRa radio
decides
ESP32-S3
output
OLED 0.96 in
Powered with 5 V through the board's USB-C port.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 6 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 13
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
lora-receiver.ino
// LoRa receiver
// Listens for LoRa packets and shows each message with its signal strength.
// ALWAYS fit the antenna before powering the radio.
// Vietnam: 920-923 MHz. Check the band that is legal where you live.
// Needs RadioLib version 8 or newer.
#include <SPI.h>
#include <Wire.h>
#include <RadioLib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int PIN_LORA_SCK = 12;
const int PIN_LORA_MISO = 13;
const int PIN_LORA_MOSI = 11;
const int PIN_LORA_NSS = 10;
const int PIN_LORA_RST = 14;
const int PIN_LORA_DIO1 = 2;
const int PIN_LORA_BUSY = 21;
const int PIN_OLED_SDA = 8;
const int PIN_OLED_SCL = 9;
// The sender must use the same three settings.
const uint32_t FREQUENCY_HZ = 921400000UL; // 921.4 MHz
const uint32_t BANDWIDTH_HZ = 125000UL; // 125 kHz
const uint8_t SPREADING_FACTOR = 9;
// Ra-01SH is an SX1262. For an SX1276 module (Ra-01H) use the SX1276 class.
SX1262 radio = new Module(PIN_LORA_NSS, PIN_LORA_DIO1, PIN_LORA_RST, PIN_LORA_BUSY);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
int packets = 0;
void show(const String& top, const String& body, const String& foot) {
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.print(top);
oled.setCursor(0, 16);
oled.print(body);
oled.setCursor(0, 54);
oled.print(foot);
oled.display();
}
void setup() {
Wire.begin(PIN_OLED_SDA, PIN_OLED_SCL);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(SSD1306_WHITE);
SPI.begin(PIN_LORA_SCK, PIN_LORA_MISO, PIN_LORA_MOSI, PIN_LORA_NSS);
// The Ra-01SH runs from a plain crystal. If your module has a TCXO instead
// (the radio then fails to start), change VoltageNone to Voltage1V6.
radio.tcxoVoltage = RadioLibTCXOVoltage_t::VoltageNone;
ConfigLoRa_t config;
config.frequency = FREQUENCY_HZ;
config.bandwidth = BANDWIDTH_HZ;
config.spreadingFactor = SPREADING_FACTOR;
int state = radio.begin(config);
if (state != RADIOLIB_ERR_NONE) {
show("LoRa failed to start", "Error " + String(state), "Check the 9 wires");
while (true) delay(1000);
}
show("LoRa receiver", "Listening on " + String(FREQUENCY_HZ / 1000000.0, 1) + " MHz", "0 packets");
}
void loop() {
String message;
int state = radio.receive(message); // waits for a packet, or times out
if (state == RADIOLIB_ERR_NONE) {
packets++;
show("Packet " + String(packets), message, String(radio.getRSSI(), 0) + " dBm SNR " + String(radio.getSNR(), 1));
}
}
Libraries
- RadioLib (version 8 or newer): install it from Sketch > Include Library > Manage Libraries.
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit SSD1306: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.