Giter VIP home page Giter VIP logo

micropython-hz1050's Introduction

MicroPython HZ-1050 125 KHz RFID Reader

A MicroPython library for the HZ-1050 RFID reader.

demo

Pins

Unless you are planning on reprogramming the Atmega8 brains of this module, you can ignore the 6 pin header on the left.

This module outputs on both UART (TXD) and Wiegand (D0,D1) pins. On detection, UART first, then ~600ms later Wiegand.

To use the UART interface, all you need to connect is 5V, GND, TXD on the right side.

To use the Wiegand interface, connect to 5V, GND, D0, D1.

pins

UART

The serial data consists of 4 bytes with no preamble, postamble or parity bits.

My example blue EM4100 keyfob is engraved with code 0003069055, which in hex is 0x002ED47F.

When detected, a UART read returns b'\x00.\xd4\x7f', which equates to b'\x00\x2E\xD4\x7F' and matches the keyfob in hex.

The 4 bytes (32 bits) match what you receive via Wiegand W34 when you strip the leading and trailing parity bits.

The first 2 bytes are whats known as the facility code, and the last 2 bytes are the card number.

Wiegand W26 differs to W34 in that it only has a 1 byte facility code.

from machine import UART
uart1 = UART(1, baudrate=9600, tx=14, rx=4)

# callback to run on detection
def cb(code, facility, card):
	print('Code: {}, Facility: {}, Card: {}'.format(code, facility, card))

# poll the uart
def uart_demo(callback):
	buf = bytearray(4)
	while True:
		if uart1.any():
			uart1.readinto(buf)
			code = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]
			facility = code >> 16
			card = code & 0xFFFF
			callback(code, facility, card)

# run the demo
uart_demo(cb)

# scan my blue EM4100 tag with engraving "0003069055"
Code: 3069055, Facility: 46, Card: 54399

# scan my pink EM4100 tag with engraving "0008123291"
Code: 8123291, Facility: 123, Card: 62363

# scan my yellow EM4100 tag with engraving "0012459289"
Code: 12459289, Facility: 190, Card: 7449

Wiegand

The two Wiegand data pins D0 and D1 are held HIGH until a card is detected.

On detection, the 24 or 32 bit card number (based on W26/W34 jumper) is transmit with a leading and trailing parity bit.

The 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

A logic 0 is when D0 goes LOW and D1 stays HIGH.

A logic 1 is when D1 goes LOW and D0 stays HIGH.

Data is sent MSB first.

Features

  • UART baud rate 9600 or 19200
  • Wiegand selection 26 or 34 bit
  • Read only support for EM4100, 4001 etc
  • Frequency 125KHz
  • Read time <0.2s
  • Read distance 3-10cm
  • Delay between reads 800ms
  • Operating voltage 3.3 - 5.5V

I tried running this board on 3.3V but it failed to detect any cards at all.

I had to power the board with 5V and use a level shifter to convert the 5V TXD down to 3V3.

Parts

Connections

TinyPICO ESP32

from machine import UART
uart1 = UART(1, baudrate=9600, tx=14, rx=4)

This is a read only module, so only using the RX pin on the UART.

HZ-1050 Level Shifter TinyPICO (ESP32)
VCC HV 5V
GND GND GND
- LV 3V3
TXD H0 -
- L0 4 (RX)

Links

License

Licensed under the MIT License.

Copyright (c) 2020 Mike Causer

micropython-hz1050's People

Contributors

mcauser avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

micropython-hz1050's Issues

Invalid second read

When I place a tag it will read twice. The first read is correct, the second is not.
This one is the blue chip
Code: 1016577, Facility: 15, Card: 33537
Code: -1928363263, Facility: -29425, Card: 33537

This one is the card that comes with the rfid module
Code: 15337849, Facility: 234, Card: 2425
Code: -1695938183, Facility: -25878, Card: 2425

PXL_20210210_064836871

RFID module is connected directly to 3.3V/GND and RX (in my case pin 25 on tinyPico).

Remove struct dependency

Using struct for this one line:

code = struct.unpack('>i',buf)[0]

Could be changed to this to remove the dependency:

code = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.