{"id":14978091,"url":"https://github.com/fladi/pyrc522","last_synced_at":"2025-10-02T13:31:05.640Z","repository":{"id":46725564,"uuid":"170321933","full_name":"fladi/pyrc522","owner":"fladi","description":"Raspberry Pi Python library for SPI RFID RC522 module","archived":false,"fork":true,"pushed_at":"2021-09-28T08:38:59.000Z","size":59,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-24T23:32:56.109Z","etag":null,"topics":["gpio","raspberry-pi-3","rfid-rc522"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ondryaso/pi-rc522","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fladi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-12T13:22:36.000Z","updated_at":"2021-02-03T22:26:16.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fladi/pyrc522","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fladi%2Fpyrc522","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fladi%2Fpyrc522/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fladi%2Fpyrc522/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fladi%2Fpyrc522/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fladi","download_url":"https://codeload.github.com/fladi/pyrc522/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219875700,"owners_count":16554702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gpio","raspberry-pi-3","rfid-rc522"],"created_at":"2024-09-24T13:56:51.140Z","updated_at":"2025-10-02T13:31:00.289Z","avatar_url":"https://github.com/fladi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python RC522 library\npyrc522 provides a simple interface for controlling an SPI RFID module \"RC522\"\nusing Raspberry Pi.\n\nBased on [MFRC522-python](https://github.com/mxgxw/MFRC522-python/) and\n[pi-rc522](https://github.com/ondryaso/pi-rc522/).\n\nInstall using pip:\n```\npip install pyrc522\n```\n\nOr get source code from Github:\n\n```\ngit clone https://github.com/fladi/pyrc522.git\ncd pyrc522\npython setup.py install\n```\n\nYou'll also need to install the [**periphery**](https://pypi.python.org/pypi/periphery) library.\n\n[MIFARE datasheet](https://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdf) can be useful.\n\n## Sectors? Blocks?\nClassic 1K MIFARE tag has **16 sectors**, each contains **4 blocks**. Each block\nhas 16 bytes. All this stuff is indexed - you must count from zero. The library\nuses \"**block addresses**\", which are positions of blocks - so block address 5\nis second block of second sector, thus it's block 1 of sector 1 (indexes). Block\naddresses 0, 1, 2, 3 are from the first sector - sector 0. Block addresses 4, 5,\n6, 7 are from the second sector - sector 1, and so on. You should **not write**\nto first block - S0B0, because it contains manufacturer data. Each sector has\nit's **sector trailer**, which is located at it's last block - block 3. This\nblock contains keys and access bits for corresponding sector. For more info,\nlook at page 10 of the datasheet. You can use\n[this](http://www.proxmark.org/forum/viewtopic.php?id=1408) useful utility to\ncalculate access bits.\n\n## Connecting\nConnecting RC522 module to SPI is pretty easy. You can use [this neat\nwebsite](http://pi.gadgetoid.com/pinout) for reference.\n\n| Board pin name | Board pin | Physical RPi pin | RPi pin name |\n|----------------|-----------|------------------|--------------|\n| SDA            | 1         | 24               | GPIO8, CE0   |\n| SCK            | 2         | 23               | GPIO11, SCKL |\n| MOSI           | 3         | 19               | GPIO10, MOSI |\n| MISO           | 4         | 21               | GPIO9, MISO  |\n| IRQ            | 5         | 18               | GPIO24       |\n| GND            | 6         | 6, 9, 20, 25     | Ground       |\n| RST            | 7         | 22               | GPIO25       |\n| 3.3V           | 8         | 1,17             | 3V3          |\n\nYou can also connect the SDA pin to CE1 (GPIO7, pin #26) and call the RFID\nconstructor with *bus=0, device=1* and you can connect RST pin to any other free\nGPIO pin and call the constructor with *pin_rst=__BOARD numbering pin__*.\nFurthermore, the IRQ pin is configurable by passing *pin_irq=__BOARD numbering pin__*.\n\n__NOTE:__ For RPi A+/B+/2/3 with 40 pin connector, SPI1/2 is available on top of\nSPI0. Kernel 4.4.x or higher and *dtoverlay* configuration is required. For\nSPI1/2, *pin_ce=__BOARD numbering pin__* is required.\n\nYou may change BOARD pinout to BCM py passing *pin_mode=RPi.GPIO.BCM*. Please\nnote, that you then have to define all pins (irq+rst, ce if neccessary).\nOtherwise they would default to perhaps wrong pins (rst to pin 15/GPIO22, irq to\npin 12/GPIO18).\n\n## Usage\nThe library provides a single class - **RFID**. You basically want to\nstart with *while True* loop and \"poll\" the tag state. That's done using\n*request* method. Most of the methods return error state, which is simple\nboolean - True is error, False is not error. The *request* method returns True\nif tag is **not** present. If request is successful, you should call *anticoll*\nmethod. It runs anti-collision algorithms and returns used tag UID, which you'll\nuse for *select_tag* method. Now you can do whatever you want. Important methods\nare documented.\n\n```python\nfrom pyrc522 import RFID\nrdr = RFID()\n\nwhile True:\n  rdr.wait_for_tag()\n  (error, tag_type) = rdr.request()\n  if not error:\n    print(\"Tag detected\")\n    (error, uid) = rdr.anticoll()\n    if not error:\n      print(\"UID: \" + str(uid))\n      # Select Tag is required before Auth\n      if not rdr.select_tag(uid):\n        # Auth for block 10 (block 2 of sector 2) using default shipping key A\n        if not rdr.card_auth(rdr.auth_a, 10, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], uid):\n          # This will print something like (False, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n          print(\"Reading block 10: \" + str(rdr.read(10)))\n          # Always stop crypto1 when done working\n          rdr.stop_crypto()\n\n# Calls GPIO cleanup\nrdr.cleanup()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffladi%2Fpyrc522","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffladi%2Fpyrc522","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffladi%2Fpyrc522/lists"}