Skip to content

Instantly share code, notes, and snippets.

@pelwell
Last active December 19, 2019 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelwell/e667bc7eebfb32d18a60bc91f6411db9 to your computer and use it in GitHub Desktop.
Save pelwell/e667bc7eebfb32d18a60bc91f6411db9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf8 -*-
# MFRC522_test.py - Copyright 2017-2019, Phil Elwell, Raspberry Pi (Trading) Ltd.
import RPi.GPIO as GPIO
import spi
import signal
import time
NRSTPD = 22
dev = spi.openSPI(device='/dev/spidev0.0', speed=1000000)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(NRSTPD, GPIO.OUT)
GPIO.output(NRSTPD, 0)
time.sleep(0.1)
GPIO.output(NRSTPD, 1)
time.sleep(0.1)
line = ''
for addr in range(0,64):
col = addr % 8
val = spi.transfer(dev, (((addr<<1)&0x7E) | 0x80,0))
if col == 0:
line = '%02x:' % addr
line += ' %02x' % val[1]
if col == 7:
print line
@Jerakin
Copy link

Jerakin commented Dec 19, 2019

I am trying to get a RC522 to work with python3, running this test I get this error

  File "MFRC522_test.py", line 25, in <module>
    val = spi.transfer((((addr<<1)&0x7E) | 0x80,0))
TypeError: function takes exactly 2 arguments (1 given)

Checking out SPI-Py to 8cce26 fixes the issue

@pelwell
Copy link
Author

pelwell commented Dec 19, 2019

The SPI-Py API changed. I've updated the MFRC522_test.py .gist to work with the current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment