2xRaspberry Pi nRF24L01无法连接

时间:2018-06-30 16:04:48

标签: python raspberry-pi

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

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

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

send.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)

recv.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.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

recv.py:

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-Raspberry Pi(Pin#)

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

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

我可以寻求帮助吗

0 个答案:

没有答案