mxgxw / MFRC522-python

A small class to interface with the NFC reader Module MFRC522
GNU Lesser General Public License v3.0
521 stars 419 forks source link

Python 3 and SPI lib updates #80

Closed lucassarcanjo closed 4 months ago

lucassarcanjo commented 4 years ago

I'd include some modifications to run the project on python 3 environment (minor changes). I also modified some functions of read/write SPI, that were changed by LThiery (author of spi library of this sensor library).

victormagalhaess commented 4 years ago

Thank you so much!

rami85 commented 4 years ago

Hi Lucas,

I tried to run your fork with SPI and Python3 modifications but I still get this error:

python Read.py

/home/pi/.../test/MFRC522-python/MFRC522.py:133: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  GPIO.setup(self.NRSTPD, GPIO.OUT)
Traceback (most recent call last):
  File "Read.py", line 41, in <module>
    MIFAREReader = MFRC522.MFRC522()
  File "/home/pi/.../test/MFRC522-python/MFRC522.py", line 135, in __init__
    self.MFRC522_Init()
  File "/home/pi/.../test/MFRC522-python/MFRC522.py", line 406, in MFRC522_Init
    self.MFRC522_Reset();
  File "/home/pi/.../test/MFRC522-python/MFRC522.py", line 138, in MFRC522_Reset
    self.Write_MFRC522(self.CommandReg, self.PCD_RESETPHASE)
  File "/home/pi/.../test/MFRC522-python/MFRC522.py", line 141, in Write_MFRC522
    spi.transfer(((addr<<1)&0x7E,val))
TypeError: function takes exactly 2 arguments (1 given)

Last version of SPI is installed and pins are connected correctly as documentation explains.

Do you have any idea of that issue? Thanks in advace Lucas.

Regards.

lucassarcanjo commented 4 years ago

Do you have any idea of that issue? Thanks in advace Lucas.

Hi @rami85, See the modifications that I did in MFRC522.py. The last update of SPI-Py lib changed the number of arguments in some functions.

The old way (your code on line 141):

spi.transfer(((addr<<1)&0x7E,val))

The new way:

spi.transfer(self.dev_dictionary, ((addr<<1)&0x7E,val))

Take a look at Files Changed tab. With slightly changes in lines 131, 141 and 144 your code must run 😄

rami85 commented 4 years ago

Thank you Lucas, I cloned the master brach instead your fork.

However, I found a couple issues:

on line 310 on MFRC522.py:

print("Size: ".format(ackData[0]))

As you see, you lost a 'b'. It should be:

print("Size: ".format(backData[0]))

On the other hand, when the Read.py reads tags, the script prints:

Card detected
Card read UID: %s,%s,%s,%s
Size:
Sector 8 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

So.. it seems there is another bug on Read.py script.

Regards.

marvin-kolja commented 4 years ago

So.. it seems there is another bug on Read.py script.

Hey @rami85, I found what the bug is.

The old python formatting is using: print "%s" % example The new one should be: print("{}".format(example)

I will change those things and upload a new version.

Best regards,

Marvin

ukleinek commented 4 years ago

Converting to python3 is also part of #78 and #28.

xenomorpheus commented 4 years ago

Hi All. I an probably missing something here. Are we waiting for @mxgxw to approve the pull request?