0

I've been having trouble connecting my Raspberry Pi 3B+ and my Raspberry Pi Pico for days. I'm using this library on the Raspberry pi 3 and the official MicroPython library on the Pico. I set all the parameters the same and added self.spidev.max_speed_hz = 4000000 in lib_nrf24.py.

I've also tried to communicate between the Pi 3 and an Arduino Uno and between two Picos and everything works fine.

Raspberry Pi Pico code (Receiver)

import ustruct as struct
import utime
from machine import Pin, SPI
from nrf24l01 import NRF24L01
from micropython import const

# delay between receiving a message and waiting for the next message
POLL_DELAY = const(15)
# Delay between receiving a message and sending the response
# (so that the other pico has time to listen)
SEND_DELAY = const(10)

# Pico pin definition:
myPins = {"spi": 0, "miso": 4, "mosi": 7, "sck": 6, "csn": 14, "ce": 17}

# Addresses
pipe = b"\xe1\xf0\xf0\xf0\xf0"

csn = Pin(myPins["csn"], mode=Pin.OUT, value=1)
ce = Pin(myPins["ce"], mode=Pin.OUT, value=0)
nrf = NRF24L01(SPI(myPins["spi"]), csn, ce, channel=46, payload_size=8)

nrf.open_rx_pipe(pipe)
nrf.start_listening()
led = Pin(25, Pin.OUT)
led.toggle()

print("nRF24L01 receiver; waiting for the first post...")

while True:
    if nrf.any(): # we received something
        print("any")
        while nrf.any():
            buf = nrf.recv()
            counter = struct.unpack("i", buf)
            print("message received:", counter[0])
            utime.sleep_ms(POLL_DELAY) # delay before next listening

Raspberry Pi 3 (Transmitter)

import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xE1, 0xF0, 0xF0, 0xF0, 0xF0], [0xD2, 0xF0, 0xF0, 0xF0, 0xF0]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 25)
radio.setPayloadSize(8)
radio.setChannel(46)
radio.setDataRate(NRF24.BR_250KBPS)
radio.setPALevel(NRF24.PA_MAX)
radio.openWritingPipe(pipes[0])
radio.printDetails()
# radio.startListening()
message = "1"
while(1):
    start = time.time()
    radio.write(message)
    print("Sent the message: {}".format(message))

    time.sleep(1)

Ignoring the packing when sending messages, I still don't receive any input on the Pico. Thanks to anyone who wants to help me.

manuel
  • 1
  • 2

0 Answers0