Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ On the board you want to receive data, make sure you have CircuitPython installe

Once you have CircuitPython running, upload the files from the ```circuit-python-lora-passthrough``` folder in this repo. Make sure to overwrite any existing ```boot.py``` and ```code.py``` files on your CircuitPython board with the ones from this folder.

> [!NOTE]
> If you're targeting a Feather rather than a flight controller board, then
> copy `feather_code.py`

```boot.py``` enables both virtual serial ports that the device presents over USB. This allows you to use one for the console and one for data. ```code.py``` acts as a LoRa radio forwarder over USB serial: The console port is used for logging and debugging, and is the first serial port that appears when the board is connected. The data port is used for actual data transfer, and is the second serial port.

1. Open the console port on your computer. This is the first serial port that opens when you plug in the circuitpython board. It should start by printing:
Expand Down
41 changes: 41 additions & 0 deletions circuit-python-lora-passthrough/feather_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
CircuitPython Feather RP2350 LoRa Radio forwarder

This code will forward any received LoRa packets to the serial console (sys.stdout). It cycles through neo pixel colors
to indicate packet reception.
"""

# import time

import adafruit_rfm9x
import board
import digitalio
import usb_cdc

# Radio constants
RADIO_FREQ_MHZ = 437.4
CS = digitalio.DigitalInOut(board.RFM9X_CS)
RESET = digitalio.DigitalInOut(board.RFM9X_RST)

rfm95 = adafruit_rfm9x.RFM9x(board.SPI(), CS, RESET, RADIO_FREQ_MHZ)
rfm95.spreading_factor = 8
rfm95.signal_bandwidth = 125000
rfm95.coding_rate = 5
rfm95.preamble_length = 8
# time_start = time.time()
packet_count = 0
print("[INFO] LoRa Receiver receiving packets")
while True:
# Look for a new packet - wait up to 2 seconds:
packet = rfm95.receive(timeout=2.0)
# If no packet was received during the timeout then None is returned.
if packet is not None:
usb_cdc.data.write(packet)
packet_count += 1
# time_delta = time.time() - time_start
# if time_delta > 10:
# print(f"[INFO] Packets received: {packet_count}")
# time_start = time.time()
data = usb_cdc.data.read(usb_cdc.data.in_waiting)
if len(data) > 0:
rfm95.send(data)