你能帮我在树莓派上写这段代码吗?我正在尝试将 nrf 模块与 nrf24 库连接.... 类型错误<= not supported instances between int and spidev error
请帮我解决这个问题
代码:
import time import spidev
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24 # GPIO pin used for CE on the NRF24L01+ radio moduleCE_PIN = 25 #GPIO pin used for the button
BUTTON_PIN = 23 # Setup SPI busspi = spidev.SpiDev()
spi.open(0,0) # Setup NRF24L01+ radio moduleradio =NRF24(GPIO, spi, CE_PIN) radio.begin(0, 0) radio.setPayloadSize(32) radio.setChannel(0x76) radio.setDataRate(NRF24.BR_1MBPS) radio.setPALevel(NRF24.PA_MAX) radio.setAutoAck(True) radio.enableDynamicPayloads() radio.enableAckPayload() # Setup button pinGPIO.setmode(GPIO.BCM) GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True: # Check if button is pressed if not GPIO.input(BUTTON_PIN): # Button is pressed, send message
message = list("Button pressed!")
while len(message) < 32:
message.append(0)
radio.write(message)
print("Message sent: {}".format(message)) time.sleep(0.5)
我尝试重新安装 spidev 库并更改密码