1

我是 Stackoverflow 的新手。我已经搜索了答案,但没有找到任何东西。

我有两个 Raspberry Pi 2B+,每个都连接了 nRF24l01。我发现很少有库可以建立这种连接,只有一个给出任何结果,但没有连接。这个:Github BLavery

我编写脚本来发送和接收:

发送.py:

import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev

GPIO.setmode(GPIO.BCM)

pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]

radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)

radio.setDataRate(NRF24.BR_2MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()

radio.openWritingPipe(pipes[1])
radio.printDetails()

while True:
    message = list("Hello World")
    radio.write(message)
    print("We sent the message of {}".format(message))

    # Check if it returned a ackPL
    if radio.isAckPayloadAvailable():
        returnedPL = []
        radio.read(returnedPL, radio.getDynamicPayloadSize())
        print("Our returned payload was {}".format(returnedPL))
    else:
        print("No payload received")
    time.sleep(1)

接收文件:

import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev

GPIO.setmode(GPIO.BCM)

pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]

radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)

radio.setDataRate(NRF24.BR_2MBPS)
radio.setPAlevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()

radio.openReadingPipe(1, pipes[1])
radio.printDetails()

radio.startListening()

while True:
    ackPL = [1]
    while not radio.available (0):
        time.sleep(1/100)

    receivedMessage = []
    radio.read(receivedMessage, radio.getDynamicPayloadSize())
    print("Received: {}".format(receivedMessage))

    print("Translating the receivedMessage into unicode characters...")
    string = ""
    for n in receivedMessage:
        # Decode into standard i=unicode set
        if (n >=32 and n <= 126):
            string += chr(n)
    print(string)

    radio.writeAckPayload(1, ackPL, len(ackPL))
    print("Loaded payload reply of {}".format(ackPL))

一切似乎都很好,下面是两个脚本返回的代码:

发送:

STATUS   = 0x03 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=1

RX_ADDR_P0-1     =
 0xf8f8f8f8f8 0xf8f8f8f8f8

RX_ADDR_P2-5     =
0xf8
0xf9
0xf9
0xf9

TX_ADDR      =
 0xf8f8f8f8f8

RX_PW_P0-6   =
0x0c
0x00
0x00
0x00
0x00
0x00

EN_AA        =
0x0f

EN_RXADDR    =
0x00

RF_CH        =
0x1c

RF_SETUP     =
0x00

CONFIG       =
0x03

DYNPD/FEATURE    =
0x03
0x01

Data Rate    = 1MBPS
Model        = nRF24L01
CRC Length   = Disabled
PA Power     = PA_MIN

We sent the message of ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

No payload received

接收文件:

STATUS   = 0x03 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=1

RX_ADDR_P0-1     =
 0xf8f8f8f8f8 0xf8f8f8f8f8

RX_ADDR_P2-5     =
0xf8
0xf9
0xf9
0xf9

TX_ADDR      =
 0xf8f8f8f8f8

RX_PW_P0-6   =
0x0c
0x0c
0x00
0x00
0x00
0x00

EN_AA        =
0x0f

EN_RXADDR    =
0x00

RF_CH        =
0x1c

RF_SETUP     =
0x00

CONFIG       =
0x03

DYNPD/FEATURE    =
0x03
0x01

Data Rate    = 1MBPS
Model        = nRF24L01
CRC Length   = Disabled
PA Power     = PA_MIN

Received: []

Translating the receivedMessage into unicode characters...

Loaded payload reply of [1]

我真的不明白为什么它不会相互连接,两者都有相同的接线:

nRF24L01-树莓派(引脚号)

  • 接地 - 接地 (6)
  • VCC - 3,3V (1)
  • CE-GPIO17 (11)
  • CSN-GPIO08(24)
  • SCK-GPIO11 (23)
  • MOSI - GPIO10 (19)
  • 味噌 - GPIO25 (22)
  • IRQ - 未连接

我需要将信息从一个 RPi 发送到第二个,以通过 PWM 控制引擎。

我可以寻求帮助吗

4

0 回答 0