[Python] RFM69 stuck on 1024

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have an RFM69HCW connected to a raspberry pi pico like this:

    [​IMG]

    running this script, I always seem to get back the wrong values.It always returns the maximum it can give.

    """ Receiver """

    from machine import SPI, Pin
    from rfm69 import RFM69
    import time

    FREQ = 432.5
    ENCRYPTION_KEY = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
    NODE_ID = 100 # ID of this node (BaseStation)

    spi = SPI(0, sck=Pin(6), mosi=Pin(7), miso=Pin(4), baudrate=50000, polarity=0, phase=0, firstbit=SPI.MSB)
    nss = Pin( 5, Pin.OUT, value=True )
    rst = Pin( 3, Pin.OUT, value=False )

    led = Pin( 25, Pin.OUT )

    rfm = RFM69( spi=spi, nss=nss, reset=rst )
    rfm.frequency_mhz = FREQ
    rfm.encryption_key = ( ENCRYPTION_KEY )
    rfm.node = NODE_ID

    print( 'Freq :', rfm.frequency_mhz )
    print( 'NODE :', rfm.node )

    print("Waiting for packets...")
    while True:
    packet = rfm.receive( timeout = 0.5 ) # Without ACK
    if packet is None: # No packet received
    print( "." )
    pass
    else: # Received a packet!
    led.on()
    # And decode from ASCII text (to local utf-8)
    print(packet)
    message = str(packet, "ascii") # this is our message
    rssi = str(rfm.last_rssi) # signal strength
    print(message + ", " + rssi) # print message with signal strength
    led.off()




    This is the output if I run the program:

    MPY: soft reboot
    Freq : 1024.0
    NODE : 100
    Waiting for packets...
    bytearray(b'\xff\xff\xff...')
    Traceback (most recent call last):
    File "<stdin>", line 35, in <module>
    UnicodeError:


    I have tested the connection using this script:

    """ Basic test of RFM69HCW SPI module

    RFM69HCW breakout : https://shop.mchobby.be/product.php?id_product=1390
    RFM69HCW breakout : https://www.adafruit.com/product/3071

    https://github.com/mchobby/esp8266-upy/tree/master/rfm69
    """

    from machine import SPI, Pin
    from rfm69 import RFM69

    def dbm_to_mw(dBm):
    """ Transform the power in dBm to its equivalent in milliWatt """
    return 10**((dBm)/10.)

    spi = SPI(0, baudrate=50000, polarity=0, phase=0, firstbit=SPI.MSB)
    nss = Pin( 5, Pin.OUT, value=True )
    rst = Pin( 3, Pin.OUT, value=False )

    rfm = RFM69( spi=spi, nss=nss, reset=rst )
    rfm.frequency_mhz = 433.1
    rfm.bitrate = 250000 # 250 Kbs
    rfm.frequency_deviation = 250000 # 250 KHz
    rfm.tx_power = 13 # 13 dBm = 20mW (default value, safer for all modules)
    #rfm.tx_power = 20 # 20 dBm = 100mW, 20 dBm for FRM69HW
    rfm.encryption_key = ( b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" )

    print( 'RFM version :', rfm.version )
    print( 'Freq :', rfm.frequency_mhz )
    print( 'Freq. deviation :', rfm.frequency_deviation, 'Hz' )
    print( 'bitrate :', rfm.bitrate, 'bits/sec' )
    print( 'tx power :', rfm.tx_power, 'dBm' )
    print( 'tx power :', dbm_to_mw(rfm.tx_power), 'mW' )
    print( 'Temperature :', rfm.temperature, 'Celsius' )
    print( 'Sync on :', 'yes' if rfm.sync_on else 'no' )
    print( 'Sync size :', rfm.sync_size )
    print( 'Sync Word Length:', rfm.sync_size+1, "(Sync size+1)" )
    print( 'Sync Word :', rfm.sync_word )
    print( 'CRC on :', rfm.crc_on )

    print( 'Preamble Lenght :', rfm.preamble_length )
    print( 'aes on :', rfm.aes_on )
    print( 'Encryption Key :', rfm.encryption_key )


    which gives this result:

    [​IMG]

    Continue reading...

Compartilhe esta Página