RFM69 micropython for pi pico #15755
hamishpyle
started this conversation in
General
Replies: 2 comments 3 replies
-
Please provide a link to the driver source. |
Beta Was this translation helpful? Give feedback.
3 replies
-
hamish |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there everyone!
I am a bit of a newbie in regard to micropython and would love some help!
Essentially I am running into a bunch of troubles with the rfm69hcw, I have attached my code below but it hangs while waiting for this to pass: while (self._readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT) == 0x00:
It may have to do with the spi.locks using _thread but I am not sure at all, any help is appreciated thank you!
Note, some methods such as the board allocations for are yet to work for pin assigning so I have just done this through hardcoding.
rfm69.py
import time
import _thread
import machine
from machine import Pin, SPI
from registers import *
from packet import Packet
from config import get_config
from registers import RF69_315MHZ as FREQ_315MHZ
from registers import RF69_433MHZ as FREQ_433MHZ
from registers import RF69_868MHZ as FREQ_868MHZ
from registers import RF69_915MHZ as FREQ_915MHZ
from registers import RF69_MAX_DATA_LEN
class Radio:
"""RFM69 Radio interface for MicroPython.
packet.py:
import json
import time
class Packet:
"""Object to represent received packet. Created internally and
returned by radio when getPackets() is called.
config.py:
Importing constants from registers.py
from registers import *
Frequency band settings
frfMSB = {
RF69_315MHZ: RF_FRFMSB_315,
RF69_433MHZ: RF_FRFMSB_433,
RF69_868MHZ: RF_FRFMSB_868,
RF69_915MHZ: RF_FRFMSB_915
}
frfMID = {
RF69_315MHZ: RF_FRFMID_315,
RF69_433MHZ: RF_FRFMID_433,
RF69_868MHZ: RF_FRFMID_868,
RF69_915MHZ: RF_FRFMID_915
}
frfLSB = {
RF69_315MHZ: RF_FRFLSB_315,
RF69_433MHZ: RF_FRFLSB_433,
RF69_868MHZ: RF_FRFLSB_868,
RF69_915MHZ: RF_FRFLSB_915
}
def get_config(freqBand, networkID):
return {
0x01: [REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY],
0x02: [REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00],
0x03: [REG_BITRATEMSB, RF_BITRATEMSB_55555], # Example bitrate; adjust as needed
0x04: [REG_BITRATELSB, RF_BITRATELSB_55555], # Example bitrate; adjust as needed
0x05: [REG_FDEVMSB, RF_FDEVMSB_50000], # Example frequency deviation; adjust as needed
0x06: [REG_FDEVLSB, RF_FDEVLSB_50000], # Example frequency deviation; adjust as needed
0x07: [REG_FRFMSB, frfMSB[freqBand]],
0x08: [REG_FRFMID, frfMID[freqBand]],
0x09: [REG_FRFLSB, frfLSB[freqBand]],
0x19: [REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2],
0x25: [REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01],
0x29: [REG_RSSITHRESH, 220], # RSSI threshold value
0x2e: [REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0],
0x2f: [REG_SYNCVALUE1, 0x2D],
0x30: [REG_SYNCVALUE2, networkID],
0x37: [REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF |
RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF],
0x38: [REG_PAYLOADLENGTH, 66], # Payload length
0x3C: [REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE],
0x3D: [REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF],
0x6F: [REG_TESTDAGC, RF_DAGC_IMPROVED_LOWBETA0], # DAGC settings
0x00: [255, 0] # End of configuration
}
the registers.py is the same as the rpi-rfm69 found here: https://github.com/jgillula/rpi-rfm69/blob/main/RFM69/radio.py and the tester script is: import time
import machine
from machine import Pin, SPI
from rfm69 import Radio, FREQ_315MHZ, FREQ_433MHZ, FREQ_868MHZ, FREQ_915MHZ
Configuration
node_id = 1
network_id = 100
recipient_id = 2
Board configuration
Adjust these as per your specific hardware setup
board = {
'isHighPower': True,
'interruptPin': 15,
'resetPin': 3,
'spiDevice': 0,
'mosiPin': 7,
'misoPin': 4,
'sckPin':6
}
Setup SPI and GPIO for the radio
interrupt_pin = Pin(board['interruptPin'], Pin.IN)
reset_pin = Pin(board['resetPin'], Pin.OUT)
def reset_radio():
reset_pin.value(0)
time.sleep(0.1)
reset_pin.value(1)
time.sleep(0.1)
Create Radio instance
radio = Radio(FREQ_915MHZ, node_id, network_id, **board)
Main loop
print("Starting loop...")
while True:
start_time = time.time()
radio.close()
spi.deinit()
interrupt_pin.init(Pin.IN)
reset_pin.init(Pin.OUT)
Beta Was this translation helpful? Give feedback.
All reactions