Raspberry Pi 3B和RFID RC522-Python TypeError

时间:2019-02-23 22:46:32

标签: python python-2.7 raspberry-pi typeerror rfid

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

4 个答案:

答案 0 :(得分:4)

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

确保回滚后再次运行安装程序。

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

答案 1 :(得分:2)

我在至少2个小时内遇到了同样的问题...现在我发现,RC522的IRQ通道必须焊接到覆盆子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])

答案 2 :(得分:0)

在这里看看:https://github.com/lthiery/SPI-Py/issues/23 更新SPI后出现相同的问题...

答案 3 :(得分:0)

我有同样的问题。我的解决方案是:

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

在执行这些命令后

 sudo python3 setup.py install