gpt4 book ai didi

python - Raspberry Pi 3B 和 RFID RC522 - Python TypeError

转载 作者:太空宇宙 更新时间:2023-11-04 06:51:35 27 4
gpt4 key购买 nike

我一直在摆弄 Raspberry Pi 和 RFID,发现了这个教程:

https://pimylifeup.com/raspberry-pi-rfid-rc522/

安装一切顺利,但当我运行脚本时出现错误。

问题是:

pi@raspberrypi:~/MFRC522-python $ sudo python Write.py
/home/pi/MFRC522-python/MFRC522.py:115: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(25, GPIO.OUT)
Traceback (most recent call last):
File "Write.py", line 6, in <module>
reader = SimpleMFRC522.SimpleMFRC522()
File "/home/pi/MFRC522-python/SimpleMFRC522.py", line 14, in __init__
self.READER = MFRC522.MFRC522()
File "/home/pi/MFRC522-python/MFRC522.py", line 117, in __init__
self.MFRC522_Init()
File "/home/pi/MFRC522-python/MFRC522.py", line 390, in MFRC522_Init
self.MFRC522_Reset();
File "/home/pi/MFRC522-python/MFRC522.py", line 120, in MFRC522_Reset
self.Write_MFRC522(self.CommandReg, self.PCD_RESETPHASE)
File "/home/pi/MFRC522-python/MFRC522.py", line 123, in Write_MFRC522
spi.transfer(((addr<<1)&0x7E,val))
TypeError: function takes exactly 2 arguments (1 given)

这是 Write.py 文件:

#!/usr/bin/env python

import RPi.GPIO as GPIO
import SimpleMFRC522

reader = SimpleMFRC522.SimpleMFRC522()

try:
text = raw_input('New data:')
print("Now place your tag to write")
reader.write(text)
print("Written")
finally:
GPIO.cleanup()

我在任何地方都找不到这个问题的解决方案。已经尝试使用 Python 3 和其他库,但我仍然遇到错误。

更新:

在 MFRC522.py 文件上编辑:

def Write_MFRC522(self, addr, val):
spi.transfer( (addr<<1)&0x7E, val )

现在我得到了这个输出:

/home/pi/MFRC522-python/MFRC522.py:115: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(25, GPIO.OUT)
First argument must be a valid dictionary.: Success
Aborted

最佳答案

问题来自https://github.com/lthiery/SPI-Py图书馆。如果你回滚到 8cce26b9ee6e69eb041e9d5665944b88688fca68 它应该可以工作

确保在回滚后再次运行设置。

git clone https://github.com/lthiery/SPI-Py.git
git checkout 8cce26b9ee6e69eb041e9d5665944b88688fca68
sudo python setup.py install

关于python - Raspberry Pi 3B 和 RFID RC522 - Python TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54847012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com