{"id":22253927,"url":"https://github.com/mcauser/micropython-hz1050","last_synced_at":"2025-03-25T12:26:39.384Z","repository":{"id":150620662,"uuid":"298121303","full_name":"mcauser/micropython-hz1050","owner":"mcauser","description":"MicroPython driver for HZ-1050 UART and Wiegand 125Khz RFID Reader","archived":false,"fork":false,"pushed_at":"2021-02-18T14:36:15.000Z","size":386,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T11:28:12.681Z","etag":null,"topics":["125khz","em4100","hz-1050","micropython","rfid","rfid-reader","wiegand"],"latest_commit_sha":null,"homepage":"","language":null,"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/mcauser.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-23T23:47:41.000Z","updated_at":"2023-05-06T09:53:53.000Z","dependencies_parsed_at":"2023-05-06T09:32:10.706Z","dependency_job_id":null,"html_url":"https://github.com/mcauser/micropython-hz1050","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hz1050","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hz1050/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hz1050/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-hz1050/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcauser","download_url":"https://codeload.github.com/mcauser/micropython-hz1050/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245460772,"owners_count":20619139,"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":["125khz","em4100","hz-1050","micropython","rfid","rfid-reader","wiegand"],"created_at":"2024-12-03T07:21:04.729Z","updated_at":"2025-03-25T12:26:39.326Z","avatar_url":"https://github.com/mcauser.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MicroPython HZ-1050 125 KHz RFID Reader\n\nA MicroPython library for the HZ-1050 RFID reader.\n\n![demo](docs/demo.jpg)\n\n\n## Pins\n\nUnless you are planning on reprogramming the Atmega8 brains of this module, you can ignore the 6 pin header on the left.\n\nThis module outputs on both UART (TXD) and Wiegand (D0,D1) pins. On detection, UART first, then ~600ms later Wiegand.\n\nTo use the UART interface, all you need to connect is 5V, GND, TXD on the right side.\n\nTo use the Wiegand interface, connect to 5V, GND, D0, D1.\n\n![pins](docs/pins.jpg)\n\n\n## UART\n\nThe serial data consists of 4 bytes with no preamble, postamble or parity bits.\n\nMy example blue EM4100 keyfob is engraved with code 0003069055, which in hex is 0x002ED47F.\n\nWhen detected, a UART read returns b'\\x00.\\xd4\\x7f', which equates to b'\\x00\\x2E\\xD4\\x7F' and matches the keyfob in hex.\n\nThe 4 bytes (32 bits) match what you receive via Wiegand W34 when you strip the leading and trailing parity bits.\n\nThe first 2 bytes are whats known as the facility code, and the last 2 bytes are the card number.\n\nWiegand W26 differs to W34 in that it only has a 1 byte facility code.\n\n```python\nfrom machine import UART\nuart1 = UART(1, baudrate=9600, tx=14, rx=4)\n\n# callback to run on detection\ndef cb(code, facility, card):\n\tprint('Code: {}, Facility: {}, Card: {}'.format(code, facility, card))\n\n# poll the uart\ndef uart_demo(callback):\n\tbuf = bytearray(4)\n\twhile True:\n\t\tif uart1.any():\n\t\t\tuart1.readinto(buf)\n\t\t\tcode = (buf[0] \u003c\u003c 24) | (buf[1] \u003c\u003c 16) | (buf[2] \u003c\u003c 8) | buf[3]\n\t\t\tfacility = code \u003e\u003e 16\n\t\t\tcard = code \u0026 0xFFFF\n\t\t\tcallback(code, facility, card)\n\n# run the demo\nuart_demo(cb)\n\n# scan my blue EM4100 tag with engraving \"0003069055\"\nCode: 3069055, Facility: 46, Card: 54399\n\n# scan my pink EM4100 tag with engraving \"0008123291\"\nCode: 8123291, Facility: 123, Card: 62363\n\n# scan my yellow EM4100 tag with engraving \"0012459289\"\nCode: 12459289, Facility: 190, Card: 7449\n```\n\n\n## Wiegand\n\nThe two Wiegand data pins D0 and D1 are held HIGH until a card is detected.\n\nOn detection, the 24 or 32 bit card number (based on W26/W34 jumper) is transmit with a leading and trailing parity bit.\n\nThe leading parity bit is an even parity of the first 12 bits and the trailing parity is an odd parity bit of the last 12 bits\n\nA logic 0 is when D0 goes LOW and D1 stays HIGH.\n\nA logic 1 is when D1 goes LOW and D0 stays HIGH.\n\nData is sent MSB first.\n\n\n## Features\n\n* UART baud rate 9600 or 19200\n* Wiegand selection 26 or 34 bit\n* Read only support for EM4100, 4001 etc\n* Frequency 125KHz\n* Read time \u003c0.2s\n* Read distance 3-10cm\n* Delay between reads 800ms\n* Operating voltage 3.3 - 5.5V\n\nI tried running this board on 3.3V but it failed to detect any cards at all.\n\nI had to power the board with 5V and use a level shifter to convert the 5V TXD down to 3V3.\n\n\n## Parts\n\n* [TinyPICO](https://www.tinypico.com/) $20.00 USD\n* [HZ-1050](https://www.aliexpress.com/item/32925644547.html) $3.39 AUD\n* [Level shifter](https://www.aliexpress.com/item/1972789887.html) $2.15 AUD\n* [10x EM4100 125KHz read only tags](https://www.aliexpress.com/item/32434392248.html) $2.52 AUD\n\n\n## Connections\n\n### TinyPICO ESP32\n\n```python\nfrom machine import UART\nuart1 = UART(1, baudrate=9600, tx=14, rx=4)\n```\n\nThis is a read only module, so only using the RX pin on the UART.\n\nHZ-1050 | Level Shifter | TinyPICO (ESP32)\n------- | ------------- | ----------------\nVCC     | HV            | 5V\nGND     | GND           | GND\n\\-      | LV            | 3V3\nTXD     | H0            | \\-\n\\-      | L0            | 4 (RX)\n\n\n## Links\n\n* [micropython.org](http://micropython.org)\n* [TinyPICO Getting Started](https://www.tinypico.com/gettingstarted)\n* [RFID on wikipedia](https://en.wikipedia.org/wiki/Radio-frequency_identification)\n* [Wiegand on wikipedia](https://en.wikipedia.org/wiki/Wiegand_interface)\n* [EM4100 Protocol](http://www.priority1design.com.au/em4100_protocol.html)\n\n## License\n\nLicensed under the [MIT License](http://opensource.org/licenses/MIT).\n\nCopyright (c) 2020 Mike Causer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-hz1050","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcauser%2Fmicropython-hz1050","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-hz1050/lists"}