树莓派Python3使用RC522

来源:互联网 发布:淘宝最红女主播 编辑:程序博客网 时间:2024/06/06 18:42
  • 开启SPI通讯
sudo raspi-config找到SPi打开。
  • 安装SPI模块
git clone https://github.com/lthiery/SPI-Pycd SPI-Py sudo python3 setup.py install
  • 安装RFID模块
pip3 install pi-rc522 或者sudo pip3 install pi-rc522
  • 获取UID
#!/usr/bin/python3from pirc522 import RFIDrdr = RFID()while True:  rdr.wait_for_tag()  (error, tag_type) = rdr.request()  if not error:    print("Tag detected")    (error, uid) = rdr.anticoll()    if not error:      print("UID: " + str(uid))      # Select Tag is required before Auth      if not rdr.select_tag(uid):        # Auth for block 10 (block 2 of sector 2) using default shipping key A        if not rdr.card_auth(rdr.auth_a, 10, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], uid):          # This will print something like (False, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])          print("Reading block 10: " + str(rdr.read(10)))          # Always stop crypto1 when done working          rdr.stop_crypto()# Calls GPIO cleanuprdr.cleanup()
原创粉丝点击