树莓派 3 和 Pico 之间的 NRF24L01

问题描述 投票:0回答:0

几天来我一直无法连接我的 Raspberry Pi 3B+ 和我的 Raspberry Pi Pico。 我在 Raspberry pi 3 上使用this library,在 Pico 上使用官方 MicroPython 库。我将所有参数设置为相同并在 lib_nrf24.py 中添加

self.spidev.max_speed_hz = 4000000

我还尝试在 Pi 3 和 Arduino Uno 之间以及两个 Pico 之间进行通信,一切正常。

Raspberry Pi Pico 代码(接收器)

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(发射器)

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)

发消息时忽略打包,我在Pico上仍然收不到任何输入。 感谢任何想帮助我的人。

raspberry-pi spi wireless micropython raspberry-pi-pico
© www.soinside.com 2019 - 2024. All rights reserved.