Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 and SPI lib updates #80

Closed
wants to merge 4 commits into from

Conversation

lucassarcanjo
Copy link

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
Copy link

Thank you so much!

@rami85
Copy link

rami85 commented Aug 27, 2019

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
Copy link
Author

lucassarcanjo commented Aug 27, 2019

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
Copy link

rami85 commented Aug 28, 2019

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
Copy link

marvin-kolja commented Sep 20, 2019

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

[mad-marvin] and others added 2 commits September 20, 2019 13:11
@ukleinek
Copy link

ukleinek commented Oct 8, 2019

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

Copy link

@marvin-kolja marvin-kolja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for responding to my request. 👍 @lucassarcanjo

@xenomorpheus
Copy link

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

@@ -52,7 +52,7 @@ def end_read(signal,frame):

# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
print("Card detected")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wat speel hier vandaag: UID alle vier de id controleren

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants