Add Pico
This commit is contained in:
34
examples/Pico_read.py
Normal file
34
examples/Pico_read.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from mfrc522 import MFRC522
|
||||||
|
|
||||||
|
|
||||||
|
def uidToString(uid):
|
||||||
|
mystring = ""
|
||||||
|
for i in uid:
|
||||||
|
mystring = "%02X" % i + mystring
|
||||||
|
return mystring
|
||||||
|
|
||||||
|
|
||||||
|
reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0)
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("Place card before reader to read from address 0x08")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
|
||||||
|
(stat, tag_type) = reader.request(reader.REQIDL)
|
||||||
|
|
||||||
|
if stat == reader.OK:
|
||||||
|
|
||||||
|
(stat, uid) = reader.SelectTagSN()
|
||||||
|
|
||||||
|
if stat == reader.OK:
|
||||||
|
print("Card detected %s" % uidToString(uid))
|
||||||
|
else:
|
||||||
|
print("Authentication error")
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Bye")
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ class MFRC522:
|
|||||||
PICC_ANTICOLL3 = 0x97
|
PICC_ANTICOLL3 = 0x97
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, sck, mosi, miso, rst, cs):
|
def __init__(self, sck, mosi, miso, rst, cs,baudrate=1000000,spi_id=0):
|
||||||
|
|
||||||
self.sck = Pin(sck, Pin.OUT)
|
self.sck = Pin(sck, Pin.OUT)
|
||||||
self.mosi = Pin(mosi, Pin.OUT)
|
self.mosi = Pin(mosi, Pin.OUT)
|
||||||
@@ -38,6 +38,8 @@ class MFRC522:
|
|||||||
elif (board == 'esp8266') or (board == 'esp32'):
|
elif (board == 'esp8266') or (board == 'esp32'):
|
||||||
self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso)
|
self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso)
|
||||||
self.spi.init()
|
self.spi.init()
|
||||||
|
elif board == 'rp2':
|
||||||
|
self.spi = SPI(spi_id,baudrate=baudrate,sck=self.sck, mosi= self.mosi, miso= self.miso)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unsupported platform")
|
raise RuntimeError("Unsupported platform")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user