Diogo Alexandre
Diogo Alexandre

Reputation: 79

Raspberry Pi 3B and RFID RC522 - Python TypeError

I've been messing around with Raspberry Pi and RFID and found this tutorial:

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

Everything went fine with the installation but when I'm running the script it presents an error.

This is the problem:

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)

This is the Write.py file:

#!/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()

I can't find the solution to this problem in any place. Already tried to use Python 3 and other libraries but I'm still getting the error.

UPDATE :

Edited this on MFRC522.py file :

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

And now I get this output :

/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

Upvotes: 1

Views: 13546

Answers (5)

lordJeA
lordJeA

Reputation: 101

I just removed IRQ cable and it worked for me. Although I'm not sure if this is the best approach.

To be sure test your scripts using root.

Upvotes: 0

Grave Digga
Grave Digga

Reputation: 1

I had the same problem . My solution was:

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

it works after these commands

 sudo python3 setup.py install

Upvotes: 0

dida110
dida110

Reputation: 121

Have a look here: https://github.com/lthiery/SPI-Py/issues/23 I'm getting the same issue after I updated SPI...

Upvotes: 0

derweili
derweili

Reputation: 141

The problem comes from the https://github.com/lthiery/SPI-Py library. If you roll back to 8cce26b9ee6e69eb041e9d5665944b88688fca68 it should work

Make sure to run the setup again after rollback.

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

Upvotes: 13

eldorado
eldorado

Reputation: 46

I had the same issue for at least 2 hours... now i found out, that the IRQ channel of RC522 has to be soldered to pin 18 of raspberry PI... I also renewed the soldered pins on the rc522, now it works fine.. seems to be a mechanic issue, no software problem..

This also helps: https://github.com/ondryaso/pi-rc522

Befor (error msg):

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)

Now:

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])

Upvotes: 2

Related Questions