Skip to the content
PCBKitNew board
2 layers65 × 56.5 mmPihat door, the printed circuit board in 3D

Pihat door

flipdot/door2

Scripts controlling our space access. Superseded by https://code.flipdot.org/flipdot/flipdoor.

Size
65 × 56.5 mm
Copper layers
2
Thickness
1.6 mm
Parts
35
Nets
78
Pads
151
Tracks, vias
295, 11
Pours
4
Routed
Yes
KiCad
KiCad 4
Created
26 Aug 2017
Updated
27 Oct 2026

Overview

Pihat door is an open-source printed circuit board by flipdot, from the flipdot/door repository on GitHub. It is a 2-layer board of 65 × 56.5 mm with 35 parts on 78 nets, routed with 295 tracks and 11 vias.

It is built around the PIC16LF77-I/PT, DMMT5401 and LM1117IMPX-ADJ, with the LM317T, BC547 and BSS138 among its other parts. Its parts include 10 resistors, 6 connectors, 5 capacitors, 4 ICs and 3 transistors. It belongs with the PIC boards of this library.

Main components

6

README

README.md

door

Door control system for the flipdot hackspace. It runs on a Raspberry Pi at the door together with a custom PCB in Raspberry Pi HAT form factor (pihat_door).

The current door control system is flipdot/flipdoor, a Rust project with web and SSH interfaces that serves door.flipdot.space. The Python implementation in this repository is legacy and no longer maintained. The sections below document that implementation and the hardware, which remain useful for reference.

The system:

  • continuously reads the door state (open/closed) from a switch on the door
  • unlocks/locks the door on request
    • from a web frontend (flipdot LDAP login, opening is restricted to flipdot members)
    • via RFID: members scan their card with a USB RFID reader
    • via MQTT close commands
  • publishes the door state to api.flipdot.org, where it is displayed on the flipdot.org status page

Repository layout

PathDescription
hardware/KiCad project for the pihat_door PCB
door_firmware.X/Firmware for the PIC microcontroller on the HAT (MPLAB X project, XC8, PIC16LF1719)
door_lib.pyShared Python library: serial access, door state, open/close, API update
web.pyFlask web frontend (login via LDAP, door state, open/close)
mqtt2door.pyMQTT bridge + RFID reader daemon
door.pySmall script that reads the door state and logs it to syslog
door_state.shShell helper that reads the door state from the serial port
acme.py, acme.sh/(legacy) TLS via Let's Encrypt/acme.sh; TLS is now handled by nginx
door-master.nginx.confExample nginx configuration (TLS, reverse proxy)
web.service, mqtt2door.servicesystemd units
sync.shSyncs authorized_keys for the opendoor user from LDAP
sync_rfid_tags.shRegenerates rfid_tags.json (employee numbers) from LDAP
config.example.pyConfiguration template (copy to config.py, see below)

The ldap_user/ and acme.sh/ submodules provide LDAP authentication and certificate handling respectively.

Hardware and serial protocol

The HAT carries a PIC16LF1719 that is wired to the Raspberry Pi GPIO header. It talks over a UART at 9600 baud 8N1 (config.SERIAL, default /dev/ttyAMA0).

The PIC continuously samples the door switch (ADC, averaged over 30 samples) and prints one line per batch:

text
<adc> - <ra0>\r\n
  • <adc>: 10-bit average of the door switch reading; values > 500 mean the door is open
  • <ra0>: digital input on pin RA0

Commands (single character, no newline required):

  • 1 – pulse the door open (~200 ms)
  • 0 – pulse the door closed (~200 ms)
  • anything else – echoed back

The PIC sends b at startup and r (followed by a UART re-init) when it hits a UART over-error. door_lib.get_state() skips lines that do not start with a number, so these are handled transparently.

Web frontend

web.py is a small Flask app:

  • login with flipdot LDAP credentials (ldap_user submodule)
  • shows the current door state (10 s cache, or fake data when config.fake_door is set)
  • "open door" button – only usable by flipdot members (is_member LDAP attribute)
  • "close door" button
sh
pip install -r requirements.txt
cp config.example.py config.py  # adjust DOMAIN, EMAIL, SERIAL, ...
./web.py

For production it runs under systemd (web.service) behind nginx (door-master.nginx.conf), which terminates TLS.

Set fake_door = True in config.py to run the app without the hardware.

MQTT and RFID

