Hi there,
So I got the Open Receiver code up on the Dev Expansion Board, Displays “Beacon Message” on first line and is sent in // REV 5.5b - SX1262 Beacon Sender with LED + Button + Power Modes // Posted below.
Press the button to send message with different power levels…
on the Sender (beacon) intervals of 2 dB Transmit power. Watch display on Open receiver and note the RSSI & SNR .
(next experiment will be a press button on each end to change modes.)
OPEN Receiver:
// REV 5.6n - SX1262 Open Receiver with OLED Display
// Board: ESP32-S3 with SX1262 LoRa Module + OLED (XIAO Expansion Board)
// Receives LoRa messages and displays:
// 1) Beacon Message (1st line)
// 2) RSSI and SNR values (formatted & centered)
// 3) Blinks onboard LED (GPIO 48) on message reception
// 4) Serial output stays consistent with previous 5.5b version
#include <RadioLib.h>
#include <Wire.h>
#include <U8g2lib.h>
// SX1262 Module Pins: NSS, DIO1, RST, BUSY
SX1262 radio = new Module(41, 39, 42, 40);
// OLED: I2C (128x64), flipped orientation (USB on right side)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0, U8X8_PIN_NONE);
// LED for RX activity
const int LED_PIN = 48;
// Last received values for change detection
float lastRSSI = 0;
float lastSNR = 0;
String lastMsg = "";
// Thresholds for display update
const float RSSI_THRESHOLD = 0.25;
const float SNR_THRESHOLD = 0.25;
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(115200);
delay(500);
Serial.println();
Serial.println(F("// REV 5.6n - SX1262 Open Receiver with OLED Display"));
Serial.println(F("// Board: ESP32-S3 with SX1262 LoRa Module + OLED"));
Serial.print(F("Initializing SX1262 LoRa radio... "));
if (radio.begin() != RADIOLIB_ERR_NONE) {
Serial.println(F("FAILED!"));
while (true);
}
Serial.println(F("SUCCESS!"));
Serial.println(F("Listening for LoRa messages..."));
// LoRa radio config
radio.setOutputPower(22);
radio.setSpreadingFactor(7);
radio.setBandwidth(125.0);
radio.setCodingRate(5);
// OLED startup screen
display.begin();
display.setFlipMode(1); // Flip vertically for correct orientation
display.clearBuffer();
display.setFont(u8g2_font_6x12_tf);
display.setCursor(0, 12);
display.print("SX1262 Open Receiver");
display.setCursor(0, 28);
display.print("XIAO S3 + OLED");
display.setCursor(0, 44);
display.print("REV 5.6n");
display.sendBuffer();
delay(2000);
// Initial Listening Screen
display.clearBuffer();
display.setCursor(0, 12);
display.print("Listening...");
display.sendBuffer();
}
void loop() {
String msg;
int state = radio.receive(msg);
if (state == RADIOLIB_ERR_NONE) {
float rssi = radio.getRSSI();
float snr = radio.getSNR();
bool updated = false;
if (msg != lastMsg) {
Serial.print("Received: ");
Serial.println(msg);
lastMsg = msg;
updated = true;
}
if (abs(rssi - lastRSSI) > RSSI_THRESHOLD || abs(snr - lastSNR) > SNR_THRESHOLD) {
Serial.print(" RSSI: ");
Serial.print(rssi, 2);
Serial.print(" dBm\tSNR: ");
Serial.print(snr, 2);
Serial.println(" dB");
lastRSSI = rssi;
lastSNR = snr;
updated = true;
} else {
Serial.print(".");
}
if (updated) {
display.clearBuffer();
display.setFont(u8g2_font_6x12_tf);
display.setCursor(0, 12);
display.print(lastMsg); // Line 1
display.setCursor(0, 28);
display.print(" RSSI - SNR"); // Line 3
display.setFont(u8g2_font_7x13B_tf);
display.setCursor(10, 44);
display.printf("%.0f", lastRSSI);
display.setCursor(74, 44);
display.printf("%.2f", lastSNR);
display.setFont(u8g2_font_6x12_tf);
display.setCursor(15, 60);
display.print("dBm");
display.setCursor(86, 60);
display.print("dB");
display.sendBuffer();
}
digitalWrite(LED_PIN, HIGH);
delay(30);
digitalWrite(LED_PIN, LOW);
}
}
Serial output for receiver ;
// REV 5.6n - SX1262 Open Receiver with OLED Display
// Board: ESP32-S3 with SX1262 LoRa Module + OLED
Initializing SX1262 LoRa radio... SUCCESS!
Listening for LoRa messages...
Received: Seeed Studio
RSSI: -125.00 dBm SNR: -9.25 dB
// REV 5.6n - SX1262 Open Receiver with OLED Display
// Board: ESP32-S3 with SX1262 LoRa Module + OLED
Initializing SX1262 LoRa radio... SUCCESS!
Listening for LoRa messages...
Received: Seeed Studio
RSSI: -125.00 dBm SNR: -8.75 dB
. RSSI: -125.00 dBm SNR: -9.25 dB
RSSI: -125.00 dBm SNR: -8.75 dB
. RSSI: -125.00 dBm SNR: -9.25 dB
... RSSI: -125.00 dBm SNR: -8.50 dB
RSSI: -125.00 dBm SNR: -9.25 dB
RSSI: -126.00 dBm SNR: -9.50 dB
. RSSI: -125.00 dBm SNR: -9.25 dB
.. RSSI: -126.00 dBm SNR: -9.50 dB
RSSI: -125.00 dBm SNR: -9.25 dB
RSSI: -126.00 dBm SNR: -9.50 dB
RSSI: -126.00 dBm SNR: -10.50 dB
RSSI: -125.00 dBm SNR: -8.75 dB
RSSI: -126.00 dBm SNR: -9.75 dB
. RSSI: -125.00 dBm SNR: -8.50 dB
RSSI: -125.00 dBm SNR: -9.00 dB
.
RSSI: -115.00 dBm SNR: 1.25 dB
RSSI: -115.00 dBm SNR: 1.75 dB
RSSI: -115.00 dBm SNR: 1.25 dB
RSSI: -113.00 dBm SNR: 3.50 dB
RSSI: -117.00 dBm SNR: -0.50 dB
RSSI: -114.00 dBm SNR: 2.00 dB
..... RSSI: -114.00 dBm SNR: 2.50 dB
RSSI: -114.00 dBm SNR: 2.00 dB
.. RSSI: -115.00 dBm SNR: 1.25 dB
RSSI: -114.00 dBm SNR: 1.75 dB
RSSI: -116.00 dBm SNR: 0.25 dB
RSSI: -114.00 dBm SNR: 2.25 dB
..... RSSI: -114.00 dBm SNR: 1.75 dB
RSSI: -115.00 dBm SNR: 1.25 dB
RSSI: -114.00 dBm SNR: 2.00 dB
..... RSSI: -113.00 dBm SNR: 2.50 dB
RSSI: -114.00 dBm SNR: 2.00 dB
.. RSSI: -114.00 dBm SNR: 2.50 dB
.. RSSI: -113.00 dBm SNR: 2.75 dB
RSSI: -114.00 dBm SNR: 2.50 dB
. RSSI: -114.00 dBm SNR: 2.00 dB
RSSI: -114.00 dBm SNR: 2.50 dB
.... RSSI: -115.00 dBm SNR: 1.00 dB
RSSI: -113.00 dBm SNR: 3.00 dB
RSSI: -110.00 dBm SNR: 5.75 dB
RSSI: -108.00 dBm SNR: 7.00 dB
............................... RSSI: -109.00 dBm SNR: 6.25 dB
RSSI: -108.00 dBm SNR: 7.25 dB
RSSI: -109.00 dBm SNR: 6.50 dB
. RSSI: -108.00 dBm SNR: 6.75 dB
. RSSI: -109.00 dBm SNR: 6.25 dB
RSSI: -108.00 dBm SNR: 7.25 dB
................ RSSI: -107.00 dBm SNR: 7.25 dB
RSSI: -109.00 dBm SNR: 6.25 dB
RSSI: -108.00 dBm SNR: 7.25 dB
.. RSSI: -108.00 dBm SNR: 6.75 dB
. RSSI: -109.00 dBm SNR: 7.00 dB
.. RSSI: -108.00 dBm SNR: 6.50 dB
. RSSI: -108.00 dBm SNR: 7.00 dB
.................
Beacon Sender…:
// REV 5.5b - SX1262 Beacon Sender with LED + Button + Power Modes
// Board: ESP32-S3 with SX1262 LoRa Module
// Sends "Seeed Studio" as beacon every 5 seconds
// LED on GPIO 48 blinks on TX
// Button on GPIO 21 cycles TX power level (2 to 22 dBm)
#include <RadioLib.h>
#define NSS 41
#define DIO1 39
#define RST 42
#define BUSY 40
#define LED_PIN 48
#define BTN_PIN 21
SX1262 radio = new Module(NSS, DIO1, RST, BUSY);
const char beaconMessage[] = "Seeed Studio";
int txPower = 22;
unsigned long lastSendTime = 0;
const unsigned long beaconInterval = 5000;
int lastButtonState = HIGH;
bool firstPrint = true;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BTN_PIN, INPUT_PULLUP);
digitalWrite(LED_PIN, LOW);
Serial.begin(115200);
delay(1000);
Serial.println();
Serial.println("// REV 5.5b - SX1262 Beacon Sender");
Serial.println("// Board: ESP32-S3 with SX1262 LoRa Module");
Serial.print("Initializing SX1262 LoRa radio... ");
if (radio.begin() != RADIOLIB_ERR_NONE) {
Serial.println("FAILED!");
while (true);
}
Serial.println("SUCCESS!");
radio.setOutputPower(txPower);
radio.setSpreadingFactor(7);
radio.setBandwidth(125.0);
radio.setCodingRate(5);
Serial.print("TX Power: ");
Serial.print(txPower);
Serial.println(" dBm");
Serial.println("Beacon message: \"Seeed Studio\"");
Serial.println("Transmitting every 5 seconds...\n");
}
void loop() {
unsigned long now = millis();
// Button handling to change TX power
int btnState = digitalRead(BTN_PIN);
if (btnState == LOW && lastButtonState == HIGH) {
txPower += 2;
if (txPower > 22) txPower = 2;
radio.setOutputPower(txPower);
Serial.print("\nTX Power changed to: ");
Serial.print(txPower);
Serial.println(" dBm");
delay(250); // debounce
}
lastButtonState = btnState;
// Send beacon every interval
if (now - lastSendTime >= beaconInterval) {
lastSendTime = now;
digitalWrite(LED_PIN, HIGH);
int state = radio.transmit(beaconMessage);
digitalWrite(LED_PIN, LOW);
if (state == RADIOLIB_ERR_NONE) {
if (firstPrint) {
Serial.print("Sent: ");
Serial.println(beaconMessage);
firstPrint = false;
} else {
Serial.print(".");
}
static int dotCount = 0;
dotCount++;
if (dotCount % 80 == 0) Serial.println();
} else {
Serial.print("Transmit failed, code ");
Serial.println(state);
}
}
}
Sender Serial Output.:
// REV 5.5b - SX1262 Beacon Sender
// Board: ESP32-S3 with SX1262 LoRa Module
Initializing SX1262 LoRa radio... SUCCESS!
TX Power: 22 dBm
Beacon message: "Seeed Studio"
Transmitting every 5 seconds...
Sent: Seeed Studio
...............................................................................
................................................................................
................................................................................
.......................................................................
TX Power changed to: 2 dBm
.........
.
TX Power changed to: 4 dBm
.....
TX Power changed to: 6 dBm
...
TX Power changed to: 8 dBm
..........
TX Power changed to: 10 dBm
....
TX Power changed to: 12 dBm
.............................................
TX Power changed to: 14 dBm
TX Power changed to: 16 dBm
.
TX Power changed to: 18 dBm
TX Power changed to: 20 dBm
TX Power changed to: 22 dBm
...
TX Power changed to: 2 dBm
........
................................................................................
........................................................
// REV 5.5b - SX1262 Beacon Sender
// Board: ESP32-S3 with SX1262 LoRa Module
Initializing SX1262 LoRa radio... SUCCESS!
TX Power: 22 dBm
Beacon message: "Seeed Studio"
Transmitting every 5 seconds...
Sent: Seeed Studio
...............................................................................
...................................
Starts at 22 dBm , press button goes to 2,4,6,8, etc…
HTH
GL PJ
Like, Share and subscribe… LOL