Repository navigation
uCompute — LORA Module
The uCompute LoRa RFM95W Extension Module adds long-range, low-power sub-GHz radio communication to the uCompute ecosystem. To make hardware diagnostics and field deployment as seamless as possible, this page hosts a dual-mode firmware tool capable of performing bidirectional data transmission integrity testing and real-time spectrum scanning.
LoRa operates within the ISM (Industrial, Scientific, and Medical) bands, which are free to use without an individual license but are strictly regulated by human laws and regional authorities. When building or purchasing a uCompute LoRa module, you must pay close attention to your local legal restrictions:
- Regional Frequency Compliance: RFM95W modules are tuned to specific frequency bounds. For instance, 868 MHz is designated for Europe (CE), whereas 915 MHz is mandatory for North America (FCC). Using the wrong module or transmitting outside your regional allocation is illegal.
- Duty Cycle Limits: Free bands come with operational limitations to prevent channel congestion. In many regions (such as Europe), radio regulations impose a strict 1% duty cycle limit per device, meaning a single node can only transmit for a maximum of 36 seconds per hour.
For a thorough, comprehensive introduction to LoRa physics, link budgets, and regional legal constraints, we highly recommend checking out the educational work of Andreas Spiess (The Guy with the Swiss Accent).
Specifically, his tutorial video LoRa / LoRaWAN De-Mystified provides an incredible breakdown of how narrow bandwidth allows low-power devices to bridge extreme distances, alongside a real-world look at duty cycle regulations.
The diagnostic firmware relies on the excellent open-source library u-lora, an efficient MicroPython port of raspi-lora designed specifically for RFM95 radio transceivers. We would like to give full credit to its author, Martyn Wheeler (GitHub: @martynwheeler), for maintaining and sharing this lightweight communication stack, which makes handling low-level SPI radio registers and hardware interrupts straightforward on MicroPython architectures.
A defining architectural feature of the uCompute expansion ecosystem is its standardized rear dual-row communication socket. The mechanical and electrical footprint of the LoRa add-on board is entirely based on the W5500 Ethernet module pinout standard.
By mapping the RFM95W signals directly onto the hardware lines traditionally reserved for the W5500 chip, uCompute allows makers to swap networking technologies on the fly without any hardware modifications. Consequently, the source code retains the naming convention of the master bus lines (_W5500_...), acting as a drop-in physical layout abstraction layer.
- SPI1 SCK: GPIO 14
- SPI1 MOSI: GPIO 15
- SPI1 MISO: GPIO 12
-
NSS (Chip Select): GPIO 8 (
_W5500_Select) -
Reset: GPIO 10 (
_W5500_Reset) -
DIO0 (Interrupt): GPIO 9 (
_W5500_INT)
The MicroPython firmware structure operates as a standalone handheld testing suite, leveraging the onboard analog resistor ladder keys (Read_Keys()) and the SSD1306 I2C OLED display driver. Upon booting past the splash screen, users can select between two essential radio troubleshooting scripts:
This test establishes a structured Client/Server (TX/RX) validation environment using explicit hardware Handshaking.
- Role Allocation: Configurable directly on the device using physical inputs (Up for Transmitter, Down for Receiver).
-
Packet Verification: Data transmissions use absolute targeting headers and mandate Explicit Acknowledgment (
acks=True). -
Live Metrics: The Receiver role utilizes an object-oriented rolling FIFO terminal class (
OLEDTerminal) to log packet origins along with real-time RSSI (Received Signal Strength Indicator) and SNR (Signal-to-Noise Ratio) figures.
A high-speed, pass-through visual frequency monitoring utility designed to analyze channel pollution and chart radio-frequency environments.
-
Low-Level Register Interaction: Rather than calling high-level library functions, the script directly manipulates the RFM95W synthesizer registers (
REG_06_FRF_MSB,REG_07_FRF_MID,REG_08_FRF_LSB) to step through the spectrum with precise channel spacing. - Visual Spectrograph Output: Translates raw RSSI numbers into a 32-channel visual histogram on the OLED display. Ambient noise floor levels generate minor bouncing markers at the base, while active transmissions generate sudden, distinctive high-amplitude columns.
-
Non-Blocking Escape Architecture: Loop execution structures periodically parse key inputs, allowing
AnyKeybutton events to safely interrupt operations and fall back to the root system menu seamlessly.
Ensure you have the required external helper modules (ulora.py and ssd1306.py) loaded inside your flash runtime directory before uploading this script.
import utime
from machine import Pin, SPI, I2C, ADC
from ulora import LoRa, ModemConfig
from ssd1306 import SSD1306_I2C
# Configuration des Ports uCompute V1.x ou uCompute2
_SPI1_SCK = 14
_SPI1_MOSI = 15
_SPI1_MISO = 12
_W5500_Select = 8
_W5500_Reset = 10
_W5500_INT = 9
_I2C_SDA = 20
_I2C_SCL = 21
_System_Led = 25
_Boutons = 26 # Entrée analogique ADC0 (GP26)
# Initialisation des IOs
System_LED = Pin(_System_Led, Pin.OUT)
BTN_Analogue = machine.ADC(_Boutons)
# Initialisation du bus I2C
i2c = I2C(0, sda=Pin(_I2C_SDA), scl=Pin(_I2C_SCL), freq=200000)
screen_width = 128
screen_height = 64
oled_driver = SSD1306_I2C(screen_width, screen_height, i2c)
# ------------------------------------------------------------------------------
# OBJECT-ORIENTED OLED TERMINAL CLASS (FIFO Scroller)
# ------------------------------------------------------------------------------
class OLEDTerminal:
def __init__(self, oled, width=128, height=64, line_height=10):
self.oled = oled
self.width = width
self.height = height
self.line_height = line_height
self.max_lines = int(height / line_height)
self.lines = []
def print_line(self, texte):
clean_text = texte[:15]
if len(self.lines) < self.max_lines:
self.lines.append(clean_text)
else:
self.lines.pop(0)
self.lines.append(clean_text)
self.render()
def render(self):
self.oled.fill(0)
for i, line in enumerate(self.lines):
self.oled.text(line, 0, i * self.line_height)
self.oled.show()
def clear(self):
self.lines = []
self.oled.fill(0)
self.oled.show()
terminal = OLEDTerminal(oled_driver, screen_width, screen_height)
# ------------------------------------------------------------------------------
# INPUT NAVIGATION & DEBOUNCING LAYERS
# ------------------------------------------------------------------------------
def WaitInputKey():
while BTN_Analogue.read_u16() > 64000:
utime.sleep(0.05)
while BTN_Analogue.read_u16() <= 64000:
utime.sleep(0.01)
def Read_Keys():
_read = BTN_Analogue.read_u16()
if _read < 7000:
return 'down'
elif _read < 12000:
return 'select'
elif _read < 16000:
return 'up'
return 'null'
# ------------------------------------------------------------------------------
# BIDIRECTIONAL LINK TEST (COMMUNICATION MODE)
# ------------------------------------------------------------------------------
def CommTest():
ROLE = None
oled_driver.fill(0)
oled_driver.text("-- Lora Test --", 0, 0)
oled_driver.text("Choose Role:", 0, 40)
oled_driver.text("(Tx) (Rx)", 0, 55)
oled_driver.show()
utime.sleep(0.1)
while ROLE is None:
button = Read_Keys()
if button == "up":
ROLE = "TX"
THIS_ADDRESS = 1
TARGET_ADDRESS = 2
elif button == "down":
ROLE = "RX"
THIS_ADDRESS = 2
TARGET_ADDRESS = 1
utime.sleep(0.05)
debounce()
terminal.print_line(f"Role: {ROLE}")
terminal.print_line(f"My Addr: {THIS_ADDRESS}")
utime.sleep(1.0)
_SPI_LORA = (1, _SPI1_SCK, _SPI1_MOSI, _SPI1_MISO)
lora = LoRa(_SPI_LORA, _W5500_INT, THIS_ADDRESS, _W5500_Select, reset_pin=_W5500_Reset, freq=915.0, tx_power=14, modem_config=ModemConfig.Bw31_25Cr48Sf512, acks=True)
if ROLE == "RX":
def on_recv(payload):
try:
msg = payload.message.decode('utf-8')
except:
msg = str(payload.message)
terminal.print_line(f"Rx from: {payload.header_from}")
terminal.print_line(f"Msg: {msg}")
terminal.print_line(f"RSSI:{int(payload.rssi)} SNR:{int(payload.snr)}")
lora.on_recv = on_recv
lora.set_mode_rx()
terminal.print_line("Listening...")
terminal.print_line("AnyKey to exit")
while True:
if Read_Keys() != 'null':
return
utime.sleep(0.1)
elif ROLE == "TX":
terminal.print_line("Mode Tx Ready")
counter = 0
while True:
counter += 1
message = f"Hello-{counter}"
terminal.print_line(f"Sending: {counter}")
success = lora.send_to_wait(message, TARGET_ADDRESS)
if success:
terminal.print_line("ACK: OK")
else:
terminal.print_line("ACK: FAILED")
for _ in range(50):
if Read_Keys() != 'null':
return
utime.sleep(0.1)
# ------------------------------------------------------------------------------
# GRAPHICAL RF SPECTRUM SCANNER (RSSI MODE)
# ------------------------------------------------------------------------------
def RSSITest():
_SPI_LORA = (1, _SPI1_SCK, _SPI1_MOSI, _SPI1_MISO)
lora = LoRa(_SPI_LORA, _W5500_INT, 0, _W5500_Select, reset_pin=_W5500_Reset, freq=914.0, acks=False)
# Scanner Sweep Spectrum Tuning Configurations
freq_start = 914.0
freq_end = 916.0
num_steps = 32 # Canals boundary limit mapping 4px bars across 128px screen width
step = (freq_end - freq_start) / num_steps
bar_width = int(screen_width / num_steps)
# Cache dataset to store active noise floor readings
rssi_values = [-157] * num_steps
while True:
freq = freq_start
for i in range(num_steps):
# Sortie immédiate si l'utilisateur appuie sur une touche
if Read_Keys() != 'null':
debounce()
return
# Compute and inject direct synthesizer parameters (FSTEP = FXOSC / 524288)
frf = int((freq * 1000000.0) / 61.03515625)
lora._spi_write(0x06, (frf >> 16) & 0xff)
lora._spi_write(0x07, (frf >> 8) & 0xff)
lora._spi_write(0x08, frf & 0xff)
lora.set_mode_rx()
utime.sleep(0.02) # Temps de stabilisation réduit pour accélérer le balayage
# Lecture du RSSI
rssi_raw = lora._spi_read(0x1B)
rssi = int(rssi_raw - 157)
rssi_values[i] = rssi
freq += step
# --- DESSIN DU GRAPHIQUE SUR L'OLED ---
oled_driver.fill(0)
# Ligne de repère textuelle en haut
oled_driver.text(f"Scan {freq_start:.1f}-{freq_end:.1f} MHz", 0, 0)
oled_driver.line(0, 10, screen_width, 10, 1)
# Dessin des barres de spectre
for i in range(num_steps):
val = rssi_values[i]
# Mappage de la valeur RSSI (-140 à -40 dBm) sur la hauteur de l'écran (0 à 50 pixels)
# Plus le signal est fort (proche de -40), plus la barre est haute
if val < -140: val = -140
if val > -40: val = -40
bar_height = int(((val + 140) / 100) * 50)
# Coordonnées de la barre
x = i * bar_width
y = screen_height - bar_height
# Dessine un rectangle plein pour chaque canal radio
oled_driver.fill_rect(x, y, bar_width - 1, bar_height, 1)
oled_driver.show()
utime.sleep(0.1)
#------------------------------------------------------------------------------
#CORE UI LAYOUT ROUTINES & ROOT MENU
#------------------------------------------------------------------------------
def splashScreen():
oled_driver.fill(0)
oled_driver.text("uCompute", 30, 7)
oled_driver.text("Lora RFM95W", 20, 20)
oled_driver.text("Testing Tools", 12, 30)
oled_driver.text("-Press key-", 20, 55)
oled_driver.rect(0, 0, screen_width, screen_height-20, 1)
oled_driver.show()
def MainMenu():
while True:
oled_driver.fill(0)
oled_driver.text("uCompute", 30, 0)
oled_driver.text("Lora RFM95W", 20, 10)
oled_driver.text("Choose TEST", 15, 40)
oled_driver.line(0, 50, 128, 50, 1)
oled_driver.text("RSSI COM", 0, 55)
oled_driver.show()
debounce()
while True:
button = Read_Keys()
if button == "up":
oled_driver.fill(0)
oled_driver.show()
RSSITest()
break
elif button == "down":
terminal.clear()
CommTest()
break
utime.sleep(0.05)
# Démarrage
splashScreen()
WaitInputKey()
MainMenu()