mqtt2door.py (run under systemd as mqtt2door.service) does three things:

  1. Connects to the MQTT broker at power.flipdot.space:1883 and closes the door on the actor/door/close topic (plus a raw ESP sensor topic).
  2. Polls the USB RFID reader on /dev/ttyUSB0. If the scanned tag is in rfid_tags.json, the door is opened, otherwise the event is only logged. sync_rfid_tags.sh regenerates rfid_tags.json from the employeeNumber attributes of all LDAP members, so member cards work automatically.
  3. Publishes the door state to https://api.flipdot.org/sensors/door/locked/<0|1> every 60 seconds.

Firmware

door_firmware.X/ is an MPLAB X project for the PIC16LF1719 on the HAT (build with the XC8 compiler, e.g. via MPLAB X IDE). See hardware/pihat_door.pro for the board design.

Configuration

Copy config.example.py to config.py (git-ignored) and adjust:

KeyMeaning
PORT, HTTPS_PORTPorts for the Flask app
SERIALSerial device of the HAT, e.g. /dev/ttyAMA0
DOMAIN, EMAILDomain and contact for certificate issuance
DEBUGVerbose logging
STAGINGUse the Let's Encrypt staging server
fake_doorSimulate the door state (for development)

Parts

35
QtyValueFootprintReferences
5CONN_01X02Connect:AK300-2P1, P2, P4, P5, P6
31kResistors_SMD:R_0805_HandSolderingR2, R4, R5
2BC547TO_SOT_Packages_THT:TO-92_Inline_WideQ2, Q3
2C_SmallCapacitors_SMD:C_0805_HandSoldering100n1, 100n2
10.1ufCapacitors_SMD:C_0805_HandSolderingC7
110kResistors_SMD:R_0805_HandSolderingR11
110uf/6.3VCapacitors_SMD:c_elec_6.3x7.7C6
11uCapacitors_SMD:c_elec_6.3x7.7C2
11ufCapacitors_SMD:C_0805_HandSolderingC8
1240Resistors_SMD:R_0805_HandSolderingR9
1330RResistors_SMD:R_0805_HandSolderingR1
1360Resistors_SMD:R_0805_HandSolderingR10
1390Resistors_SMD:R_0805_HandSolderingR8
147kResistors_SMD:R_0805_HandSolderingR12
14k7Resistors_SMD:R_0805_HandSolderingR3
150uf/50vCapacitors_SMD:c_elec_6.3x7.7C1
1BSS138TO_SOT_Packages_SMD:SOT-23_HandsolderingQ1
1DMMT5401TO_SOT_Packages_SMD:SOT-23-6U5
1LEDLEDs:LED-3MMD3
1LM1117IMPX-ADJPower_Integrations:TO-220U4
1LM317TPower_Integrations:TO-220U1
1PIC16(L)F77-I/PHousings_DIP:DIP-40_W15.24mmU2
1Raspberry_Pi_+_ConnConnect:IDC_Header_Straight_40pinsP3

The 31 most common of 35 parts.

Questions

How big is the Pihat door PCB?

It measures 65 × 56.5 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Pihat door use?

35 parts, built around the PIC16LF77-I/PT, DMMT5401, LM1117IMPX-ADJ and LM317T. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Pihat door KiCad files?

From the flipdot/door repository on GitHub, at the commit this page was made from: the board is hardware/pihat_door.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the Pihat door design in my own project?

Its repository states no licence, so its author keeps all rights: ask flipdot before reusing the design.

Similar boards

  • 2 layers171 × 56 mmSlushengine modelx lite, the printed circuit board in 3D

    Slushengine modelx lite

    Roboteurs/slushengine-modelx-lite

    Slushehgine model x lite version hardware files

    124 parts1
  • 2 layers65 × 56.5 mmPihat template, the printed circuit board in 3D

    Pihat template

    Sideous/kicad_old

    This is a project template for a Raspberry Pi B+ Hat.

    60 parts
  • 2 layers65 × 56.5 mmPihat template, the printed circuit board in 3D

    Pihat template

    UMONS-GFA/kicad-projects

    Open your .sch file -> Preferences -> Component libraries

    37 parts1
  • 2 layers151.3 × 50.8 mm6ch preamp, the printed circuit board in 3D

    6ch preamp

    dilshan/6ch-af-preamplifier

    5.1 channel audio preamplifier

    126 parts12MIT
  • 2 layers65 × 56 mmRDMA, the printed circuit board in 3D

    RDMA

    SkullKill/RDMA-PCB

    Rpi Dead Man Alarm - PCB and 3D case - Occupancy Monitoring - Raspberry Pi hat

    92 partsGPL-3.0
  • 4 layers133.8 × 102.9 mmVca backplane, the printed circuit board in 3D

    Vca backplane

    brer-rabbit/zoxnoxious

    Analog synth / software interface

    102 parts68GPL-3.0