-
Notifications
You must be signed in to change notification settings - Fork 118
Added support for ESP32 #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
200ea0e
2e5a87b
fb8ba08
0533a9b
008a9af
85a5798
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't have some of these pins on my wems oled esp32 devboard. 16, 5, 26, 25, 4 worked for me. |
||
|
|
||
| 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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,21 @@ | |
| from os import uname | ||
|
|
||
|
|
||
| def do_read(): | ||
| def do_read(x,y): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8: please have a blank after the comma also, don't call it x and y, but give good names. |
||
|
|
||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8: please have a blank after the percent |
||
| 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") | ||
| print("Bye") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as you are doing precisely the same thing as 3 lines above, how about just changing line 32 to: |
||
| else: | ||
| raise RuntimeError("Unsupported platform") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't have a "cs" on my board.
so, if it really is labelled "sda" for me, keeping that comment seems useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can confirm that cs is labelled sda for me. at least it practically works if i wire it like that.