Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with device #30

Open
hamishpyle opened this issue Aug 30, 2024 · 4 comments
Open

Issues with device #30

hamishpyle opened this issue Aug 30, 2024 · 4 comments

Comments

@hamishpyle
Copy link

Hey there!
First of all, thank you so much for making this repo it is genuinely amazing documentation wise.

I have however run into various different problems potentially due to the breakout I am using which is the red sparkfun 915MHz breakout. This is with a raspberry Pi 3B+ by the way.

Basically when I follow the tutorial connecting the pins to the physical pins as follows:
Miso - 21
Mosi - 19
SCK - 23
NSS - 24
RST - 22
GND - 20
Vin - 17
And run the example_rxtx.py file with the only difference being this :

board = {'isHighPower': True, 'interruptPin': 18, 'resetPin': 22, 'spiDevice': 0}

I get this output:

Screen Shot 2024-08-30 at 9 17 47 pm
or in case the above doesnt load:

python3 example_rxtx.py
/home/pi/Thesis/rpi-rfm69/RFM69/radio.py:115: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(self.rstPin, GPIO.OUT)
Traceback (most recent call last):
File "/home/pi/Thesis/rpi-rfm69/example_rxtx.py", line 23, in
with Radio(FREQ_915MHZ, node_id, network_id, verbose=False, **board) as radio:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/Thesis/rpi-rfm69/RFM69/radio.py", line 87, in init
self._initialize(freqBand, nodeID, networkID)
File "/home/pi/Thesis/rpi-rfm69/RFM69/radio.py", line 96, in _initialize
self._reset_radio()
File "/home/pi/Thesis/rpi-rfm69/RFM69/radio.py", line 135, in _reset_radio
raise Exception('Failed to sync with radio') # pylint: disable=broad-exception-raised
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Failed to sync with radio

Any help would be appreciated and I have looked into each of the separate examples separately to no avail.
Could it be an issue with power supply? Or is this a rooted raspberry pi issue.

Thanks!

@jgillula
Copy link
Owner

I don't think it's a root raspberry pi issue. There's a chance it's a power supply issue, but that also wouldn't be my first guess.

Where the example is dying is where the code first tries to even communicate with the radio. It tries to write to one of the registers, and then waits up to 15 seconds to see if the write was successful.

I'm not sure what the problem could be, since it looks like you have everything wired up correctly. Have you successfully tried your radio with an Arduino (or some other board)?

@hamishpyle
Copy link
Author

Hey there, thank you so much for the reply ! I ended up basically unistalling python3-rpi.gpio and installing python3-rpi-lgpio and this worked and I can actually get passed that step. Not 100% sure why though. My next step is understanding the networkID and how that relates to the nodeID and recipient_id, is it possible to run the script without using a networkID and plainly sending to the nodes?

@jgillula
Copy link
Owner

nodeID is the ID of the local node, and recipient_ID is the ID of the recipient node you're transmitting to. networkID is used to specify a specific network, so that, e.g., if you and your neighbor both had RFM69 nodes, you could use the same nodeIDs as long as you picked different networkIDs.

@hamishpyle
Copy link
Author

Thank you for that! Essentially I am trying to port this into micropython and am having issues (all good if you don't know btw) but I am hanging and waiting for this: while (self._readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT) == 0x00:
this is the code : def _sendFrame(self, toAddress, buff, requestACK, sendACK):
# Set to standby mode and wait until the mode is ready
self._setMode(RF69_MODE_STANDBY)
print("Setting mode to STANDBY")
while (self._readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00:
print("Waiting for mode to be ready...")
print("Current IRQFLAGS1 register value:", bin(self._readReg(REG_IRQFLAGS1)))
time.sleep(0.01)
print("Mode is ready")

    # Configure DIO mapping
    self._writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00)
    print("DIO mapping set")
    print("Current DIOMAPPING1 register value:", bin(self._readReg(REG_DIOMAPPING1)))

    # Check buffer length
    if len(buff) > RF69_MAX_DATA_LEN:
        buff = buff[:RF69_MAX_DATA_LEN]
    print("Buffer length adjusted to:", len(buff))

    # Determine ACK settings
    ack = 0
    if sendACK:
        ack = 0x80
        if enableATC:
            ack |= 0x20
        print("Sending ACK with ATC enabled" if enableATC else "Sending ACK")
    elif requestACK:
        ack = 0x40
        print("Requesting ACK")

    # Convert buffer to list of bytes if it's a string
    with self.spiLock:
        if isinstance(buff, str):
            buff = [ord(i) for i in buff]
            print("Converted buffer from string to list of bytes:", buff)

    # Prepare and send data
    # Adjusted packet format example
    packet = bytearray([REG_FIFO | 0x80, len(buff) + 5, toAddress, self.address, ack] + buff)
    print("Sending packet:", list(packet))
    try:
        self.spiBus.write(packet)
        print("Packet written to SPI bus")
    except Exception as e:
        print("SPI write error:", e)

    # Wait for transmission to complete
    with self.sendLock:
        self._setMode(RF69_MODE_TX)
        print("Setting mode to TX")
        timeout = 10  # Increase timeout to 10 seconds
        start_time = time.time()
        while (self._readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT) == 0x00:
            current_time = time.time()
            if (current_time - start_time) > timeout:
                print("Timeout waiting for packet sent flag")
                break
            print("Waiting for packet sent flag...")
            print("Current IRQFLAGS2 register value:", bin(self._readReg(REG_IRQFLAGS2)))
            print("Current OPMODE register value:", bin(self._readReg(REG_OPMODE)))
            time.sleep(0.1)
        else:
            print("Packet sent flag detected")

    # Set to receive mode
    self._setMode(RF69_MODE_RX)
    print("Setting mode to RX")

Again genuinely don't feel obliged to respond if you don't know ! But thank you for the help anyways :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants