This guide assumes that you've gotten your Raspberry Pi up and running, and have CircuitPython installed.
Installing CircuitPython Libraries
We're running CircuitPython on the Raspberry Pi, installing the libraries for radio communication is simple.
To install the library for the display, enter the following into the terminal:
pip3 install adafruit-circuitpython-ssd1306
You'll also need to install the framebuf module in order to write to the display.
sudo pip3 install adafruit-circuitpython-framebuf
To install the library for the RFM9x Module, enter the following into the terminal:
sudo pip3 install adafruit-circuitpython-rfm9x
Testing the Setup
There have been a lot of steps so far - let's verify that everything is wired up and all the libraries are installed properly before moving on to sending and receiving data.
The following code is for checking if the RFM9x radio is set up for transmitting and receiving. Save the code on your Pi as rfm9x_check.py
.
# SPDX-FileCopyrightText: 2018 Brent Rubell for Adafruit Industries # # SPDX-License-Identifier: MIT """ Wiring Check, Pi Radio w/RFM9x Learn Guide: https://learn.adafruit.com/lora-and-lorawan-for-raspberry-pi Author: Brent Rubell for Adafruit Industries """ import time import busio from digitalio import DigitalInOut, Direction, Pull import board # Import the SSD1306 module. import adafruit_ssd1306 # Import the RFM9x radio module. import adafruit_rfm9x # Button A btnA = DigitalInOut(board.D5) btnA.direction = Direction.INPUT btnA.pull = Pull.UP # Button B btnB = DigitalInOut(board.D6) btnB.direction = Direction.INPUT btnB.pull = Pull.UP # Button C btnC = DigitalInOut(board.D12) btnC.direction = Direction.INPUT btnC.pull = Pull.UP # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) # 128x32 OLED Display reset_pin = DigitalInOut(board.D4) display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin) # Clear the display. display.fill(0) display.show() width = display.width height = display.height # Configure RFM9x LoRa Radio CS = DigitalInOut(board.CE1) RESET = DigitalInOut(board.D25) spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) while True: # Clear the image display.fill(0) # Attempt to set up the RFM9x Module try: rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0) display.text('RFM9x: Detected', 0, 0, 1) except RuntimeError as error: # Thrown on version mismatch display.text('RFM9x: ERROR', 0, 0, 1) print('RFM9x Error: ', error) # Check buttons if not btnA.value: # Button A Pressed display.text('Ada', width-85, height-7, 1) display.show() time.sleep(0.1) if not btnB.value: # Button B Pressed display.text('Fruit', width-75, height-7, 1) display.show() time.sleep(0.1) if not btnC.value: # Button C Pressed display.text('Radio', width-65, height-7, 1) display.show() time.sleep(0.1) display.show() time.sleep(0.1)
To use the code, enter the following in your terminal:
python3 rfm9x_check.py
You'll also want to download the font file, font5x8.bin
, and copy it into the same directory as the script:
Then, let's check the setup:
If the RFM9x is detected, the OLED will display Detected!
You can test the buttons by pressing them and watching the display for changes.
If the wiring of the radio module is incorrect - the display will show ERROR. Check over your wiring on the Wiring Page and re-run the test. You may also need to ensure the correct CircuitPython library is installed for the module.
If the OLED does not turn on - first check that it is wired correctly. Then, make sure you enabled I2C from raspi-config
and installed the required libraries (adafruit-circuitpython-framebuf
and adafruit-circuitpython-ssd1306
).
Install the Single Channel Pi Gateway
WiringPi is PRE-INSTALLED with standard Raspbian systems. To check if it is pre-installed on your system, run:
gpio -v
If you get something, then you have it already installed. Otherwise, install WiringPi by running:
sudo apt-get install wiringpi
Then, clone the packet forwarder repository
git clone https://github.com/adafruit/single_chan_pkt_fwd.git
Navigate into the packet forwarder directory
cd single_chan_pkt_fwd/
and compile the code for the gateway
sudo make all
You'll also want to download the font file, font5x8.bin
, and copy it into the same directory as the script:
If you are using a Raspberry Pi ZERO, you will need to change a value within the configuration file. Using a text editor, open the global_conf.json
file. Replace "is_pi_zero": false
with "is_pi_zero": true
. Your configuration file should look like the following.
{ "SX127x_conf": { "freq": 905100000, "spread_factor": 7, "pin_nss": 11, "pin_dio0": 3, "pin_rst": 25 }, "gateway_conf": { "ref_latitude": 0.0, "ref_longitude": 0.0, "ref_altitude": 10, "name": "Radio Pi Bonnet", "email": "[email protected]", "desc": "Adafruit Radio Pi LoRa 1-Ch Gateway", "is_pi_zero": true, "servers": [ { "address": "router.us.thethings.network", "port": 1700, "enabled": true }, { "address": "router.eu.thethings.network", "port": 1700, "enabled": false } ] } }
Gateway Usage
From within the single_chan_pkt_fwd/
folder, run the Python program by entering the following into the terminal:
python3 lorawan_gateway.py
Page last edited January 22, 2025
Text editor powered by tinymce.