我将我的RC522射频识别模块按照https://pimylifeup.com/raspberry-pi-rfid-rc522/连接到我的Raspberry Pi 4,所以我们有Write.py和Read.py:
Write.py:
#!/usr/bin/env python
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
try:
text = input('New data:')
print("Now place your tag to write")
reader.write(text)
print("Written")
finally:
GPIO.cleanup()Read.py是:
#!/usr/bin/env python
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
try:
id, text = reader.read()
print(id)
print(text)
finally:
GPIO.cleanup()但是,当我执行sudo python3 Write.py时,会出现以下错误:
Traceback (most recent call last):
File "Write.py", line 6, in <module>
reader = SimpleMFRC522()
File "/usr/local/lib/python3.7/dist-packages/mfrc522/SimpleMFRC522.py", line 14, in __init__
self.READER = MFRC522()
File "/usr/local/lib/python3.7/dist-packages/mfrc522/MFRC522.py", line 130, in __init__
self.spi.open(bus, device)对于Read.py,我们几乎与Write.py执行错误相同,如下所示:
Traceback (most recent call last):
File "Read.py", line 6, in <module>
reader = SimpleMFRC522()
File "/usr/local/lib/python3.7/dist-packages/mfrc522/SimpleMFRC522.py", line 14, in __init__
self.READER = MFRC522()
File "/usr/local/lib/python3.7/dist-packages/mfrc522/MFRC522.py", line 130, in __init__
self.spi.open(bus, device)
FileNotFoundError: [Errno 2] No such file or directory
FileNotFoundError: [Errno 2] No such file or directory我尝试过几种方法,但根本没有起作用:1-检查布线2-使用python2 3-检查SPI使用图形用户界面,也启动/config.txt 4-使用sudo apt-get update、sudo apt-get upgrade、sudo apt-get install python3-dev python3-pip和sudo pip3 install spidev
我试图检查lsmod |grep spi,结果是:
spidev 20480 0
spi_bcm2835 24576 0
spi_bcm2835aux 16384 0你觉得有什么问题吗?我的覆盆子Pi 4也有一个3.5英寸触摸屏液晶显示器.这就是spi0被保留的原因吗?怎么修呢?我甚至不能使用另一个RC522程序--在github.com中,它们在spi.open(总线、设备)中有几乎相同的错误。
发布于 2021-08-30 14:56:03
我找到了简单的答案。只要重新安装Raspbian操作系统,重置SPI配置(这是为3.5英寸液晶),这样RFID读写工作良好,一切都是正确的。
https://stackoverflow.com/questions/68873696
复制相似问题