Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Basic class to access RFID readers of the type [MFRC522](http://www.nxp.com/docu
This is basically a re-write of [this](https://github.com/mxgxw/MFRC522-python) Python port for the MFRC522. I
tried to strip things down and make them more "pythonic" so the result is small enough to run on
[Micropython](https://github.com/micropython/micropython) boards. I tried the class so far on the
[ESP8266](https://github.com/micropython/micropython/tree/master/esp8266) and
the [WiPy](https://github.com/micropython/micropython/tree/master/cc3200).
[ESP8266](https://github.com/micropython/micropython/tree/master/ports/esp8266),
the [WiPy](https://github.com/micropython/micropython/tree/master/ports/cc3200)
and [Pi Pico](https://github.com/micropython/micropython/tree/master/ports/rp2).

## Usage

Expand All @@ -16,15 +17,15 @@ For the ESP8266 there are multiple solutions to do that. E.g. use the

I used the following pins for my setup:

| Signal | GPIO ESP8266 | GPIO WiPy | Note |
| --------- | ------------ | -------------- | ------------------------------------ |
| sck | 0 | "GP14" | |
| mosi | 2 | "GP16" | |
| miso | 4 | "GP15" | |
| rst | 5 | "GP22" | |
| cs | 14 | "GP14" |Labeled SDA on most RFID-RC522 boards |
| Signal | GPIO ESP8266 | GPIO WiPy | GPIO Pi Pico | Note |
| --------- | ------------ | -------------- | -------------- | ------------------------------------ |
| sck | 0 | "GP14" | 18 | |
| mosi | 2 | "GP16" | 19 | |
| miso | 4 | "GP15" | 16 | |
| rst | 5 | "GP22" | 20 | |
| cs | 14 | "GP17" | 17 | SDA on most RFID-RC522 boards |

Now enter the REPL you could run one of the two exmaples:
Now enter the REPL you could run one of the two examples:

For detecting, authenticating and reading from a card:

Expand Down
6 changes: 4 additions & 2 deletions examples/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

def do_read():

if uname()[0] == 'WiPy':
if uname()[0] == 'WiPy' or board == 'LoPy' or board == 'FiPy':
rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17")
elif uname()[0] == 'esp8266':
rdr = mfrc522.MFRC522(0, 2, 4, 5, 14)
elif uname()[0] == 'rp2':
rdr = mfrc522.MFRC522(18, 19, 16, 20, 17)
else:
raise RuntimeError("Unsupported platform")

Expand Down Expand Up @@ -43,4 +45,4 @@ def do_read():
print("Failed to select tag")

except KeyboardInterrupt:
print("Bye")
print("Bye")
4 changes: 3 additions & 1 deletion examples/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

def do_write():

if uname()[0] == 'WiPy':
if uname()[0] == 'WiPy' or board == 'LoPy' or board == 'FiPy':
rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17")
elif uname()[0] == 'esp8266':
rdr = mfrc522.MFRC522(0, 2, 4, 5, 14)
elif uname()[0] == 'rp2':
rdr = mfrc522.MFRC522(18, 19, 16, 20, 17)
else:
raise RuntimeError("Unsupported platform")

Expand Down
2 changes: 2 additions & 0 deletions mfrc522.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self, sck, mosi, miso, rst, cs):
elif board == 'esp8266':
self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso)
self.spi.init()
elif board == 'rp2':
self.spi = SPI(0, baudrate=100000, sck=self.sck, mosi=self.mosi, miso=self.miso)
else:
raise RuntimeError("Unsupported platform")

Expand Down