Raspberry Pi 3B 和 RFID RC522 - Python TypeError

Raspberry Pi 3B and RFID RC522 - Python TypeError

我一直在研究 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

我有同样的问题至少 2 小时...现在我发现,RC522 的 IRQ 通道必须焊接到 raspberry PI 的引脚 18...我也更新了焊接rc522 上的引脚,现在它工作正常.. 似乎是一个机械问题,没有软件问题..

这也有帮助:https://github.com/ondryaso/pi-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)

现在:

pi@raspberrypi:~ $ sudo python rfidreader2.py 
/usr/local/lib/python2.7/dist-packages/pi_rc522-2.2.1-py2.7.egg/pirc522/rfid.py:78: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
clean up
Tag detected
UID: [169, 112, 111, 72, 254]
Reading block 10: (False, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

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

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

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

看这里:https://github.com/lthiery/SPI-Py/issues/23 我在更新 SPI 后遇到了同样的问题...

我遇到了同样的问题。我的解决方案是:

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

它在这些命令后工作

 sudo python3 setup.py install

我刚刚移除了 IRQ 电缆,它对我有用。虽然我不确定这是否是最好的方法。

确保使用 root 测试您的脚本。