Skip to content

Commit 1d53de9

Browse files
authored
Add fixed circuitpython code for feather board + readme note (#66)
* add fixed circuitpython code for feather board + readme note * fix lint + spurious backslash * move feather exception code into own directory
1 parent cfac1aa commit 1d53de9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ On the board you want to receive data, make sure you have CircuitPython installe
8383

8484
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.
8585

86+
> [!NOTE]
87+
> If you're targeting a Feather rather than a flight controller board, then
88+
> copy from ```circuit-python-lora-passthrough-feather``` instead.
89+
8690
```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.
8791

8892
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:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
boot.py
3+
4+
This file helps to use an RP2350 CircuitPython environment as a passthrough for
5+
interacting with the radio and F Prime GDS. The usb_cdc.enable() function creates a
6+
USB serial endpoint that the GDS can connect to to receive all the data that is
7+
streamed out. The function has to be called in boot.py before the USB device is enabled.
8+
"""
9+
10+
import usb_cdc
11+
12+
usb_cdc.enable(console=True, data=True)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
CircuitPython Feather RP2350 LoRa Radio forwarder
3+
4+
This code will forward any received LoRa packets to the serial console (sys.stdout). It cycles through neo pixel colors
5+
to indicate packet reception.
6+
"""
7+
8+
# import time
9+
10+
import adafruit_rfm9x
11+
import board
12+
import digitalio
13+
import usb_cdc
14+
15+
# Radio constants
16+
RADIO_FREQ_MHZ = 437.4
17+
CS = digitalio.DigitalInOut(board.RFM9X_CS)
18+
RESET = digitalio.DigitalInOut(board.RFM9X_RST)
19+
20+
rfm95 = adafruit_rfm9x.RFM9x(board.SPI(), CS, RESET, RADIO_FREQ_MHZ)
21+
rfm95.spreading_factor = 8
22+
rfm95.signal_bandwidth = 125000
23+
rfm95.coding_rate = 5
24+
rfm95.preamble_length = 8
25+
# time_start = time.time()
26+
packet_count = 0
27+
print("[INFO] LoRa Receiver receiving packets")
28+
while True:
29+
# Look for a new packet - wait up to 2 seconds:
30+
packet = rfm95.receive(timeout=2.0)
31+
# If no packet was received during the timeout then None is returned.
32+
if packet is not None:
33+
usb_cdc.data.write(packet)
34+
packet_count += 1
35+
# time_delta = time.time() - time_start
36+
# if time_delta > 10:
37+
# print(f"[INFO] Packets received: {packet_count}")
38+
# time_start = time.time()
39+
data = usb_cdc.data.read(usb_cdc.data.in_waiting)
40+
if len(data) > 0:
41+
rfm95.send(data)

0 commit comments

Comments
 (0)