{"id":13481061,"url":"https://github.com/Galarzaa90/android-things-rc522","last_synced_at":"2025-03-27T11:31:45.608Z","repository":{"id":96171051,"uuid":"86503256","full_name":"Galarzaa90/android-things-rc522","owner":"Galarzaa90","description":"Android library to communicate with RFID Module RC522","archived":true,"fork":false,"pushed_at":"2019-02-04T17:20:26.000Z","size":323,"stargazers_count":45,"open_issues_count":4,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T18:12:42.474Z","etag":null,"topics":["android","android-library","android-things","java","mifare","mifare1k","rc522","rfid","rfid-rc522"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Galarzaa90.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-28T20:16:27.000Z","updated_at":"2024-11-12T06:20:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c4c53c0-faca-4b76-a0a8-0c4b81742fd5","html_url":"https://github.com/Galarzaa90/android-things-rc522","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galarzaa90%2Fandroid-things-rc522","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galarzaa90%2Fandroid-things-rc522/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galarzaa90%2Fandroid-things-rc522/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galarzaa90%2Fandroid-things-rc522/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Galarzaa90","download_url":"https://codeload.github.com/Galarzaa90/android-things-rc522/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245836212,"owners_count":20680335,"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":["android","android-library","android-things","java","mifare","mifare1k","rc522","rfid","rfid-rc522"],"created_at":"2024-07-31T17:00:48.242Z","updated_at":"2025-03-27T11:31:45.270Z","avatar_url":"https://github.com/Galarzaa90.png","language":"Java","funding_links":[],"categories":["Useful links"],"sub_categories":["Drivers"],"readme":"# Android Things RC522\nAn Android Things libray to control RFID readers based on the RC522 reader.\n\nBased on [pi-rc522](https://github.com/ondryaso/pi-rc522) by user **ondryaso**\n\n[![Bintray](https://api.bintray.com/packages/galarzaa90/maven/android-things-rc522/images/download.svg)](https://bintray.com/galarzaa90/maven/android-things-rc522/_latestVersion)\n[![license](https://img.shields.io/github/license/Galarzaa90/android-things-rc522.svg)](https://github.com/Galarzaa90/android-things-rc522/blob/master/LICENSE.md)\n[![Android Things](https://img.shields.io/badge/android--things-0.7--preview-red.svg)](https://developer.android.com/things/preview/releases.html#preview-7)\n### Features\n* Detect MIFARE 1k tags (not tested in other tags)\n* Authenticate, read and write to tags\n* Change authentication keys and access bits (must be done manually)\n* Increment, decrement, transfer and restore for value blocks\n* Easier way of changing keys and access bits\n\n### Planned features\n* Helper functions\n* Better error handling\n\n## Connections\nThe connections vary based on the [board](https://developer.android.com/things/hardware/developer-kits.html) used.\n\n**RST** pin is configured programatically.\n\n### Raspberry Pi 3\n![rfid-rc522_bb](https://user-images.githubusercontent.com/12865379/33002472-ad7a712a-cd71-11e7-8724-d8e1433de13a.png)\n\n| RC522 Pin | RPi Pin name | RPi Pin number |\n| --------- | ------- | -------------- |\n| SDA | GPIO8, CE0 | 24\n| SCK | GPIO11, SCKL | 23\n| MOSI | GPIO10, MOSI | 19\n| MISO | GPIO9, MISO | 21\n| GND | GND | 6, 9, 20, 25\n| RST | Any GPIO pin | --\n| 3.3V | 3V3V | 1, 17\n\n\n## Installing\nThis library is available at jCenter. To install add this to your module's build.gradle\n```groovy\ndependencies {\n    compile 'com.galarzaa.android-things:rc522:1.0.0'\n```\n\n## Usage\n_The use of interruptions is not supported yet._\n\nThe RC522 must be polled until a card is found, and then \nperform any operations you want.\n\nUnfortunately, in Android, the UI thread shouldn't be blocked, so the polling has to be done on a \nseparate thread e.g. AsyncTask, Runnable, etc.\n\nTo use the libary, a `SpiDevice` object must be passed in the constructor, along with a `Gpio` object for\nthe RST pin.\n\n### Polling state\n```java\nimport com.galarzaa.androidthings.Rc522;\npublic class MainActivty extends AppCompatActivity{\n    private Rc522 mRc522;\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        PeripheralManagerService pioService = new PeripheralManagerService();\n        try {\n            /* Names based on Raspberry Pi 3 */\n            SpiDevice spiDevice = pioService.openSpiDevice(\"SPI0.0\");\n            Gpio resetPin = pioService.openGpio(\"BCM25\");\n            /* Names based on NXP Pico i.MX7D I/O */\n            SpiDevice spiDevice = pioService.openSpiDevice(\"SPI3.0\");\n            Gpio resetPin = pioService.openGpio(\"GPIO5_IO00\");\n            mRc522 = new Rc522(this, spiDevice, resetPin);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n    \n    private void readRFid(){\n        while(true){\n            boolean success = mRc522.request();\n            if(!success){\n                continue;\n            }\n            success = mRc522.antiCollisionDetect();\n            if(!success){\n                continue;\n            }\n            byte[] uid = mRc522.getUid();\n            mRc522.selectTag(uid);\n            break;\n        }\n        // Factory Key A:\n        byte[] key = {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF};\n        // Data that will be written\n        byte[] newData = {0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};\n        // Get the address of the desired block\n        byte block = Rc522.getBlockAddress(3, 2);\n        //We need to authenticate the card, each sector can have a different key\n        boolean result = rc522.authenticateCard(Rc522.AUTH_A, block, key);\n        if (!result) {\n            //Authentication failed\n            return;\n        }\n        result = rc522.writeBlock(block, newData);\n        if(!result){\n            //Could not write, key might have permission to read but not write\n            return;\n        }\n        //Buffer to hold read data\n        byte[] buffer = new byte[16];\n        //Since we're still using the same block, we don't need to authenticate again\n        result = rc522.readBlock(block, buffer);\n        if(!result){\n            //Could not read card\n            return;\n        }\n        //Stop crypto to allow subsequent readings\n        rc522.stopCrypto();\n            \n        \n    }\n}\n```\n\n## Contributing\nThis library is still in development, suggestions, improvements and fixes are welcome. Please \nsubmit a **pull request**\n\n## Resources\n* [This library's javadoc](https://galarzaa90.github.io/android-things-rc522/com/galarzaa/androidthings/Rc522.html)\n* [MFRC522 product data sheet, pdf, 95 pages](http://www.nxp.com/docs/en/data-sheet/MFRC522.pdf)\n* [MIFARE Classic EV1 1K tags data product data sheet, pdf, 20 pages](http://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGalarzaa90%2Fandroid-things-rc522","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGalarzaa90%2Fandroid-things-rc522","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGalarzaa90%2Fandroid-things-rc522/lists"}