SPI not defined lora rfm9x

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
candybolt777
 
Posts: 2
Joined: Thu May 19, 2022 3:19 pm

SPI not defined lora rfm9x

Post by candybolt777 »

Hi,
Below is the error received. Could the SPI be damaged?

root@loraradio2:/home/pi# python rfm9x_spi.py Traceback (most recent call last):
File "rfm9x_spi.py", line 10, in <module>
import adafruit_rfm9x
File "/usr/local/lib/python3.7/dist-packages/adafruit_rfm9x.py", line 142, in <module>
class RFM9x:
File "/usr/local/lib/python3.7/dist-packages/adafruit_rfm9x.py", line 265, in RFM9x
crc: bool = True
NameError: name 'SPI' is not defined

below is the script used:

Code: Select all

 # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# Simple demo of sending and recieving data with the RFM95 LoRa radio.
# Author: Tony DiCola
import board
import busio
import digitalio

import adafruit_rfm9x


# Define radio parameters.
RADIO_FREQ_MHZ = 915.0  # Frequency of the radio in Mhz. Must match your
# module! Can be a value like 915.0, 433.0, etc.

# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
CS = digitalio.DigitalInOut(board.D5)
RESET = digitalio.DigitalInOut(board.D6)
# Or uncomment and instead use these if using a Feather M0 RFM9x board and the appropriate
# CircuitPython build:
# CS = digitalio.DigitalInOut(board.RFM9X_CS)
# RESET = digitalio.DigitalInOut(board.RFM9X_RST)

# Define the onboard LED
LED = digitalio.DigitalInOut(board.D13)
LED.direction = digitalio.Direction.OUTPUT

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialze RFM radio
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)

# Note that the radio is configured in LoRa mode so you can't control sync
# word, encryption, frequency deviation, or other settings!

# You can however adjust the transmit power (in dB).  The default is 13 dB but
# high power radios like the RFM95 can go up to 23 dB:
rfm9x.tx_power = 23

# Send a packet.  Note you can only send a packet up to 252 bytes in length.
# This is a limitation of the radio packet size, so if you need to send larger
# amounts of data you will need to break it into smaller send calls.  Each send
# call will wait for the previous one to finish before continuing.
rfm9x.send(bytes("Hello world!\r\n", "utf-8"))
print("Sent Hello World message!")

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: SPI not defined lora rfm9x

Post by neradoc »

Hi,
that's a bug in the library, for a temporary solution try installing the previous version of it.

Code: Select all

pip install adafruit-circuitpython-rfm9x==2.2.3 

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: SPI not defined lora rfm9x

Post by neradoc »

Ah it's fixed an released now so instead you can just update to latest:

Code: Select all

pip3 install -U adafruit-circuitpython-rfm9x

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”