diff --git a/README.md b/README.md index ff50f49..b89b9c3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# 03-04-2018 ADDED SUPPORT FOR ESP32 + # micropython-mfrc522 (Micro)Python class to access the MFRC522 RFID reader @@ -13,23 +15,29 @@ the [WiPy](https://github.com/micropython/micropython/tree/master/cc3200). Put the modules ``mfrc522.py``, ``examples/read.py``, ``examples/write.py`` to the root of the flash FS on your board. For the ESP8266 there are multiple solutions to do that. E.g. use the [WebREPL file transfer](https://github.com/micropython/webrepl), or [mpfshell](https://github.com/wendlers/mpfshell). - + +For ESP32 I use ampy to transfer the files. + I used the following pins for my setup: -| Signal | GPIO ESP8266 | GPIO WiPy | Note | +| Signal | GPIO ESP8266 | GPIO WiPy | ESP32 | | --------- | ------------ | -------------- | ------------------------------------ | -| sck | 0 | "GP14" | | -| mosi | 2 | "GP16" | | -| miso | 4 | "GP15" | | -| rst | 5 | "GP22" | | -| cs | 14 | "GP14" |Labeled SDA on most RFID-RC522 boards | +| sck | 0 | "GP14" | 18 | +| mosi | 2 | "GP16" | 23 | +| miso | 4 | "GP15" | 19 | +| rst | 5 | "GP22" | 4 | +| cs | 14 | "GP14" | 2 | Now enter the REPL you could run one of the two exmaples: For detecting, authenticating and reading from a card: import read - read.do_read() + cs_pin = 2 + reader_number = 0 + read.do_read(cs_pin, reader_number) + +This way you can use multiple readers. Just make sure to assign a new cs_pin. The other pins can be shared. This will wait for a MifareClassic 1k card. As soon the card is detected, it is authenticated, and 16 bytes are read from address 0x08. diff --git a/examples/read.py b/examples/read.py index 783d554..4bf2356 100644 --- a/examples/read.py +++ b/examples/read.py @@ -2,16 +2,21 @@ from os import uname -def do_read(): +def do_read(x,y): if uname()[0] == 'WiPy': rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) + + elif uname()[0] == 'esp32': + rdr = mfrc522.MFRC522(18, 23, 19, 4, x) + else: raise RuntimeError("Unsupported platform") print("") + print('READER %s' %y) print("Place card before reader to read from address 0x08") print("") @@ -43,4 +48,4 @@ def do_read(): print("Failed to select tag") except KeyboardInterrupt: - print("Bye") \ No newline at end of file + print("Bye") diff --git a/examples/write.py b/examples/write.py index 7878d83..026d26d 100644 --- a/examples/write.py +++ b/examples/write.py @@ -8,6 +8,8 @@ def do_write(): rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") elif uname()[0] == 'esp8266': rdr = mfrc522.MFRC522(0, 2, 4, 5, 14) + elif uname()[0] == 'esp32': + rdr = mfrc522.MFRC522(18, 23, 19, 4, 2) else: raise RuntimeError("Unsupported platform") diff --git a/mfrc522.py b/mfrc522.py index 1833d75..66f306c 100644 --- a/mfrc522.py +++ b/mfrc522.py @@ -32,6 +32,9 @@ 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 == 'esp32': + self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso) + self.spi.init() else: raise RuntimeError("Unsupported platform")