From 2e326d3ca6495bd88aaa1fe960ba8a83a67eed29 Mon Sep 17 00:00:00 2001 From: Jason Antman Date: Wed, 25 Nov 2026 17:26:46 -0500 Subject: [PATCH 1/2] Custom MCU PCB - add V2 hardware research doc (#208) Research doc for a custom PCB to replace the V1 COTS assembly in the MAC MCU box, in the feature-doc format so its implementation plan can follow once approved. No firmware, ESPHome config or server changes. - Enclosure constraints first: base-mounted 90x70 mm board with keyed JST-XH cables to lid parts, keep M12 A-coded 8-pin and V1 pinout, IP54/IP65 and temperature targets, antenna/metal keep-outs. - ESP32-WROOM-32E-N4 (WROOM-32D is NRND), same esp32dev pin map, so the existing config works unchanged. - Relay stays a pilot contact only: M12 8-pin is rated 30 V / 2 A, so mains must not run through pins 3/4. Fail-safe low-side driver, second-relay output ANDed with primary drive in hardware. - Tamper moved off strapping pin GPIO12 to GPIO35; CT input on GPIO36; DNP external watchdog footprint; EN supervisor; input/ESD protection. - Draft BOM with LCSC prices looked up 2026-11-25, JLCPCB fees, and a cost comparison against V1 (roughly cost-neutral). - Open questions for Jason (unit count, machine list, mains on M12, fob technology, outdoor scope, hardware/v2_mcu layout). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KQ8DrLoknL3m1Wq3Um6vAe --- docs/features/custom-mcu-pcb.md | 634 ++++++++++++++++++++++++++++++++ 1 file changed, 634 insertions(+) create mode 100644 docs/features/custom-mcu-pcb.md diff --git a/docs/features/custom-mcu-pcb.md b/docs/features/custom-mcu-pcb.md new file mode 100644 index 0000000..7b95709 --- /dev/null +++ b/docs/features/custom-mcu-pcb.md @@ -0,0 +1,634 @@ +# Custom MCU PCB (V2 Hardware) + +You must read, understand, and follow all instructions in `./README.md` when planning and implementing this feature. + +## Overview + +Research and recommend a custom PCB to replace the off-the-shelf (COTS) assembly inside the +[Version 1 MCU box](../source/hardware.rst) (ESP32 dev board on a screw-terminal breakout, level +converter, relay module, and point-to-point wiring to the reader, LCD, LED, button and M12 +connector). Tracked in GitHub issue #208. + +**This document is research, not a finished design.** It is written in the feature-doc format so +that, once Jason approves the recommendations, the "Implementation Plan" section below becomes the +plan for the actual board. A feature doc is a reasonable container for this: the research is the +planning phase of the feature. If Jason would rather keep research and the build plan separate, the +research sections can move to a dated `docs/YYYY-MM-DD-*.md` analysis doc like the existing +lockup analyses. + +**Status:** research complete; **awaiting Jason's answers to the open questions and approval of the +recommendations before any design work.** Nothing has been ordered and no firmware or ESPHome +config has been changed. + +Conventions used below: + +* **[confirmed]**: verified from this repo, a datasheet, or a distributor page (cited). +* **[assumed]**: inferred, not confirmed. Each one needs checking by Jason or on a prototype. +* Prices were looked up on **2026-11-25** from the cited distributor pages; they are not estimates. + +## 1. Constraints for the enclosure effort + +These are stated first so the hardened enclosure for movable tools (Trello card "Design hardened +MAC MCU enclosure for movable tools") can start from them. Board numbers are targets until the +first layout is done; the enclosure should budget for the "envelope" figures, which include margin. + +### 1.1 Architecture that drives the enclosure + +**Recommendation: one controller board mounted to the enclosure base, with every lid-mounted part +on a keyed, latching cable.** The LCD, status LED, Oops button and RFID reader stay separate parts +mounted to the lid (as in V1) and plug into the board on JST-XH 2.5 mm headers. The M12 connector +is panel-mounted in the enclosure wall and its leads land on an 8-position pluggable terminal block +on the board. + +Why, compared with putting the UI parts on the PCB and mounting the board behind the lid: + +* The enclosure keeps free placement of the LCD window, button, LED and card pocket, so one board + serves the existing V1-style box and a hardened outdoor box with a different layout. +* The RFID antenna can sit right behind the card pocket and away from the board's ground pour and + the ESP32 antenna (see 1.5). +* The 16 mm button has a deep body behind the panel, which would collide with a board mounted + directly behind the lid. +* Cost: a board-behind-the-lid layout needs the board to be at least as wide as the LCD plus the + card pocket (about 170 x 100 mm), which is above JLCPCB's 100 x 100 mm price break, and it puts + parts on both faces (LCD and LED on the front, SMT on the back), which pushes assembly to + double-sided. + +What this does not fix: there are still five cables inside the box. They are crimped, keyed and +latching instead of hand-soldered or screw-terminal joints, which removes the wiring errors and +loose-wire failures but not the cables themselves. + +### 1.2 Board outline and mounting + +| Item | Target | Notes | +|---|---|---| +| Board outline | 90 x 70 mm, 1.6 mm FR-4, 2 layers | [assumed] fits after layout; first layout may shrink it to about 80 x 60 mm | +| Enclosure envelope to reserve | 100 x 80 mm footprint | includes margin for cables bending off the headers | +| Mounting holes | 4 x M3 (3.2 mm plated), 4 mm from each edge | pattern 82 x 62 mm for the 90 x 70 outline; matches the M3 hardware already used in V1 | +| Height above board (component side) | 20 mm max | tallest parts are the relay (about 16 mm) and the pluggable terminal plug with wires | +| Height below board | 3 mm (THT lead stubs) | use standoffs of at least 5 mm | +| Single-sided SMT | yes | all SMT on the top face; THT connectors and relay on the top face too | +| ESP32 antenna | module antenna overhangs or sits at a board edge | keep metal, wires and the ground pour 15 mm clear of the antenna; enclosure must be non-metallic in front of it | + +### 1.3 Lid parts (unchanged in size from V1) + +All dimensions are from `hardware/v1_mcu/*.scad` [confirmed]. + +| Part | Size | Cable to board | +|---|---|---| +| 16x2 LCD with I2C backpack | 80.1 x 38.6 mm PCB, 17.5 mm total depth including backpack (`lcd.scad`) | 4-pin JST-XH (5 V, GND, SDA, SCL) | +| Wiegand RFID reader | 47.2 x 26.2 mm PCB, 25.4 mm square antenna, 4.7 mm deep (`rfid.scad`) | 5-pin JST-XH (VCC, GND, D0, D1, CST) | +| 16 mm Oops button | 16 mm panel hole (`oops_button.scad`) | 4-pin JST-XH (switch, switch return, LED+, LED-) | +| Status LED (WS2812-type) | 12 mm module as V1, or any WS2812-type pixel | 3-pin JST-XH (5 V, GND, data) | + +### 1.4 External connector + +**Recommendation: keep the M12 A-coded 8-pin connector and the V1 pinout**, with the box carrying +a panel-mount female socket with wire leads (as V1) rather than a PCB-mount socket. The M12 is an +industrial sensor connector with a threaded coupling ring, which survives vibration and being moved +far better than friction connectors, prewired cables are cheap and widely stocked, and every +deployed V1 junction box already has the mating cable. + +Constraint this places on the enclosure: one M16 x 1.5 or Pg9 threaded panel hole (check the +chosen socket's datasheet; for example Phoenix Contact 1436343 is a rear-mount Pg9 socket with +solder cups, IP67), with a flat sealing face for the O-ring, and a protective cap on a +lanyard for movable units so an unplugged socket stays sealed. + +Important rating limit: **M12 A-coded 8-pin connectors are rated 30 V and 2 A per contact** (Phoenix Contact 1436343 datasheet: IP67, 30 V, 2 A at 40 °C [confirmed]; the V1 Amazon part has no published rating and is [assumed] to be the same class). +That is a low-voltage connector. Anything switched through pins 3 and 4 must stay within that +rating; see section 5 (Load switching). + +Alternatives considered: + +* **GX16-8 (V1's original choice):** cheaper, but no IP rating worth relying on and the doc + already moved away from it for cable availability. +* **M12 PCB-mount socket:** saves the pigtail, but fixes the connector to a board edge and makes the + board position dictate the enclosure wall. Rejected for the reason in 1.1. +* **Separate mains and signal connectors (for example an IEC inlet plus M12):** only needed if the + box ever switches mains itself, which this document recommends against. + +### 1.5 RFID antenna placement + +* The reader reads through the plastic lid; the card sits in the external pocket. A sealed lid is + fine for RFID. [confirmed from V1 design: the reader is under the lid behind the card holder] +* Keep at least 25 mm between the reader antenna and any metal, including a cast-iron tool body + behind the box, the board's ground pour, and the ESP32 module. [assumed rule of thumb for + 125 kHz readers; verify read range on a prototype mounted on a metal machine] +* The enclosure must be non-metallic (or have a non-metallic window) over the reader and in front of + the ESP32 antenna. A die-cast aluminium "hardened" box would break both RFID and WiFi. + +### 1.6 Environmental targets + +| Item | Indoor (V1-style) box | Hardened / movable / outdoor box | +|---|---|---| +| IP rating | IP54 | IP65 | +| Operating ambient | 0 to +40 °C | -10 to +50 °C ambient; +70 °C inside a box in direct sun [assumed] | +| Humidity | non-condensing | condensing possible; add a vent membrane and consider conformal coat | + +How these affect part choice: + +* The **LCD is the weakest part for temperature**: standard 16x2 HD44780 modules are rated + 0 to +50 °C [assumed: typical HD44780 rating; no rating was given on the distributor page checked]. An outdoor unit needs an extended-temperature LCD (usually -20 to +70 °C) or should + be shaded. All board parts in the BOM below are rated -40 to +85 °C or better. +* **IP65** needs: a gasketed lid, a sealed LCD window (glued or gasketed clear panel), an IP65 or + better 16 mm button (the V1 button has no stated IP rating [assumed]; the V1 cover helps with + dust but not water jets; an IP65 option is in the BOM), the M12 cap, and no open card slot (the external card pocket is fine). +* Condensation: a sealed box that heats and cools breathes moisture in. A small ePTFE vent plug and + a conformal coat on the board are the usual fixes. Conformal coat complicates hand rework, so it + is listed as optional for the outdoor build only. + +## 2. Known problems and how the board addresses them + +| # | Problem | Hardware or firmware/server? | Board's answer | +|---|---|---|---| +| 1 | Machine starts on the next login after an Oops clear because the machine's own switch was left ON (`docs/2026-11-21-oops-clear-power-on-analysis.md`) | **Hardware gap at the machine**, not the MCU | The board cannot see the machine switch while its relay is open. Real fix: NVR or magnetic switches on the machines. Board adds a current-transformer input so future firmware can detect current flowing the instant the relay closes and open it again (section 8). | +| 2 | MCUs wedged for 22 h and 40 min while WiFi-associated (`docs/2026-05-05-*` and `docs/2026-05-11-*`) | **Firmware/server** root causes, already fixed in firmware (bounded HTTP, liveness watchdog, task WDT panic) | Board adds a proper reset supervisor on EN and a footprint for an external watchdog timer, not populated by default because using it needs a firmware change (section 7). | +| 3 | Relay state at boot / brown-out | Hardware | Low-side MOSFET relay driver with a gate pull-down, so the relay is open whenever the GPIO is high-impedance (reset, boot, brown-out). Tamper input moved off strapping pin GPIO12. Second-relay output gated in hardware by the primary relay drive (section 5). | +| 4 | Hand-wired COTS stack | Hardware | One assembled board with keyed cables (section 1.1). | +| 5 | No current sensing, no tamper; second relay optional | Hardware + future firmware | Board provides tamper input, CT input and the second-relay output on the existing M12 pins; firmware for tamper and current is proposed only (section 10). | + +Which parts of problem 4 are confirmed versus assumed: + +* **[confirmed]** Point-to-point wiring between dev board, breakout, level converter, relay module, + reader, LCD, LED and button (`docs/source/hardware.rst` wiring list). +* **[confirmed]** The reader needs a solder blob on `S2` for Wiegand mode, and is a single-source + AliExpress part (same doc, note 5). +* **[confirmed]** Power is a bare 5 V feed on M12 pins 1 and 2 with no documented protection. +* **[assumed]** That these have caused field failures. Nothing in the repo records a wiring or + power failure; the documented lockups were firmware/server. **Jason: have any units failed from + loose wiring, the breakout terminals, or the power feed?** + +## 3. Recommended architecture + +```mermaid +flowchart LR + subgraph M12["M12 A-coded 8-pin (panel, wire leads)"] + P1["1 +5V in"] + P2["2 GND"] + P34["3/4 relay COM/NO"] + P5["5 tamper"] + P6["6 2nd relay out"] + P78["7/8 CT clamp"] + end + subgraph Board["Controller board"] + PROT["Input protection: PTC fuse, reverse-polarity PFET, TVS"] + LDO["3.3 V LDO, 1 A"] + SUP["Reset supervisor on EN (+ optional ext. watchdog, DNP)"] + ESP["ESP32-WROOM-32E-N4"] + USB["USB-C + CH340C + auto-reset, BOOT/EN buttons"] + RLY["Relay driver (NMOS + pull-down) + 5 V relay"] + AND["AND gate: GPIO14 AND relay drive"] + LS["5 V level shift: I2C (PCA9306), LED data (74AHCT1G125)"] + RIN["Reader input buffer (74LVC125A, 5 V tolerant)"] + ESD["ESD arrays on all off-board signals"] + CT["CT bias + burden -> ADC1"] + end + P1 --> PROT --> LDO --> ESP + P2 --- PROT + SUP --> ESP + USB --> ESP + ESP -- GPIO33 --> RLY --> P34 + ESP -- GPIO14 --> AND --> P6 + RLY -. drive .-> AND + P5 --> ESD --> ESP + P78 --> CT --> ESP + ESP -- GPIO22/23 --> LS --> LCD["16x2 LCD (PCF8574, 5 V)"] + ESP -- GPIO27 --> LS --> LED["WS2812 status LED"] + READER["Wiegand reader"] --> RIN --> ESP + BTN["Oops button + LED"] --> ESD +``` + +Summary of the decisions (each is argued in the numbered sections that follow): + +* ESP32-WROOM-32E-N4 module, same `esp32dev` ESPHome board, same GPIOs as V1 for everything the + current config uses. +* Wiegand reader stays a separate module on a header, now with a 5 V-tolerant input buffer and a + selectable 3.3 V / 5 V reader supply so more Wiegand readers fit. +* 16x2 PCF8574 LCD and WS2812-type LED stay; the board does the 5 V level shifting. +* One on-board relay as a low-voltage pilot contact for an external contactor/SSR; external + contactor stays mandatory for motor loads. +* 5 V input stays, with real input protection. No mains on the board. + +## 4. MCU module + +**Recommendation: ESP32-WROOM-32E-N4.** + +* It is the current revision of the module V1 already uses (WROOM-32D is marked "Not Recommended for New Designs" on its datasheet, v2.8 [confirmed]). Same chip + family, same pinout, same 4 MB flash, so `board: esp32dev` and the existing config work + unchanged. 4 MB is what V1 has today and is enough for ESPHome with OTA (two app partitions). + [confirmed for V1 today: the deployed config builds and OTAs on 4 MB dev boards] +* ESPHome support for the classic ESP32 is the most mature of any Espressif part. [assumed: it was ESPHome's first ESP32 target; ESPHome's docs do not name the WROOM-32E with `esp32dev` explicitly, but `esp32dev` is the generic 4 MB ESP32 definition] +* Availability: Espressif's longevity commitment lists the ESP32 (classic) chip for at least 15 years from 2016-01-01 (the module is not listed separately), and LCSC showed 38,735 WROOM-32E-N4 in stock [confirmed, 2026-11-25]. +* It is on JLCPCB's parts library (see BOM), so the PCB service can place it; it can also be + hand-soldered (castellated pads) for the hand-assembly path. + +Alternatives: + +* **ESP32-S3-WROOM-1:** USB built in (would drop the CH340C), more RAM. But a different chip means a + different `board:` and different GPIO capabilities, so the config would change in several places, + against the "minimal firmware changes" constraint, and it buys nothing this application needs. +* **ESP32-C3 / C6:** cheaper, but fewer GPIOs (the design uses 13 signals plus programming pins) and + a different config. Not worth it. + +## 5. Load switching + +Ratings needed are **unknown**: the repo has no list of controlled machines with voltages and +full-load amps. **Jason: please list each machine (or planned machine) with supply voltage, FLA, +and how V1 switches it today (box relay directly, external relay, contactor, SSR, coil voltage).** + +**Recommendation: keep V1's design intent and make it explicit: the box's relay is a low-voltage +pilot contact only; an external contactor or SSR in a junction box switches the machine.** + +* The M12 A-coded 8-pin connector is rated 30 V and 2 A per contact (section 1.4). Mains on pins 3 and 4 would be outside the + connector's rating and would put mains in the same cable as the 5 V supply and GPIO lines. So + the relay contact on pins 3/4 should switch only SELV: a 24 VAC/VDC contactor coil, a 5 V or + 12 V relay coil, an SSR's DC input, or a machine's own low-voltage control circuit. + **[assumed] that no deployed unit runs mains through the M12 today; Jason please confirm.** If + some do (for example a 120 VAC contactor coil), those junction boxes should get an interposing + 5 V relay or SSR powered from the 5 V supply already in the junction box. +* On-board relay: a 5 V coil relay rated at least 5 A, with **reinforced coil-to-contact + insulation** (the Hongfa HF115F/005-1HS3 has 5 kV coil-contact dielectric strength, 10 mm creepage and reinforced insulation per VDE 0700/0631 [confirmed from a copy of the Hongfa datasheet, not from hongfa.com]), even though only SELV should be switched. That is cheap insurance + against a junction box wired wrong. Add a board slot between coil and contact copper, and keep + at least 8 mm creepage from the contact traces to anything on the logic side, so the board does + not rely on the "SELV only" rule for safety. +* Contact rating for inductive loads: a contactor coil has an inrush of several times its holding + current. Size the relay for that (5 A or more resistive gives margin), and fit suppression at the + coil in the junction box: a flyback diode for DC coils, an RC snubber or MOV for AC coils. + [assumed] that the coil inrush of the contactors in use is under the M12's 2 A per contact; this + needs checking against the contactor datasheets once Jason lists them. +* Relay driver: AO3400A N-MOSFET low-side, 10 kΩ gate pull-down, 1N4148W flyback across the coil. + The relay is open whenever GPIO33 is not actively driven high: during reset, during boot (all + GPIOs come up as inputs), in brown-out reset, and with the ESP32 removed or unpowered. + GPIO33 is not a strapping pin. Espressif's IO_MUX table (ESP32 datasheet, Appendix A) shows GPIO33 with output and input disabled and no pull at and after reset [confirmed]. +* SSR on board: rejected. A triac SSR leaks current when off (an "off" machine can still have a + few mA on its terminals), needs a heatsink above a few amps, and puts mains on the board. +* **Second relay (M12 pin 6):** V1 wires GPIO14 straight to pin 6 as a 3.3 V logic output that + drives an external relay module. V2 keeps pin 6 as a 3.3 V logic output so existing second-relay + junction boxes still work, but drives it through a 74LVC1G08 AND gate whose inputs are GPIO14 + and the primary relay drive, with a series resistor and ESD clamp on the output. That enforces in + hardware what the server already does (the second relay only energizes while the primary relay + does), and it masks anything GPIO14 does during boot while GPIO33 is low. Espressif's IO_MUX table shows GPIO14 with its weak pull-up **enabled** after reset until firmware configures the pin [confirmed], so on V1 the external relay module on pin 6 sees a weakly pulled-up line during boot; whether that is enough to trigger a given module is [assumed] and should be scoped on a V1 unit. The often-repeated "GPIO14 outputs PWM at boot" claim has no Espressif source that could be found. + No firmware change. + +What the relay does on any reset: **it opens.** With a normal (non-latching) relay there is no +way to keep a load on through an ESP32 reset without adding a hold circuit, and the constitution +requires relays to default off. The firmware already avoids self-reboots while the relay is on +(the liveness watchdog defers), so a reset that drops the load only happens when the firmware is +too wedged to run its own watchdog, and in that state the Oops button does not work either. See +section 7. + +## 6. Power input + +**Recommendation: keep an external 5 V supply via M12 pins 1 and 2. No mains on the board.** + +* Mains on the board would mean: mains creepage and clearance on the board, a fuse and probably a + certified PSU module, an earth-bonded or double-insulated enclosure rated for mains, and mains in + the box next to a reader the user touches. V1 already has a 5 V supply in the junction box (or + uses the machine's own supply), so there is no gain worth that. +* Wide-input (for example 12 or 24 V via a buck converter) was considered, because many machines + have 24 V control supplies. It would change the meaning of M12 pin 1 for every deployed junction + box, so it is listed as an open question rather than recommended. +* 3.3 V rail: a 1 A LDO (AP7361C-33) from 5 V. The ESP32 draws up to about 500 mA in WiFi + transmit bursts [confirmed, Espressif datasheet]; AMS1117 is cheaper but its 1.1 V dropout + leaves little margin once the input protection drops a few hundred mV, so it is not + recommended. +* 5 V budget [assumed, to measure on a prototype]: ESP32 about 250 mA average, LCD backlight about + 30 mA, relay coil about 80 mA (HF115F 5 V coil, 62 Ω), WS2812 up to 60 mA at full white, reader about 50 mA. Under + 0.5 A in total, well within V1's 2.5 A supply and the M12's 2 A per contact. + +## 7. Protection, reset and watchdog + +Input (M12 pins 1/2): + +* PTC resettable fuse, 1.1 A hold (1812). +* Reverse-polarity protection: AO3401A P-MOSFET (lower drop than a Schottky diode). +* TVS diode, SMBJ5.0A, after the fuse. +* Bulk capacitance (47 to 100 µF) plus a ferrite on the 5 V rail feeding the relay coil, to keep + relay switching and motor noise away from the 3.3 V LDO. + +Signals: + +* ESD arrays (SRV05-4 or similar) on every off-board signal: reader D0/D1/CST, button switch and + LED, LED data, I2C, M12 pins 5, 6, 7, 8. +* Series resistors (about 100 to 330 Ω) on off-board inputs so the ESD diodes are not the only + current limit. +* The relay contact side (M12 pins 3/4) is isolated from logic by the relay itself and the board + slot; no ESD parts on it. + +Reset and brown-out: + +* ESP32 internal brown-out detector stays on (ESPHome default) [assumed default, verify]. +* **Voltage supervisor on EN** (APX803-class, about 2.9 to 3.1 V threshold) instead of the usual + RC on EN. The plain RC is known to give unreliable starts on slowly rising supplies such as a + long cable or a soft-start supply [assumed from common ESP32 practice]. The supervisor holds the + chip in reset until 3.3 V is good and resets it cleanly on a sag. + +External watchdog (problem 2): + +* The lockups in the analysis docs were the main loop stuck inside an HTTP call that kept feeding + the task watchdog. The firmware now bounds that call and panics the task WDT (60 s), and enables + the RTC watchdog. An external watchdog would add an independent check that the ESPHome main loop + is alive, in case the on-chip watchdogs are ever misconfigured again. +* The case it covers is "loop dead", and in that case the Oops button and LCD are dead too, so + resetting and dropping the relay is the safe outcome. The case where Bronte deliberately kept its + relay on mid-cut was "loop alive, server unreachable", which the firmware handles and the + external watchdog would never see, as long as it is kicked from the main loop. +* **Recommendation: footprint only, not populated by default.** A TPL5010 timer (resistor-set + timeout) with its reset output into EN, a timeout of about 120 s (longer than the 60 s task WDT, + so the on-chip watchdog fires first), kicked from a spare GPIO (GPIO25) by an ESPHome + `interval:`. Populating it needs that firmware change, which is out of scope here. A DNP + resistor in the reset path keeps it from doing anything until it is deliberately enabled. +* EN reset is enough; a full power cycle of the board is not needed, because an EN reset restarts + the ESP32 exactly as a power cycle does and the LCD/reader recover on their own [assumed, the + analysis docs recovered with power cycles, never EN resets; verify on a prototype]. + +## 8. Current sensing and the "machine switch left ON" problem + +* **The board cannot detect the machine switch position while its relay is open**, because no + current flows and the board (by design) sees no mains. The only pre-emptive fixes are at the + machine: an NVR (no-volt release) paddle switch or a magnetic starter, which drops out when power + is removed and so cannot be "left ON", or an auxiliary contact on the machine switch wired back + to an input. NVR switches are the standard practice and the recommendation for problem 1. +* What a current input adds: after the relay closes on a login, firmware can see current within a + few hundred ms. Firmware could then open the relay and show "turn machine switch off" if current + appears before the operator presses start. The motor would still twitch. That is a mitigation, + not a fix. +* **Recommendation: include the CT input now, firmware later.** It is a handful of passives: a + burden resistor (or none, for a voltage-output CT), a 1.65 V mid-rail bias, an RC filter and an + ESD clamp, into ADC1 on GPIO36 (ADC2 cannot be used with WiFi on). ADC1 is GPIO32 to 39 per the ESP-IDF GPIO docs [confirmed].. Sensor: a split-core + voltage-output CT such as the YHDC SCT-013-030 (30 A, 1 V output) clamped on one machine + conductor inside the junction box, wired to M12 pins 7 and 8. ESPHome supports this through the + `ct_clamp` sensor platform. [confirmed: https://esphome.io/components/sensor/ct_clamp/; reads an `adc` sensor, needs `attenuation` set because the ESP32 ADC tops out near 1.1 V by default] +* `esphome-configs/` has only `no-current-input.yaml`; a future `current-input.yaml` would add + the `ct_clamp` sensor (section 10). No current-input config exists today [confirmed]. + +## 9. Programming and debug + +* **USB-C with a CH340C USB-UART and the standard two-transistor auto-reset circuit**, plus BOOT and + EN tactile buttons. First flash and serial logs need nothing but a USB-C cable. USB VBUS feeds the + 5 V rail through a Schottky diode so a board can be flashed and bench-tested without M12 power, + and so USB cannot back-feed a junction box supply. +* A 2.54 mm header with TX, RX, GND, 3.3 V, EN, GPIO0 for an external adapter or logic analyzer. +* **OTA stays the production path** (`ota: platform: esphome` in the config, see + `docs/source/hardware.rst` ESPHome section). USB is for first flash and bench work only; the USB + connector is inside the box. + +## 10. Firmware compatibility (pin map) + +Every pin the current config (`esphome-configs/2025.11.2/no-current-input.yaml`) uses stays on the +same GPIO, so **the existing config works unchanged** on the V2 board. + +| Function | V1 GPIO | V2 GPIO | Change | +|---|---|---|---| +| Wiegand D0 | 16 | 16 | none (through 5 V-tolerant buffer) | +| Wiegand D1 | 4 | 4 | none (through buffer) | +| Card present (CST) | 18 | 18 | none (through buffer) | +| LCD SDA / SCL | 22 / 23 | 22 / 23 | none (PCA9306 replaces the level converter) | +| Status LED data | 27 | 27 | none (74AHCT1G125 replaces the level converter) | +| Oops button | 32 | 32 | none (internal pull-up still used; V1 wires the switch's NC contact, so an unplugged button cable reads as "Oops pressed", and V2 keeps that) | +| Oops LED | 5 | 5 | none | +| Primary relay | 33 | 33 | none | +| Second relay (M12 pin 6) | 14 | 14 | none; output now ANDed with the relay drive in hardware | +| Tamper (M12 pin 5) | 12 | **35** | moved off strapping pin GPIO12; not used by any config today | +| CT clamp (M12 pins 7/8) | none | **36** | new; not used by any config today | +| External watchdog kick | none | **25** | new; only if the DNP watchdog is fitted | + +Why GPIO12 must move: GPIO12 (MTDI) is a strapping pin that sets the flash voltage at reset. A +tamper switch with a pull-up that holds it high during reset selects 1.8 V flash on a module whose +flash needs 3.3 V, and the board fails to boot. (ESP32 datasheet section 3.2; the WROOM-32E datasheet says "IO12 should be kept low when the module is powered on" [confirmed]; that a high level stops the board booting is an inference from the 1.8 V flash supply, not a quoted Espressif statement). GPIO35 is input-only with no internal +pull-up, so the board adds an external 10 kΩ pull-up. + +Status LED colour order: the V1 config sets `rgb_order: RGB` because V1 uses LEDs cut from a +string. A genuine WS2812B is GRB. Builders who use a WS2812B on the LED header need +`rgb_order: GRB`; this is a property of the LED, not the board. + +Proposed config additions for later (**proposal only, not applied to any config**): + +```yaml +binary_sensor: + - platform: gpio + pin: GPIO35 # tamper switch, M12 pin 5; external pull-up on the V2 board + name: "Tamper" + id: tamper + device_class: tamper + +sensor: + - platform: adc + pin: GPIO36 # CT clamp, M12 pins 7/8, biased to mid-rail on the V2 board + id: ct_adc + attenuation: 12db + update_interval: never + - platform: ct_clamp + sensor: ct_adc + name: "Machine Current" + sample_duration: 200ms + update_interval: 2s +``` + +## 11. Draft BOM + +Prices looked up 2026-11-25. "Board BOM" means parts on the controller board; lid parts, M12 +connector and enclosure carry over from V1 unchanged. + +Unit prices are LCSC's price at its quantity-10 break, or the nearest break when 10 is not one +(noted). "Class" is the JLCPCB assembly library class: Basic parts have no loading fee, each +unique Extended part has one. Source URL pattern: `https://www.lcsc.com/product-detail/.html`. + +### Controller board + +| Ref | Function | Manufacturer / MPN | LCSC # | Qty | Unit (USD) | Class | +|---|---|---|---|---|---|---| +| U1 | MCU module | Espressif ESP32-WROOM-32E-N4 | C701341 | 1 | 3.3129 | Extended | +| U2 | USB-UART | WCH CH340C | C84681 | 1 | 0.4594 | Extended | +| J1 | USB-C receptacle | Korean Hroparts TYPE-C-31-M-12 | C165948 | 1 | 0.1888 (qty 5 break) | Extended | +| U3 | 3.3 V 1 A LDO | Diodes AP7361C-33E-13 | C500795 | 1 | 0.8833 | Extended | +| U4 | Reset supervisor, 2.93 V, open drain | Diodes APX803S-29SA-7 | C143831 | 1 | 0.2862 | Extended | +| U5 | External watchdog timer (**DNP**) | TI TPL5010DDCR | C473912 | 0 | 0.2727 | Extended | +| K1 | Relay, 5 V coil, 10 A 250 VAC, reinforced | Hongfa HF115F/005-1HS3 | C81373 | 1 | 1.9224 | Extended (THT) | +| Q1 | Relay driver | AOS AO3400A | C20917 | 1 | 0.0786 (qty 5 break) | Basic | +| Q2 | Reverse-polarity PFET | AOS AO3401A | C15127 | 1 | 0.0827 (qty 5 break) | Basic | +| D1, D2 | Relay flyback, misc. | JSCJ 1N4148WS | C2128 | 2 | 0.0098 (qty 50 break) | Basic | +| U6 | 2nd-relay AND gate | SN74LVC1G08DBVR (UMW) | C434068 | 1 | 0.0421 | Extended | +| U7 | LED data 3.3 → 5 V | TI SN74AHCT1G125DBVR | C7484 | 1 | 0.1109 (qty 5 break) | Extended | +| U8 | I2C 3.3 ↔ 5 V | TI PCA9306DCTR | C123752 | 1 | 0.3762 (qty 5 break) | Extended | +| U9 | Reader input buffer | TI SN74LVC125APWR | C7813 | 1 | 0.3518 (qty 5 break) | Extended | +| D3 | Input TVS | MDD SMBJ5.0A | C113974 | 1 | 0.0592 | Extended | +| U10-U12 | ESD arrays (12 lines) | Protek SRV05-4-P-T7 | C85364 | 3 | 0.2214 (qty 5 break) | Extended | +| F1 | PTC fuse, 1.1 A hold | Littelfuse 1812L110PR | C163516 | 1 | 0.0529 | Extended | +| J2-J4 | LCD, button, LED headers (LED uses pin 4 as a spare GND) | JST B4B-XH-A(LF)(SN) | C144395 | 3 | 0.0522 | Extended (THT) | +| J5 | Reader header | JST B5B-XH-A(LF)(SN) | C157991 | 1 | 0.091 (qty 5 break) | Extended (THT) | +| J6 | M12 lead terminal, plug half | Cixi Kefa KF2EDGK-3.81-8P | C440864 | 1 | 0.4448 | Extended (THT) | +| SW1, SW2 | BOOT, EN buttons | XKB TS-1187A-B-A-B | C318884 | 2 | 0.0198 (qty 20 break) | Basic | +| (passives) | about 40 resistors and capacitors | e.g. UNI-ROYAL 0603 1 k/10 k (C21190/C25804), 100 nF 0603 (C14663), 10 µF 0805 (C15850) | | 40 | 0.0015 to 0.0311 | Basic | +| | **Priced subtotal per board** | | | | **9.62 + at most 1.24 passives = 10.86** | | + +Not yet priced (small parts, to price at schematic time): the PCB header half of the 8-position +3.81 mm terminal (KF2EDGR/KF2EDGV, not found on LCSC), two auto-reset NPN transistors, the USB +VBUS Schottky, the 5 V bulk capacitor and the ferrite bead. The passive line uses 40 times the +most expensive passive priced, as an upper bound. + +AP7361C vs AMS1117-3.3: the AMS1117-3.3 (C6186, $0.2032, **Basic**) would save about $0.68 per +board plus one $3.07 loading fee per order, but its 1.1 V dropout is too close to the margin +after input protection (section 6). Kept AP7361C. + +### Carried over from V1 (unchanged) + +| Item | Price | Source | +|---|---|---| +| 16x2 LCD with PCF8574 I2C backpack | $3.99 | V1 table, November 2025, **not re-checked** (no current PCF8574-backpack listing found at a distributor; Adafruit's 16x2 LCD alone is $8.96 at qty 10, adafruit.com/product/181, 2026-11-25) | +| Wiegand RFID reader | $6.26 | V1 table, November 2025, **not re-checked** (AliExpress) | +| 16 mm Oops button + cover | $5.49 | V1 table, November 2025, **not re-checked** | +| WS2812-type LED | $0.32 | V1 table, November 2025, **not re-checked** | +| M12 8-pin socket + 2 m cable | $9.80 + ~$15.49 | V1 table, November 2025, **not re-checked**; no verified US distributor price found on 2026-11-25 for the Phoenix Contact 1436343 Pg9 socket (EUR snippets only) | +| Enclosure + card holder | $9.90 | V1 table | + +Options for the hardened outdoor build: + +| Item | Price | Source | +|---|---|---| +| IP65 16 mm LED pushbutton, Olimex BUTTON-16MM-RED (LED 3 to 5 V) | EUR 1.80 at 10+ | olimex.com product page, from a search snippet, **unverified** | +| Adafruit 558 16 mm LED pushbutton (3 to 6 V LED; gasket, no IP rating) | $4.46 at 10 | adafruit.com/products/558, 2026-11-25 | +| YHDC SCT-013-030 CT (30 A, 1 V out), only when current sensing is wanted | $12.90 to $15.33 | retailer search snippets, **unverified**; no DigiKey/Adafruit listing found | + +## 12. DFM, ordering and cost + +* **Board:** 2 layers, 1.6 mm FR-4, HASL, about 100 x 80 mm or smaller, single panel per board (no + panelization needed at these quantities; JLCPCB's price is per board up to 100 x 100 mm). +* **Assembly:** JLCPCB **Economic** PCBA, single-sided. All SMT on one face. Through-hole parts + (relay, JST headers, terminal header) are either added by JLCPCB's hand-soldering service or + soldered by us; both keep a hand-solder path, and a fully hand-built board is possible because + the ESP32 module has castellated pads and every SMT part is 0603, SOT-23, SOIC or TSSOP. +* **Extended parts:** 12 unique SMT Extended part types (U1-U4, J1, U6-U9, D3, F1, and the SRV05-4 used three times), each + with a $3.07 loading fee per order on Economic PCBA ([assumed] per unique part; JLCPCB's page + does not say so explicitly). Swapping parts to Basic equivalents is the main lever on small-batch + cost; it is a schematic-time decision. +* **JLCPCB published fees** (jlcpcb.com/help/article/pcb-assembly-price, updated 2026-10-22, + read 2026-11-25): Economic setup $8.18, stencil $1.53, $0.0016 per SMT joint, $3.07 per + Extended part, $0.45 parts-placement confirmation, $3.58 hand-soldering labor per order. +* **PCB quote** (cart.jlcpcb.com/quote, 100 x 80 mm, page defaults, 2026-11-25): $4.00 for 5, + $5.00 for 10 (both marked "Special Offer"), $19.40 for 20. UPS shipping shown as $25.99. + The 2-layer / 1.6 mm defaults were [assumed], not re-checked on the form. +* **Lead time:** not looked up for this order shape; JLCPCB's Economic PCBA is typically days + plus shipping [assumed]. Get the real figure with the live quote in Milestone 2. +* **Supply risk:** the RFID reader (single AliExpress source) is the only part with real supply + risk; the board's 5 V-tolerant reader input and 5 V reader supply are there so a different + Wiegand reader with a card-present output can replace it. The ESP32-WROOM-32E has a long + longevity commitment and deep stock. The M12 socket and cables are multi-source. + +### Cost comparison with V1 + +V2 replaces only these V1 items: ESP32 dev board $5.66, screw-terminal breakout $8.13, level +converter $0.75, relay module $1.29, a total of **$15.83** (V1 table, November 2025 prices, not +re-checked). Everything else in the $67.08 control box carries over. + +Rough V2 controller board cost, from the prices above (qty-10 LCSC prices used for both +quantities, which overstates the 20-board case slightly; about 250 SMT joints per board +[assumed]): + +| Line | 10 boards | 20 boards | +|---|---|---| +| PCBs | $5.00 | $19.40 | +| Economic PCBA setup + stencil + placement confirmation | $10.16 | $10.16 | +| Extended-part loading fees (12 × $3.07) | $36.84 | $36.84 | +| SMT joints (250 × $0.0016 per board) | $4.00 | $8.00 | +| Board parts ($10.86 per board) | $108.60 | $217.20 | +| Shipping (quoted UPS) | $25.99 | $25.99 | +| **Total** | **$190.59** | **$317.59** | +| **Per board** | **$19.06** | **$15.88** | + +Not included: the unpriced small parts listed under the BOM, THT soldering (our time, or +JLCPCB's $3.58 per order plus per-joint fees), tariffs/duties, and any CT clamp. + +So, per control box: + +| | V1 | V2 at 10 | V2 at 20 | +|---|---|---|---| +| Replaced electronics | $15.83 | $19.06 | $15.88 | +| Control box total | $67.08 | about $70.31 | about $67.13 | + +**Conclusion: V2 is roughly cost-neutral, not a saving.** The case for it is repeatable assembly, +input and ESD protection, a fail-safe relay driver, the GPIO12 boot fix, and the tamper/CT inputs, +not cost. The fixed fees dominate at these quantities, so ordering 20 instead of 10 costs about +$127 more for 10 extra boards. At the confirmed count of four units, 10 boards leaves six spares. + +## 13. Safety and compliance notes for mains switching + +These are research notes on common practice, **not a certification or compliance claim**. + +* **The external contactor stays mandatory** for motors and any load above the pilot relay's + rating. The box never carries mains (section 5 and 6). +* Junction box: a listed enclosure (V1 uses a Carlon PVC box), with cord grips or strain reliefs on + every cable, the machine's equipment-grounding conductor carried through and bonded, and + contactors and supplies that are UL-recognized/listed parts rated for the load voltage and the + motor's FLA (motor-rated, AC-3 or HP-rated contacts). +* Switch every ungrounded conductor: both legs for 240 V machines (V1's 2-pole contactor option + already does this), the hot (never the neutral) for 120 V. +* Overcurrent protection: the branch circuit protects the cord and contactor; the box's 5 V supply + is protected by its own internal fuse; a separate fuse on the 5 V supply's mains input is good + practice for supplies without one. +* Clearance and creepage on any board that does carry mains: about 3 mm clearance and 4 mm creepage + for basic insulation at 250 VAC, doubled for reinforced (from IEC 60664-1 tables, pollution + degree 2; check the exact figures before relying on them). This is why the recommendation keeps + mains off the board entirely. +* Labeling: label the junction box "controlled by access control; disconnect machine plug or + breaker before servicing", and label the machine with how to clear an Oops. The access-control + relay is **not** a lockout/tagout disconnect and must not be used as one. +* The access-control relay is also not an emergency stop. The Oops button is a request to the + server, not a safety-rated stop; machines that need an E-stop keep their own. + +## 14. Open questions for Jason + +1. **Unit count:** how many MAC units are in production now, and how many are planned? The repo's + `machines.json` is a test stub; the analysis docs name four. Board quantities in section 12 use + 10 and 20 boards (the four units named in the analysis docs plus spares and growth) [assumed] until this is answered. +2. **Machine list:** voltage, FLA, and current switching method (box relay direct, external relay, + contactor and its coil voltage, SSR) for each machine. +3. **Mains on M12:** does any deployed unit run mains (for example a 120 VAC contactor coil) through + M12 pins 3/4? +4. **Field failures:** have any V1 units failed from wiring, the screw-terminal breakout, or the + power feed (problem 4 is otherwise assumed)? +5. **Fob technology:** are the Neon fobs 125 kHz (EM4100-type)? That decides whether a 13.56 MHz + reader (PN532, which ESPHome supports with tag-removed events) is even an option later. +6. **Reader supply:** is the V1 AliExpress reader still orderable? If not, a 5 V Wiegand reader with + a card-present output is the fallback, which is why the board offers a 5 V reader supply. +7. **Wide-input power:** worth accepting 12/24 V on M12 pin 1 in a future revision, given that it + changes every junction box? +8. **Outdoor scope:** which movable tools are going outdoors, and do they need IP65 or is IP54 with + shade enough? This decides the LCD and button choice. +9. **Approval:** approve the recommendations (base-mounted board, keep M12 and pinout, ESP32-WROOM-32E, + pilot relay only, 5 V input, CT input and DNP watchdog footprints) so the implementation plan + below can start? +10. **Hardware layout:** OK to create `hardware/v2_mcu/` holding a KiCad project (schematic, PCB, + JLCPCB BOM/CPL exports, and a README) alongside the existing `hardware/v1_mcu/`? + +## Implementation Plan + +Proposed only; not started. Per `docs/features/README.md`, each milestone needs Jason's approval +before moving to the next. Commit prefix: `Custom MCU PCB - {Milestone}.{Task}`. + +### Milestone 1: Schematic + +* 1.1 Create `hardware/v2_mcu/` KiCad project and README (after question 10 is answered). +* 1.2 Schematic per sections 3 to 10, with LCSC part numbers on every SMT part. +* 1.3 Review: fresh reviewer checks pin map against the ESPHome config and the fail-safe relay path. + +### Milestone 2: Layout and order files + +* 2.1 Board outline and mounting per section 1.2; confirm the final outline back to the enclosure + effort. +* 2.2 Layout, DRC, JLCPCB BOM/CPL export. +* 2.3 Get a live JLCPCB quote; **Jason approves before any order is placed.** + +### Milestone 3: Prototype bring-up + +* 3.1 Flash the existing `hardware-test.yaml` and `no-current-input.yaml` unchanged; run + `esphome-configs/2025.11.2/hardware-test.md`. +* 3.2 Measure: relay state through power-up, EN reset, brown-out (variable supply) and with + GPIO14 toggled; 5 V current budget; RFID read range on a metal machine. +* 3.3 Fix-ups and a second revision if needed. + +### Milestone 4: Acceptance Criteria + +* 4.1 Update `docs/source/hardware.rst` with a Version 2 section (components, wiring, pinout). +* 4.2 Update `CLAUDE.md` if anything in it changes. +* 4.3 All nox sessions pass (no server code changes are expected). +* 4.4 Move this file to `docs/features/completed/`. From 77688c202626aa1d2d0933f91b9f35c05af4f20c Mon Sep 17 00:00:00 2001 From: Jason Antman Date: Wed, 25 Nov 2026 18:06:29 -0500 Subject: [PATCH 2/2] Custom MCU PCB - revise research doc after Jason's answers (#208) Rework the V2 hardware research around Jason's 2026-11-25 answers: single lid-mounted board (LCD, reader, LED on board; button and M12 on short cables), M12 8-pin kept, IP54, 5 + 6 units with ~10 more, <=1 A SELV pilot loads only, no mains on M12, 125 kHz EM4100 fobs. - New reader section: any reader must deliver the full 32-bit EM4100 ID (ESPHome wiegand truncates 26-bit frames to 24 bits) plus card presence. Compares the V1 AliExpress module, ID Innovations ID-12LA (ASCII output parsed by ESPHome rdm6300, Tag-in-Range pin) and an on-board EM4095 + PCB antenna. Recommends ID-12LA for rev A with a Wiegand fallback header, and EM4095 as a separate cost-down study. - Module-vs-dev-board trade-off table; recommends soldered module (WROOM-32E / -32UE share a footprint for metal housings). - Pilot relay changed to a gold-clad signal relay (G5V-1) for VFD dry-circuit inputs; button LED now MOSFET-driven for any LED voltage. - Proposed (not applied) ESPHome diff for the ID-12LA; updated BOM, cost comparison at 10/25/50 units, open questions and milestones. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KQ8DrLoknL3m1Wq3Um6vAe --- docs/features/custom-mcu-pcb.md | 922 +++++++++++++++----------------- 1 file changed, 438 insertions(+), 484 deletions(-) diff --git a/docs/features/custom-mcu-pcb.md b/docs/features/custom-mcu-pcb.md index 7b95709..4a91b43 100644 --- a/docs/features/custom-mcu-pcb.md +++ b/docs/features/custom-mcu-pcb.md @@ -16,404 +16,382 @@ planning phase of the feature. If Jason would rather keep research and the build research sections can move to a dated `docs/YYYY-MM-DD-*.md` analysis doc like the existing lockup analyses. -**Status:** research complete; **awaiting Jason's answers to the open questions and approval of the -recommendations before any design work.** Nothing has been ordered and no firmware or ESPHome -config has been changed. +**Status:** second revision, after Jason's answers of 2026-11-25 (section 0). **Awaiting Jason's +decisions in section 14 before any design work.** Nothing has been ordered and no firmware or +ESPHome config has been changed. Conventions used below: -* **[confirmed]**: verified from this repo, a datasheet, or a distributor page (cited). +* **[confirmed]**: verified from this repo, a datasheet, distributor page or source file (cited), + or stated by Jason. * **[assumed]**: inferred, not confirmed. Each one needs checking by Jason or on a prototype. -* Prices were looked up on **2026-11-25** from the cited distributor pages; they are not estimates. +* **[snapshot]**: a price or stock figure taken from a search-result summary because the live page + could not be fetched. Recheck before ordering. +* Other prices were read from live distributor pages on **2026-11-25**; they are not estimates. + +## 0. Decisions and answers from Jason (2026-11-25) + +* **Connector:** keep the M12 A-coded 8-pin. It is the only widely available locking connector with + pigtails, cables and extensions; the 2 A limit is accepted. (GX16-8 is hard to find except as + bare connector bodies.) +* **Architecture:** the ideal is **a single board mounted to the lid** carrying the LCD, reader, + button and LED, with as few connections as possible, supporting different button and LED styles. + Housing is a custom 3D-printed housing, or a 3D-printed faceplate on a metal housing with an + external WiFi antenna. Enclosure constraints from the first revision are all open. +* **GPIOs can be reassigned.** +* **Unit count:** 5 in production, 6 more built and not yet deployed (11 V1 units). About 10 more + after that; a bulk lot may be bought for stock depending on cost. Quantities used below: 10, 25 + and 50 boards. +* **Loads:** from a VFD's logic-level input up to a 5 HP 240 VAC motor. **Anything switching more + than 1 A uses an external relay/contactor assembly.** +* **Mains on M12: no.** Every unit that switches more than a control signal has a second enclosure + with the 5 VDC supply and a 5 VDC-coil relay; M12 pins 3/4 carry only that relay's control + circuit. +* **Field failures: none.** All V1 units are securely mounted on stationary equipment. (Movable + tools are new, so vibration is a new consideration for V2.) +* **Fobs:** generic 125 kHz EM4100-compatible cards and keyfobs. +* **Movable tools:** planer, jointer; later perhaps a contractor table saw; welders are at most a + stretch goal. **IP54 is sufficient**; they are never used outdoors in rain. +* **Main concern: the RFID reader**, as the hardest part to source (section 4). ## 1. Constraints for the enclosure effort -These are stated first so the hardened enclosure for movable tools (Trello card "Design hardened -MAC MCU enclosure for movable tools") can start from them. Board numbers are targets until the -first layout is done; the enclosure should budget for the "envelope" figures, which include margin. - -### 1.1 Architecture that drives the enclosure - -**Recommendation: one controller board mounted to the enclosure base, with every lid-mounted part -on a keyed, latching cable.** The LCD, status LED, Oops button and RFID reader stay separate parts -mounted to the lid (as in V1) and plug into the board on JST-XH 2.5 mm headers. The M12 connector -is panel-mounted in the enclosure wall and its leads land on an 8-position pluggable terminal block -on the board. - -Why, compared with putting the UI parts on the PCB and mounting the board behind the lid: - -* The enclosure keeps free placement of the LCD window, button, LED and card pocket, so one board - serves the existing V1-style box and a hardened outdoor box with a different layout. -* The RFID antenna can sit right behind the card pocket and away from the board's ground pour and - the ESP32 antenna (see 1.5). -* The 16 mm button has a deep body behind the panel, which would collide with a board mounted - directly behind the lid. -* Cost: a board-behind-the-lid layout needs the board to be at least as wide as the LCD plus the - card pocket (about 170 x 100 mm), which is above JLCPCB's 100 x 100 mm price break, and it puts - parts on both faces (LCD and LED on the front, SMT on the back), which pushes assembly to - double-sided. - -What this does not fix: there are still five cables inside the box. They are crimped, keyed and -latching instead of hand-soldered or screw-terminal joints, which removes the wiring errors and -loose-wire failures but not the cables themselves. +### 1.1 Architecture + +**Recommendation: one lid-mounted board. The LCD, RFID reader and status LED are on the board; +the Oops button is a panel part on a short keyed cable; the M12 is a panel-mount socket whose +leads land on a pluggable terminal block.** That is two internal connections (plus a u.FL antenna +cable in a metal housing). + +* **Front face (towards the faceplate):** through-hole parts only: the bare 16x2 LCD on a 16-pin + header and standoffs, the reader (module socket or on-board antenna, see section 4), and a + through-hole addressable LED (5 mm or 8 mm WS2812-compatible) or a light pipe. +* **Back face:** all SMT parts, so assembly stays single-sided (JLCPCB charges double setup and + stencil for double-sided), plus the relay, the terminal block and the button header. +* **Button:** a 4-pin JST-XH header. The faceplate holds whichever panel button is chosen (16 mm, + 19 mm, 22 mm mushroom); the board cannot hold it directly because panel buttons have a deep body + and threaded bushing. The button LED is driven through a MOSFET from 5 V with a resistor + footprint, so 3 V, 5 V and (dimly) 12 V LED buttons all work, which widens button choice compared + with V1's "LED must be 3.3 V-drivable" rule. +* **LED styles:** footprints for a through-hole 5 mm/8 mm addressable LED on the front, plus a + 3-pin header for an external pixel such as V1's 12 mm LED. Only one is fitted. + +What this costs: the board is larger (about 150 x 85 mm, see 1.2), above JLCPCB's 100 x 100 mm +price tier, and the faceplate layout is fixed by the board. The housing becomes "a box that fits +this board" rather than "a box that holds loose parts". ### 1.2 Board outline and mounting | Item | Target | Notes | |---|---|---| -| Board outline | 90 x 70 mm, 1.6 mm FR-4, 2 layers | [assumed] fits after layout; first layout may shrink it to about 80 x 60 mm | -| Enclosure envelope to reserve | 100 x 80 mm footprint | includes margin for cables bending off the headers | -| Mounting holes | 4 x M3 (3.2 mm plated), 4 mm from each edge | pattern 82 x 62 mm for the 90 x 70 outline; matches the M3 hardware already used in V1 | -| Height above board (component side) | 20 mm max | tallest parts are the relay (about 16 mm) and the pluggable terminal plug with wires | -| Height below board | 3 mm (THT lead stubs) | use standoffs of at least 5 mm | -| Single-sided SMT | yes | all SMT on the top face; THT connectors and relay on the top face too | -| ESP32 antenna | module antenna overhangs or sits at a board edge | keep metal, wires and the ground pour 15 mm clear of the antenna; enclosure must be non-metallic in front of it | - -### 1.3 Lid parts (unchanged in size from V1) - -All dimensions are from `hardware/v1_mcu/*.scad` [confirmed]. - -| Part | Size | Cable to board | -|---|---|---| -| 16x2 LCD with I2C backpack | 80.1 x 38.6 mm PCB, 17.5 mm total depth including backpack (`lcd.scad`) | 4-pin JST-XH (5 V, GND, SDA, SCL) | -| Wiegand RFID reader | 47.2 x 26.2 mm PCB, 25.4 mm square antenna, 4.7 mm deep (`rfid.scad`) | 5-pin JST-XH (VCC, GND, D0, D1, CST) | -| 16 mm Oops button | 16 mm panel hole (`oops_button.scad`) | 4-pin JST-XH (switch, switch return, LED+, LED-) | -| Status LED (WS2812-type) | 12 mm module as V1, or any WS2812-type pixel | 3-pin JST-XH (5 V, GND, data) | - -### 1.4 External connector - -**Recommendation: keep the M12 A-coded 8-pin connector and the V1 pinout**, with the box carrying -a panel-mount female socket with wire leads (as V1) rather than a PCB-mount socket. The M12 is an -industrial sensor connector with a threaded coupling ring, which survives vibration and being moved -far better than friction connectors, prewired cables are cheap and widely stocked, and every -deployed V1 junction box already has the mating cable. - -Constraint this places on the enclosure: one M16 x 1.5 or Pg9 threaded panel hole (check the -chosen socket's datasheet; for example Phoenix Contact 1436343 is a rear-mount Pg9 socket with -solder cups, IP67), with a flat sealing face for the O-ring, and a protective cap on a -lanyard for movable units so an unplugged socket stays sealed. - -Important rating limit: **M12 A-coded 8-pin connectors are rated 30 V and 2 A per contact** (Phoenix Contact 1436343 datasheet: IP67, 30 V, 2 A at 40 °C [confirmed]; the V1 Amazon part has no published rating and is [assumed] to be the same class). -That is a low-voltage connector. Anything switched through pins 3 and 4 must stay within that -rating; see section 5 (Load switching). - -Alternatives considered: - -* **GX16-8 (V1's original choice):** cheaper, but no IP rating worth relying on and the doc - already moved away from it for cable availability. -* **M12 PCB-mount socket:** saves the pigtail, but fixes the connector to a board edge and makes the - board position dictate the enclosure wall. Rejected for the reason in 1.1. -* **Separate mains and signal connectors (for example an IEC inlet plus M12):** only needed if the - box ever switches mains itself, which this document recommends against. - -### 1.5 RFID antenna placement - -* The reader reads through the plastic lid; the card sits in the external pocket. A sealed lid is - fine for RFID. [confirmed from V1 design: the reader is under the lid behind the card holder] -* Keep at least 25 mm between the reader antenna and any metal, including a cast-iron tool body - behind the box, the board's ground pour, and the ESP32 module. [assumed rule of thumb for - 125 kHz readers; verify read range on a prototype mounted on a metal machine] -* The enclosure must be non-metallic (or have a non-metallic window) over the reader and in front of - the ESP32 antenna. A die-cast aluminium "hardened" box would break both RFID and WiFi. - -### 1.6 Environmental targets - -| Item | Indoor (V1-style) box | Hardened / movable / outdoor box | -|---|---|---| -| IP rating | IP54 | IP65 | -| Operating ambient | 0 to +40 °C | -10 to +50 °C ambient; +70 °C inside a box in direct sun [assumed] | -| Humidity | non-condensing | condensing possible; add a vent membrane and consider conformal coat | - -How these affect part choice: - -* The **LCD is the weakest part for temperature**: standard 16x2 HD44780 modules are rated - 0 to +50 °C [assumed: typical HD44780 rating; no rating was given on the distributor page checked]. An outdoor unit needs an extended-temperature LCD (usually -20 to +70 °C) or should - be shaded. All board parts in the BOM below are rated -40 to +85 °C or better. -* **IP65** needs: a gasketed lid, a sealed LCD window (glued or gasketed clear panel), an IP65 or - better 16 mm button (the V1 button has no stated IP rating [assumed]; the V1 cover helps with - dust but not water jets; an IP65 option is in the BOM), the M12 cap, and no open card slot (the external card pocket is fine). -* Condensation: a sealed box that heats and cools breathes moisture in. A small ePTFE vent plug and - a conformal coat on the board are the usual fixes. Conformal coat complicates hand rework, so it - is listed as optional for the outdoor build only. +| Outline | about 150 x 85 mm, 1.6 mm FR-4, 2 layers | [assumed] until first layout; driven by LCD (80 x 36 mm) + reader zone + button/LED row | +| Mounting | 6 x M3 (3.2 mm plated): 4 at the corners, 2 near the LCD and reader | the faceplate is the reference surface; board on standoffs behind it | +| Front-face height | LCD: about 10 mm (bare LCD, no I2C backpack) above the board; reader module: about 10 mm [assumed] | the faceplate sits on the LCD bezel; window over LCD, plain plastic over reader | +| Back-face height | 20 mm max | relay and terminal plug with wires | +| Reader zone | no copper pour under or around the reader antenna; at least 20 mm from the LCD's metal bezel and the ESP32 module [assumed] | 125 kHz fields detune near metal and ground planes | +| ESP32 antenna (WROOM-32E) | at a board edge, 15 mm clear of metal | not needed for WROOM-32UE (external antenna) | + +### 1.3 Connectors + +* **M12 A-coded 8-pin, V1 pinout, panel-mount female socket** in the housing wall (Pg9 or + M16 x 1.5 threaded hole), leads to an 8-position 3.81 mm pluggable terminal on the board. Rated + **30 V and 2 A per contact, IP67 mated** (Phoenix Contact 1436343 datasheet) [confirmed]. Fine for + every load path Jason described: ≤1 A SELV pilot circuits only [confirmed by Jason]. +* **Oops button:** 4-pin JST-XH (switch, switch return, LED+, LED-). +* **External antenna (metal housing only):** ESP32-WROOM-32UE's u.FL socket to a bulkhead RP-SMA + pigtail. WROOM-32E and WROOM-32UE share one footprint, so one board design serves both housings; + the module is chosen at order time [assumed: same footprint per Espressif's combined datasheet, + verify against the land pattern]. + +### 1.4 Housing and environment + +* **IP54** for all units, indoor and movable [confirmed by Jason]: gasketed lid/faceplate seam, + sealed LCD window, and an M12 cap on a lanyard for unplugged movable units. The external card + pocket is fine at IP54. +* **Temperature:** 0 to +40 °C ambient, up to +50 °C for occasional dry outdoor use in sun + [assumed]. The standard HD44780 LCD (typically 0 to +50 °C [assumed; not stated on the + distributor page checked]) is the limiting part; everything else on the board is rated -40 to + +85 °C. +* **Metal housing:** the faceplate over the LCD and reader must be non-metallic, and the reader + antenna should be at least 25 mm from the metal housing edge [assumed rule of thumb; verify read + range on a prototype]. WiFi needs the WROOM-32UE and an external antenna. +* **Vibration (planer, jointer, table saw):** soldered module rather than a socketed dev board + (section 3), latching JST-XH for the button, the terminal block plug screwed down, LCD on + standoffs as well as its header, and the reader module (if used) retained by the faceplate or a + clip, not only by its socket. ## 2. Known problems and how the board addresses them | # | Problem | Hardware or firmware/server? | Board's answer | |---|---|---|---| -| 1 | Machine starts on the next login after an Oops clear because the machine's own switch was left ON (`docs/2026-11-21-oops-clear-power-on-analysis.md`) | **Hardware gap at the machine**, not the MCU | The board cannot see the machine switch while its relay is open. Real fix: NVR or magnetic switches on the machines. Board adds a current-transformer input so future firmware can detect current flowing the instant the relay closes and open it again (section 8). | -| 2 | MCUs wedged for 22 h and 40 min while WiFi-associated (`docs/2026-05-05-*` and `docs/2026-05-11-*`) | **Firmware/server** root causes, already fixed in firmware (bounded HTTP, liveness watchdog, task WDT panic) | Board adds a proper reset supervisor on EN and a footprint for an external watchdog timer, not populated by default because using it needs a firmware change (section 7). | -| 3 | Relay state at boot / brown-out | Hardware | Low-side MOSFET relay driver with a gate pull-down, so the relay is open whenever the GPIO is high-impedance (reset, boot, brown-out). Tamper input moved off strapping pin GPIO12. Second-relay output gated in hardware by the primary relay drive (section 5). | -| 4 | Hand-wired COTS stack | Hardware | One assembled board with keyed cables (section 1.1). | -| 5 | No current sensing, no tamper; second relay optional | Hardware + future firmware | Board provides tamper input, CT input and the second-relay output on the existing M12 pins; firmware for tamper and current is proposed only (section 10). | - -Which parts of problem 4 are confirmed versus assumed: - -* **[confirmed]** Point-to-point wiring between dev board, breakout, level converter, relay module, - reader, LCD, LED and button (`docs/source/hardware.rst` wiring list). -* **[confirmed]** The reader needs a solder blob on `S2` for Wiegand mode, and is a single-source - AliExpress part (same doc, note 5). -* **[confirmed]** Power is a bare 5 V feed on M12 pins 1 and 2 with no documented protection. -* **[assumed]** That these have caused field failures. Nothing in the repo records a wiring or - power failure; the documented lockups were firmware/server. **Jason: have any units failed from - loose wiring, the breakout terminals, or the power feed?** - -## 3. Recommended architecture - -```mermaid -flowchart LR - subgraph M12["M12 A-coded 8-pin (panel, wire leads)"] - P1["1 +5V in"] - P2["2 GND"] - P34["3/4 relay COM/NO"] - P5["5 tamper"] - P6["6 2nd relay out"] - P78["7/8 CT clamp"] - end - subgraph Board["Controller board"] - PROT["Input protection: PTC fuse, reverse-polarity PFET, TVS"] - LDO["3.3 V LDO, 1 A"] - SUP["Reset supervisor on EN (+ optional ext. watchdog, DNP)"] - ESP["ESP32-WROOM-32E-N4"] - USB["USB-C + CH340C + auto-reset, BOOT/EN buttons"] - RLY["Relay driver (NMOS + pull-down) + 5 V relay"] - AND["AND gate: GPIO14 AND relay drive"] - LS["5 V level shift: I2C (PCA9306), LED data (74AHCT1G125)"] - RIN["Reader input buffer (74LVC125A, 5 V tolerant)"] - ESD["ESD arrays on all off-board signals"] - CT["CT bias + burden -> ADC1"] - end - P1 --> PROT --> LDO --> ESP - P2 --- PROT - SUP --> ESP - USB --> ESP - ESP -- GPIO33 --> RLY --> P34 - ESP -- GPIO14 --> AND --> P6 - RLY -. drive .-> AND - P5 --> ESD --> ESP - P78 --> CT --> ESP - ESP -- GPIO22/23 --> LS --> LCD["16x2 LCD (PCF8574, 5 V)"] - ESP -- GPIO27 --> LS --> LED["WS2812 status LED"] - READER["Wiegand reader"] --> RIN --> ESP - BTN["Oops button + LED"] --> ESD -``` - -Summary of the decisions (each is argued in the numbered sections that follow): - -* ESP32-WROOM-32E-N4 module, same `esp32dev` ESPHome board, same GPIOs as V1 for everything the - current config uses. -* Wiegand reader stays a separate module on a header, now with a 5 V-tolerant input buffer and a - selectable 3.3 V / 5 V reader supply so more Wiegand readers fit. -* 16x2 PCF8574 LCD and WS2812-type LED stay; the board does the 5 V level shifting. -* One on-board relay as a low-voltage pilot contact for an external contactor/SSR; external - contactor stays mandatory for motor loads. -* 5 V input stays, with real input protection. No mains on the board. +| 1 | Machine starts on the next login after an Oops clear because the machine's own switch was left ON (`docs/2026-11-21-oops-clear-power-on-analysis.md`) | **Hardware gap at the machine**, not the MCU | The board cannot see the machine switch while its relay is open. Real fix: NVR or magnetic switches on the machines. The board adds a current-transformer input so future firmware can detect current flowing the instant the relay closes and open it again (section 8). | +| 2 | MCUs wedged for 22 h and 40 min while WiFi-associated (`docs/2026-05-05-*`, `docs/2026-05-11-*`) | **Firmware/server**, already fixed in firmware | Reset supervisor on EN; external watchdog footprint, not fitted by default because using it needs a firmware change (section 7). | +| 3 | Relay state at boot / brown-out | Hardware | MOSFET relay driver with a gate pull-down: the relay is open whenever the GPIO is not driven. Tamper input moved off strapping pin GPIO12. Second-relay output gated in hardware by the primary relay drive (section 5). | +| 4 | Hand-wired COTS stack | Hardware | One board, two internal connections. No V1 field failures from wiring [confirmed by Jason], so the gain is build time and repeatability, plus robustness for the new movable units. | +| 5 | No current sensing or tamper; second relay optional | Hardware + future firmware | Tamper input, CT input and the second-relay output on the existing M12 pins; firmware for tamper and current is proposed only (section 10). | -## 4. MCU module +## 3. MCU: module on the board vs a dev board on headers -**Recommendation: ESP32-WROOM-32E-N4.** +**Recommendation: ESP32-WROOM-32E-N4 (or -32UE-N4 for an external antenna) soldered to the +board.** -* It is the current revision of the module V1 already uses (WROOM-32D is marked "Not Recommended for New Designs" on its datasheet, v2.8 [confirmed]). Same chip - family, same pinout, same 4 MB flash, so `board: esp32dev` and the existing config work - unchanged. 4 MB is what V1 has today and is enough for ESPHome with OTA (two app partitions). - [confirmed for V1 today: the deployed config builds and OTAs on 4 MB dev boards] -* ESPHome support for the classic ESP32 is the most mature of any Espressif part. [assumed: it was ESPHome's first ESP32 target; ESPHome's docs do not name the WROOM-32E with `esp32dev` explicitly, but `esp32dev` is the generic 4 MB ESP32 definition] -* Availability: Espressif's longevity commitment lists the ESP32 (classic) chip for at least 15 years from 2016-01-01 (the module is not listed separately), and LCSC showed 38,735 WROOM-32E-N4 in stock [confirmed, 2026-11-25]. -* It is on JLCPCB's parts library (see BOM), so the PCB service can place it; it can also be - hand-soldered (castellated pads) for the hand-assembly path. - -Alternatives: - -* **ESP32-S3-WROOM-1:** USB built in (would drop the CH340C), more RAM. But a different chip means a - different `board:` and different GPIO capabilities, so the config would change in several places, - against the "minimal firmware changes" constraint, and it buys nothing this application needs. -* **ESP32-C3 / C6:** cheaper, but fewer GPIOs (the design uses 13 signals plus programming pins) and - a different config. Not worth it. +| | Module soldered on the board | Dev board (ESP32-DevKitC-32E/-32UE) plugged into headers | +|---|---|---| +| Part cost | module $3.31 at 10 (LCSC C701341) [confirmed]; -32UE $2.65 to $4.16 [snapshot]; plus USB-UART, USB-C, LDO, supervisor, buttons: about $1.90 more (section 11) | Espressif DevKitC-32E $14.69, -32UE $14.40 at Mouser [snapshot; currency unverified] | +| Assembly | JLCPCB places it; about five extra Extended-part fees per order ($3.07 each) | fewer SMT parts; two 19-pin header sockets to solder | +| Field swap | replace the whole board (it is the spare part) | pull the dev board, which is quicker if the ESP32 itself fails | +| Vibration | nothing to work loose | header sockets can fret or back out on a planer or jointer; needs a retaining strap | +| Height | module is 3 mm | dev board on sockets adds about 20 mm on the back face [assumed] | +| Reset, power quality | our own supervisor and LDO | whatever the dev board has: the genuine DevKitC is fine, clones vary (AMS1117, RC on EN) | +| Pinout risk | none | the board must match one dev board pinout; 38-pin and 30-pin clones differ in width and order | +| Antenna | 32E or 32UE on the same footprint | buy the matching dev board | + +What the module option gives up: you cannot swap only the ESP32. Since the board is the swap unit +and costs less than one genuine dev board in parts, that is the right trade for movable tools. + +Module notes: + +* WROOM-32D (V1) is marked "Not Recommended for New Designs" on its datasheet v2.8; WROOM-32E is + its current replacement [confirmed]. Espressif's longevity commitment covers the ESP32 (classic) + chip for at least 15 years from 2016-01-01 [confirmed]. +* Same chip, so `board: esp32dev` and every ESPHome component in the current config carry over. + 4 MB flash, the same as V1, is enough for OTA. +* ESP32-S3 / C3 / C6 were considered and rejected: different board targets and pin capabilities for + no gain this application needs. + +## 4. RFID reader (the main sourcing problem) + +### 4.1 What any reader must do + +* **Deliver the full 32-bit EM4100 ID.** The fob numbers in Neon are 10-digit decimals (the + `Fob10Digit` field in `docs/source/neon.rst`), which is the 32-bit EM4100 ID printed on the card. + ESPHome's `wiegand` component gives the full 32 bits only for 34-bit frames: for 26-bit frames + it emits the lower 24 bits, at most 8 digits (`wiegand.cpp`, lines 72 to 93) [confirmed]. So the + V1 reader must be sending Wiegand-34 [assumed: inferred from the codes matching Neon; Jason, + please confirm from a V1 log line], and a **Wiegand-26-only reader would break every existing + fob**. +* **Report card presence**, because pulling the card logs the user out. V1 uses the reader's `CST` + line on GPIO18. + +### 4.2 Options + +| | A. V1 AliExpress Wiegand reader on a header | B. ID Innovations ID-12LA module on the board | C. On-board EM4095 front end + PCB antenna | +|---|---|---|---| +| Sourcing | single AliExpress listing; the core problem | SparkFun SEN-11827 in stock, $32.50 (1), $30.88 (25+), $29.25 (100+) [confirmed, sparkfun.com]; Mouser 474-SEN-11827, 28 in stock [snapshot]. ID Innovations' own site did not resolve and the datasheet dates from 2015 [confirmed], so it is a long-lived part from one small maker | EM Microelectronic EM4095 (SOIC-16): LCSC out of stock, about $2.85 at 100+ [snapshot]; TME EUR 4.30 at 1, 898 in stock [snapshot]; DigiKey listed [snapshot]. No EOL notice found | +| Full 32-bit ID | yes (Wiegand-34) [assumed, 4.1] | yes, via its ASCII serial output (STX, 10 hex chars, checksum, CR LF ETX). Its Wiegand output is 26-bit only, so it must not be used [confirmed, datasheet v1.2] | yes, firmware decodes the raw EM4100 frame | +| Card present | `CST` pin | Tag-in-Range pin (pin 6, high while a tag is in range, all formats) [confirmed in datasheet text; one table row marks it "(Future)", so bench-test it] | in firmware: card present while frames keep arriving (EM4100 tags repeat their frame continuously) | +| Supply | 3.3 to 5 V | 2.8 to 5 V, needs a clean linear-regulated supply (under 3 mV p-p) [confirmed] | 4.1 to 5.5 V (5 V rail) [confirmed] | +| Read range | short [assumed] | 12 cm with an ISO card [confirmed]; the ID-20LA (SEN-11828, $37.50) reads 18 cm | about 11 cm on EM's demo board PCB antenna (120 µH) [confirmed, AN404] | +| ESPHome | `wiegand` (unchanged) | built-in `rdm6300` component parses this exact frame (it skips CR/LF "for ID-20LA compatibility") and emits the 32-bit ID [confirmed, `rdm6300.cpp`] | **no ESPHome component exists** [confirmed by search]; closest code is the MIT-licensed `Nickjgniklu/em4095` ESP32 library, which would have to become an ESPHome external component in this repo | +| Firmware change | none | small: `uart:` + `rdm6300:` instead of `wiegand:`, plus a duplicate filter (section 10) | large: new component, Manchester decode, card-present logic, and it must not disturb the main loop | +| Board design risk | none | low: module footprint, clean 3.3 V supply, keep-out | high: antenna design and tuning, layout near the LCD bezel and ground, EMC of a 125 kHz carrier | +| Per-unit reader cost | $6.26 (V1 price, Nov 2025, not re-checked) | about $31 | about $3 to $5 IC plus passives; antenna is PCB copper [snapshot prices] | + +Other modules checked: Seeed Grove 125 kHz (5 V only, UART or Wiegand-26, no card-present pin), +RF125e (Wiegand-26 only, non-commercial licence), RDM6300 (cheap and everywhere, UART frame +parsed by ESPHome, but no card-present pin, and whether it keeps sending frames while a card is +held is not confirmed). None of them both deliver 32 bits and report presence [confirmed for +Grove and RF125e from their docs; RDM6300 behaviour unconfirmed]. + +### 4.3 Recommendation + +**Rev A: ID-12LA (option B) as the fitted reader, with a 5-pin header for a V1-style Wiegand +reader (option A) on the same GPIOs as a fallback.** It is the only distributor-stocked part found +that delivers the full ID and a presence signal, it needs a small, well-understood firmware change, +and it removes the antenna design from the critical path. Its cost is the price: about $25 more per +unit than V1's reader, about $625 over 25 units. + +**Evaluate option C separately, as a cost-down for a bulk buy.** If 50 units are on the table, the +roughly $27 per-unit saving (about $1,350) may pay for the antenna and firmware work. It should be +proven on a small test board (EM4095, PCB antenna, ESP32 dev board) before it goes onto the main +board. The main board's reader zone can be laid out so a later revision swaps the ID-12LA socket for +the EM4095 antenna without moving anything else. + +What this does not fix: the ID-12LA is still effectively single-source. The Wiegand header is the +hedge, and option C is the long-term exit. ## 5. Load switching -Ratings needed are **unknown**: the repo has no list of controlled machines with voltages and -full-load amps. **Jason: please list each machine (or planned machine) with supply voltage, FLA, -and how V1 switches it today (box relay directly, external relay, contactor, SSR, coil voltage).** - -**Recommendation: keep V1's design intent and make it explicit: the box's relay is a low-voltage -pilot contact only; an external contactor or SSR in a junction box switches the machine.** - -* The M12 A-coded 8-pin connector is rated 30 V and 2 A per contact (section 1.4). Mains on pins 3 and 4 would be outside the - connector's rating and would put mains in the same cable as the 5 V supply and GPIO lines. So - the relay contact on pins 3/4 should switch only SELV: a 24 VAC/VDC contactor coil, a 5 V or - 12 V relay coil, an SSR's DC input, or a machine's own low-voltage control circuit. - **[assumed] that no deployed unit runs mains through the M12 today; Jason please confirm.** If - some do (for example a 120 VAC contactor coil), those junction boxes should get an interposing - 5 V relay or SSR powered from the 5 V supply already in the junction box. -* On-board relay: a 5 V coil relay rated at least 5 A, with **reinforced coil-to-contact - insulation** (the Hongfa HF115F/005-1HS3 has 5 kV coil-contact dielectric strength, 10 mm creepage and reinforced insulation per VDE 0700/0631 [confirmed from a copy of the Hongfa datasheet, not from hongfa.com]), even though only SELV should be switched. That is cheap insurance - against a junction box wired wrong. Add a board slot between coil and contact copper, and keep - at least 8 mm creepage from the contact traces to anything on the logic side, so the board does - not rely on the "SELV only" rule for safety. -* Contact rating for inductive loads: a contactor coil has an inrush of several times its holding - current. Size the relay for that (5 A or more resistive gives margin), and fit suppression at the - coil in the junction box: a flyback diode for DC coils, an RC snubber or MOV for AC coils. - [assumed] that the coil inrush of the contactors in use is under the M12's 2 A per contact; this - needs checking against the contactor datasheets once Jason lists them. -* Relay driver: AO3400A N-MOSFET low-side, 10 kΩ gate pull-down, 1N4148W flyback across the coil. - The relay is open whenever GPIO33 is not actively driven high: during reset, during boot (all - GPIOs come up as inputs), in brown-out reset, and with the ESP32 removed or unpowered. - GPIO33 is not a strapping pin. Espressif's IO_MUX table (ESP32 datasheet, Appendix A) shows GPIO33 with output and input disabled and no pull at and after reset [confirmed]. -* SSR on board: rejected. A triac SSR leaks current when off (an "off" machine can still have a - few mA on its terminals), needs a heatsink above a few amps, and puts mains on the board. -* **Second relay (M12 pin 6):** V1 wires GPIO14 straight to pin 6 as a 3.3 V logic output that - drives an external relay module. V2 keeps pin 6 as a 3.3 V logic output so existing second-relay - junction boxes still work, but drives it through a 74LVC1G08 AND gate whose inputs are GPIO14 - and the primary relay drive, with a series resistor and ESD clamp on the output. That enforces in - hardware what the server already does (the second relay only energizes while the primary relay - does), and it masks anything GPIO14 does during boot while GPIO33 is low. Espressif's IO_MUX table shows GPIO14 with its weak pull-up **enabled** after reset until firmware configures the pin [confirmed], so on V1 the external relay module on pin 6 sees a weakly pulled-up line during boot; whether that is enough to trigger a given module is [assumed] and should be scoped on a V1 unit. The often-repeated "GPIO14 outputs PWM at boot" claim has no Espressif source that could be found. - No firmware change. - -What the relay does on any reset: **it opens.** With a normal (non-latching) relay there is no -way to keep a load on through an ESP32 reset without adding a hold circuit, and the constitution -requires relays to default off. The firmware already avoids self-reboots while the relay is on -(the liveness watchdog defers), so a reset that drops the load only happens when the firmware is -too wedged to run its own watchdog, and in that state the Oops button does not work either. See -section 7. +All load paths are ≤1 A SELV pilot circuits: a VFD's logic input or the 5 VDC coil of the relay in +the separate mains enclosure; anything over 1 A goes through an external relay/contactor +[confirmed by Jason]. So the board needs a small pilot relay, not a power relay. + +**Recommendation: Omron G5V-1-DC5 signal relay** (or equivalent) on M12 pins 3/4. + +* Gold-clad contacts with a minimum load of about 1 mA at 5 VDC and a 1 A rating [snapshot: LCSC + C28695 page text and RS spec sheet; Omron's datasheet could not be fetched, confirm before + ordering]. That matters because a VFD input switches only a few mA, below what the silver + contacts of V1's 10 A relay module reliably switch [assumed: typical power-relay minimum load is + around 10 to 100 mA]. +* Mechanical contact: tolerant of the coil kickback from the 5 V relay in the mains enclosure, and + works for AC or DC. +* Alternative: a PhotoMOS solid-state relay such as Toshiba TLP241A (40 V, 2 A, LCSC C2152214, + $1.55 at 1 [snapshot]). No wear and silent, but it needs a TVS across the output to survive coil + kickback if the mains enclosure's relay has no flyback diode, and it leaks a little when off. + Reasonable if relay chatter or wear ever becomes an issue. +* **Fail-safe:** AO3400A low-side driver with a 10 kΩ gate pull-down and a flyback diode. The relay + is open whenever GPIO33 is not actively driven: during reset, boot and brown-out, and with the + ESP32 unpowered. Espressif's IO_MUX table shows GPIO33 with output disabled and no pull at and + after reset [confirmed, ESP32 datasheet Appendix A]. +* **Second relay (M12 pin 6):** stays a 3.3 V logic output so existing second-relay setups still + work, driven through a 74LVC1G08 AND gate (GPIO14 AND the primary relay drive), with a series + resistor and ESD clamp. GPIO14's weak pull-up is enabled after reset until firmware configures it + [confirmed, same table], so on V1 the line floats weakly high during boot; the AND gate blocks + that while GPIO33 is low, and enforces in hardware what the server already does (second relay + only while the primary is on). No firmware change. The common "GPIO14 outputs PWM at boot" claim + has no Espressif source. +* On any reset the relay opens. With a non-latching relay there is no way to hold a load through + an ESP32 reset, and the constitution requires relays to default off. The firmware already avoids + self-reboots while the relay is on (section 7). +* Suppression at the far end: the 5 V relay in each mains enclosure should have a flyback diode + across its coil [assumed: most 5 V relay modules include one; check the ones in use]. ## 6. Power input -**Recommendation: keep an external 5 V supply via M12 pins 1 and 2. No mains on the board.** - -* Mains on the board would mean: mains creepage and clearance on the board, a fuse and probably a - certified PSU module, an earth-bonded or double-insulated enclosure rated for mains, and mains in - the box next to a reader the user touches. V1 already has a 5 V supply in the junction box (or - uses the machine's own supply), so there is no gain worth that. -* Wide-input (for example 12 or 24 V via a buck converter) was considered, because many machines - have 24 V control supplies. It would change the meaning of M12 pin 1 for every deployed junction - box, so it is listed as an open question rather than recommended. -* 3.3 V rail: a 1 A LDO (AP7361C-33) from 5 V. The ESP32 draws up to about 500 mA in WiFi - transmit bursts [confirmed, Espressif datasheet]; AMS1117 is cheaper but its 1.1 V dropout - leaves little margin once the input protection drops a few hundred mV, so it is not - recommended. -* 5 V budget [assumed, to measure on a prototype]: ESP32 about 250 mA average, LCD backlight about - 30 mA, relay coil about 80 mA (HF115F 5 V coil, 62 Ω), WS2812 up to 60 mA at full white, reader about 50 mA. Under - 0.5 A in total, well within V1's 2.5 A supply and the M12's 2 A per contact. +**Keep the external 5 V supply on M12 pins 1/2** [confirmed by Jason: the mains enclosure, or the +machine, provides it]. No mains on the board. -## 7. Protection, reset and watchdog - -Input (M12 pins 1/2): +* 3.3 V main rail: AP7361C-33 (1 A LDO). The ESP32 draws up to about 500 mA in WiFi transmit + bursts. AMS1117 is cheaper, but its 1.1 V dropout leaves little margin after the input protection. +* Reader rail: a separate AMS1117-3.3 (JLCPCB Basic part) for the ID-12LA, which asks for a + clean linear-regulated supply; at about 35 mA load the dropout is not a problem. +* 5 V loads [assumed, measure on a prototype]: ESP32 about 250 mA average, LCD backlight about + 30 mA, relay coil about 30 mA (G5V-1, [assumed]), status LED up to 60 mA, reader 35 mA, button + LED up to 20 mA. Well under 0.5 A in total, within the M12's 2 A per contact. -* PTC resettable fuse, 1.1 A hold (1812). -* Reverse-polarity protection: AO3401A P-MOSFET (lower drop than a Schottky diode). -* TVS diode, SMBJ5.0A, after the fuse. -* Bulk capacitance (47 to 100 µF) plus a ferrite on the 5 V rail feeding the relay coil, to keep - relay switching and motor noise away from the 3.3 V LDO. +## 7. Protection, reset and watchdog -Signals: +Input (M12 pins 1/2): 1.1 A PTC resettable fuse, AO3401A reverse-polarity P-MOSFET, SMBJ5.0A TVS, +47 to 100 µF bulk capacitance, and a ferrite between the relay/LED 5 V and the LDO inputs. -* ESD arrays (SRV05-4 or similar) on every off-board signal: reader D0/D1/CST, button switch and - LED, LED data, I2C, M12 pins 5, 6, 7, 8. -* Series resistors (about 100 to 330 Ω) on off-board inputs so the ESD diodes are not the only - current limit. -* The relay contact side (M12 pins 3/4) is isolated from logic by the relay itself and the board - slot; no ESD parts on it. +Signals: ESD arrays (SRV05-4) and series resistors on every off-board line: M12 pins 5 to 8, the +button and its LED, and the external-LED header. The reader, LCD and on-board LED no longer leave +the board, which removes most of V1's exposed lines. Reset and brown-out: -* ESP32 internal brown-out detector stays on (ESPHome default) [assumed default, verify]. -* **Voltage supervisor on EN** (APX803-class, about 2.9 to 3.1 V threshold) instead of the usual - RC on EN. The plain RC is known to give unreliable starts on slowly rising supplies such as a - long cable or a soft-start supply [assumed from common ESP32 practice]. The supervisor holds the - chip in reset until 3.3 V is good and resets it cleanly on a sag. +* ESP32 internal brown-out detector stays on [assumed ESPHome default, verify]. +* **APX803S-29 voltage supervisor on EN** in place of the usual RC, so the chip starts cleanly on a + slowly rising supply (long cable, soft-start supply) and resets cleanly on a sag [assumed from + common ESP32 practice]. External watchdog (problem 2): -* The lockups in the analysis docs were the main loop stuck inside an HTTP call that kept feeding - the task watchdog. The firmware now bounds that call and panics the task WDT (60 s), and enables - the RTC watchdog. An external watchdog would add an independent check that the ESPHome main loop - is alive, in case the on-chip watchdogs are ever misconfigured again. -* The case it covers is "loop dead", and in that case the Oops button and LCD are dead too, so - resetting and dropping the relay is the safe outcome. The case where Bronte deliberately kept its - relay on mid-cut was "loop alive, server unreachable", which the firmware handles and the - external watchdog would never see, as long as it is kicked from the main loop. -* **Recommendation: footprint only, not populated by default.** A TPL5010 timer (resistor-set - timeout) with its reset output into EN, a timeout of about 120 s (longer than the 60 s task WDT, - so the on-chip watchdog fires first), kicked from a spare GPIO (GPIO25) by an ESPHome - `interval:`. Populating it needs that firmware change, which is out of scope here. A DNP - resistor in the reset path keeps it from doing anything until it is deliberately enabled. -* EN reset is enough; a full power cycle of the board is not needed, because an EN reset restarts - the ESP32 exactly as a power cycle does and the LCD/reader recover on their own [assumed, the - analysis docs recovered with power cycles, never EN resets; verify on a prototype]. +* The documented lockups were the main loop stuck in an HTTP call that kept feeding the task + watchdog. Firmware now bounds that call and panics the task watchdog after 60 s. An external + watchdog would be an independent check that the main loop is alive. +* That case ("loop dead") is also the case where the Oops button does nothing, so resetting and + dropping the relay is the safe outcome. Bronte's deliberate relay-on-mid-cut case was "loop alive, + server unreachable", which the firmware handles and an external watchdog kicked from the main loop + never sees. +* **Recommendation: footprint only, not fitted.** TPL5010 timer, about 120 s timeout (longer than the + 60 s task watchdog), reset output to EN through a not-fitted resistor, kicked from GPIO25 by an + ESPHome `interval:`. Fitting it needs that firmware change. ## 8. Current sensing and the "machine switch left ON" problem -* **The board cannot detect the machine switch position while its relay is open**, because no - current flows and the board (by design) sees no mains. The only pre-emptive fixes are at the - machine: an NVR (no-volt release) paddle switch or a magnetic starter, which drops out when power - is removed and so cannot be "left ON", or an auxiliary contact on the machine switch wired back - to an input. NVR switches are the standard practice and the recommendation for problem 1. -* What a current input adds: after the relay closes on a login, firmware can see current within a - few hundred ms. Firmware could then open the relay and show "turn machine switch off" if current - appears before the operator presses start. The motor would still twitch. That is a mitigation, - not a fix. -* **Recommendation: include the CT input now, firmware later.** It is a handful of passives: a - burden resistor (or none, for a voltage-output CT), a 1.65 V mid-rail bias, an RC filter and an - ESD clamp, into ADC1 on GPIO36 (ADC2 cannot be used with WiFi on). ADC1 is GPIO32 to 39 per the ESP-IDF GPIO docs [confirmed].. Sensor: a split-core - voltage-output CT such as the YHDC SCT-013-030 (30 A, 1 V output) clamped on one machine - conductor inside the junction box, wired to M12 pins 7 and 8. ESPHome supports this through the - `ct_clamp` sensor platform. [confirmed: https://esphome.io/components/sensor/ct_clamp/; reads an `adc` sensor, needs `attenuation` set because the ESP32 ADC tops out near 1.1 V by default] -* `esphome-configs/` has only `no-current-input.yaml`; a future `current-input.yaml` would add - the `ct_clamp` sensor (section 10). No current-input config exists today [confirmed]. +* The board cannot detect the machine switch position while its relay is open: no current flows and + the board sees no mains. Pre-emptive fixes are at the machine: an NVR (no-volt release) paddle + switch or magnetic starter, or an auxiliary contact on the machine switch wired back to an input. + **NVR switches are the recommendation for problem 1.** +* A current input lets future firmware see current within a few hundred ms of the relay closing, + then open the relay and show "turn machine switch off" if current flows before the operator + presses start. The motor would still twitch. That is a mitigation, not a fix. +* **Recommendation: include the CT input now, firmware later.** Burden resistor footprint, 1.65 V + bias, RC filter and ESD clamp into GPIO36 (ADC1; ADC2 cannot be used with WiFi) [confirmed ADC1 = + GPIO32 to 39, ESP-IDF docs]. Sensor: a voltage-output split-core CT such as the YHDC SCT-013-030 + (30 A, 1 V) on one machine conductor inside the mains enclosure, wired to M12 pins 7/8. ESPHome's + `ct_clamp` sensor platform reads it through an `adc` sensor [confirmed, esphome.io]. +* No current-input ESPHome config exists today [confirmed: only `no-current-input.yaml`]. ## 9. Programming and debug -* **USB-C with a CH340C USB-UART and the standard two-transistor auto-reset circuit**, plus BOOT and - EN tactile buttons. First flash and serial logs need nothing but a USB-C cable. USB VBUS feeds the - 5 V rail through a Schottky diode so a board can be flashed and bench-tested without M12 power, - and so USB cannot back-feed a junction box supply. -* A 2.54 mm header with TX, RX, GND, 3.3 V, EN, GPIO0 for an external adapter or logic analyzer. -* **OTA stays the production path** (`ota: platform: esphome` in the config, see - `docs/source/hardware.rst` ESPHome section). USB is for first flash and bench work only; the USB - connector is inside the box. +* USB-C with a CH340C USB-UART and two-transistor auto-reset, plus BOOT and EN buttons. VBUS feeds + the 5 V rail through a Schottky diode, so a board can be flashed and bench-tested without M12 + power and cannot back-feed the mains enclosure's supply. +* A 2.54 mm header with TX, RX, GND, 3.3 V, EN and GPIO0 for an external adapter or logic analyzer. +* **OTA stays the production path** (`ota: platform: esphome`). The USB connector is inside the + housing. ## 10. Firmware compatibility (pin map) -Every pin the current config (`esphome-configs/2025.11.2/no-current-input.yaml`) uses stays on the -same GPIO, so **the existing config works unchanged** on the V2 board. - | Function | V1 GPIO | V2 GPIO | Change | |---|---|---|---| -| Wiegand D0 | 16 | 16 | none (through 5 V-tolerant buffer) | -| Wiegand D1 | 4 | 4 | none (through buffer) | -| Card present (CST) | 18 | 18 | none (through buffer) | -| LCD SDA / SCL | 22 / 23 | 22 / 23 | none (PCA9306 replaces the level converter) | -| Status LED data | 27 | 27 | none (74AHCT1G125 replaces the level converter) | -| Oops button | 32 | 32 | none (internal pull-up still used; V1 wires the switch's NC contact, so an unplugged button cable reads as "Oops pressed", and V2 keeps that) | -| Oops LED | 5 | 5 | none | +| Reader data | Wiegand D0 16, D1 4 | **ID-12LA serial out → 16** (UART RX); Wiegand header keeps D0 16, D1 4 | config change if the ID-12LA is fitted (below) | +| Card present | 18 (`CST`) | 18 (ID-12LA Tag-in-Range, or header `CST`), with a pull-down | none; both are active high | +| LCD SDA / SCL | 22 / 23 | 22 / 23 | none: PCF8574 on the board at address 0x27, powered from 3.3 V, driving a 5 V LCD | +| Status LED data | 27 | 27 | none, except `rgb_order` for the LED fitted (below) | +| Oops button | 32 | 32 | none; the NC wiring is kept, so an unplugged button cable reads as "Oops pressed" | +| Oops LED | 5 | 5 | none; now drives a MOSFET, same polarity | | Primary relay | 33 | 33 | none | -| Second relay (M12 pin 6) | 14 | 14 | none; output now ANDed with the relay drive in hardware | -| Tamper (M12 pin 5) | 12 | **35** | moved off strapping pin GPIO12; not used by any config today | -| CT clamp (M12 pins 7/8) | none | **36** | new; not used by any config today | -| External watchdog kick | none | **25** | new; only if the DNP watchdog is fitted | - -Why GPIO12 must move: GPIO12 (MTDI) is a strapping pin that sets the flash voltage at reset. A -tamper switch with a pull-up that holds it high during reset selects 1.8 V flash on a module whose -flash needs 3.3 V, and the board fails to boot. (ESP32 datasheet section 3.2; the WROOM-32E datasheet says "IO12 should be kept low when the module is powered on" [confirmed]; that a high level stops the board booting is an inference from the 1.8 V flash supply, not a quoted Espressif statement). GPIO35 is input-only with no internal -pull-up, so the board adds an external 10 kΩ pull-up. +| Second relay (M12 pin 6) | 14 | 14 | none; ANDed with the relay drive in hardware | +| Tamper (M12 pin 5) | 12 | **35** | moved off strapping pin GPIO12; no config uses it today | +| CT clamp (M12 pins 7/8) | none | **36** | new; no config uses it today | +| External watchdog kick | none | **25** | new; only if the not-fitted watchdog is fitted | + +Why GPIO12 must move: GPIO12 (MTDI) sets the flash supply voltage at reset, and the WROOM-32E +datasheet says "IO12 should be kept low when the module is powered on" [confirmed]. A tamper switch +pulling it high during reset selects a 1.8 V flash supply for 3.3 V flash, so the board would not +boot [inference from that]. GPIO35 is input-only with no internal pull-up, so the board adds one. + +PCF8574 at 3.3 V driving a 5 V LCD: ESPHome's `lcd_pcf8574` driver only writes and never reads the +LCD (`pcf8574_display.cpp`) [confirmed], and the HD44780's logic-high threshold at 5 V is about +2.2 V [assumed from the Hitachi datasheet; verify on the prototype]. This removes the level +shifter and the I2C backpack. + +Status LED colour order: V1's config uses `rgb_order: RGB` for LEDs cut from a string. Genuine +WS2812B and most through-hole addressable LEDs are GRB [assumed; check the part fitted]. + +**Config diff for an ID-12LA-fitted board (proposal only, not applied to any config):** + +```diff +-wiegand: +- - id: keypad +- d0: GPIO16 +- d1: GPIO4 +- on_tag: +- - lambda: ESP_LOGI("TAG", "received tag %s", x.c_str()); +- - lambda: |- +- id(rfid_tag) = x.c_str(); +- ... +- - script.execute: post_to_mac ++uart: ++ - id: rfid_uart ++ rx_pin: GPIO16 ++ baud_rate: 9600 ++ ++rdm6300: ++ uart_id: rfid_uart ++ on_tag: ++ # rdm6300 fires on every frame while the card is held; act only on a new tag ++ - if: ++ condition: ++ lambda: 'return to_string(x) != id(rfid_tag);' ++ then: ++ - lambda: ESP_LOGI("TAG", "received tag %u", x); ++ - lambda: |- ++ id(rfid_tag) = to_string(x); ++ ... ++ - script.execute: post_to_mac +``` -Status LED colour order: the V1 config sets `rgb_order: RGB` because V1 uses LEDs cut from a -string. A genuine WS2812B is GRB. Builders who use a WS2812B on the LED header need -`rgb_order: GRB`; this is a property of the LED, not the board. +`to_string(x)` of the 32-bit ID is the same decimal string the `wiegand` component emits for a +34-bit frame, and the server zero-pads both to 10 digits, so no fob data changes [confirmed from +`rdm6300.cpp` line 49 and `wiegand.cpp` lines 83 to 93]. The `card_present` binary sensor on GPIO18 +and its `on_release` logout are unchanged. -Proposed config additions for later (**proposal only, not applied to any config**): +Proposed later additions (proposal only): ```yaml binary_sensor: - platform: gpio - pin: GPIO35 # tamper switch, M12 pin 5; external pull-up on the V2 board + pin: GPIO35 # tamper switch, M12 pin 5; external pull-up on the board name: "Tamper" - id: tamper device_class: tamper sensor: - platform: adc - pin: GPIO36 # CT clamp, M12 pins 7/8, biased to mid-rail on the V2 board + pin: GPIO36 # CT clamp, M12 pins 7/8, biased to mid-rail on the board id: ct_adc attenuation: 12db update_interval: never @@ -426,150 +404,120 @@ sensor: ## 11. Draft BOM -Prices looked up 2026-11-25. "Board BOM" means parts on the controller board; lid parts, M12 -connector and enclosure carry over from V1 unchanged. - -Unit prices are LCSC's price at its quantity-10 break, or the nearest break when 10 is not one -(noted). "Class" is the JLCPCB assembly library class: Basic parts have no loading fee, each -unique Extended part has one. Source URL pattern: `https://www.lcsc.com/product-detail/.html`. +Unit prices are LCSC's price at its quantity-10 break, or the nearest break (noted), read +2026-11-25. "Class" is the JLCPCB assembly class: Basic parts have no loading fee, each unique +Extended part has one. URL pattern: `https://www.lcsc.com/product-detail/.html`. -### Controller board +### Board (option B reader) | Ref | Function | Manufacturer / MPN | LCSC # | Qty | Unit (USD) | Class | |---|---|---|---|---|---|---| -| U1 | MCU module | Espressif ESP32-WROOM-32E-N4 | C701341 | 1 | 3.3129 | Extended | +| U1 | MCU module | Espressif ESP32-WROOM-32E-N4 (or -32UE-N4, C701344) | C701341 | 1 | 3.3129 | Extended | | U2 | USB-UART | WCH CH340C | C84681 | 1 | 0.4594 | Extended | -| J1 | USB-C receptacle | Korean Hroparts TYPE-C-31-M-12 | C165948 | 1 | 0.1888 (qty 5 break) | Extended | +| J1 | USB-C receptacle | Korean Hroparts TYPE-C-31-M-12 | C165948 | 1 | 0.1888 (qty 5) | Extended | | U3 | 3.3 V 1 A LDO | Diodes AP7361C-33E-13 | C500795 | 1 | 0.8833 | Extended | -| U4 | Reset supervisor, 2.93 V, open drain | Diodes APX803S-29SA-7 | C143831 | 1 | 0.2862 | Extended | -| U5 | External watchdog timer (**DNP**) | TI TPL5010DDCR | C473912 | 0 | 0.2727 | Extended | -| K1 | Relay, 5 V coil, 10 A 250 VAC, reinforced | Hongfa HF115F/005-1HS3 | C81373 | 1 | 1.9224 | Extended (THT) | -| Q1 | Relay driver | AOS AO3400A | C20917 | 1 | 0.0786 (qty 5 break) | Basic | -| Q2 | Reverse-polarity PFET | AOS AO3401A | C15127 | 1 | 0.0827 (qty 5 break) | Basic | -| D1, D2 | Relay flyback, misc. | JSCJ 1N4148WS | C2128 | 2 | 0.0098 (qty 50 break) | Basic | -| U6 | 2nd-relay AND gate | SN74LVC1G08DBVR (UMW) | C434068 | 1 | 0.0421 | Extended | -| U7 | LED data 3.3 → 5 V | TI SN74AHCT1G125DBVR | C7484 | 1 | 0.1109 (qty 5 break) | Extended | -| U8 | I2C 3.3 ↔ 5 V | TI PCA9306DCTR | C123752 | 1 | 0.3762 (qty 5 break) | Extended | -| U9 | Reader input buffer | TI SN74LVC125APWR | C7813 | 1 | 0.3518 (qty 5 break) | Extended | +| U4 | Reader 3.3 V LDO | AMS1117-3.3 | C6186 | 1 | 0.2032 (qty 5) | Basic | +| U5 | Reset supervisor | Diodes APX803S-29SA-7 | C143831 | 1 | 0.2862 | Extended | +| U6 | External watchdog (**not fitted**) | TI TPL5010DDCR | C473912 | 0 | 0.2727 | Extended | +| U7 | LCD I2C expander | NXP/TI PCF8574T | not priced | 1 | not priced | | +| K1 | Pilot relay | Omron G5V-1-DC5 | C28695 | 1 | not priced (RS UK GBP 2.57 [snapshot]) | Extended (THT) | +| Q1, Q2 | Relay driver, button LED driver | AOS AO3400A | C20917 | 2 | 0.0786 (qty 5) | Basic | +| Q3 | Reverse-polarity PFET | AOS AO3401A | C15127 | 1 | 0.0827 (qty 5) | Basic | +| D1, D2 | Flyback, misc. | JSCJ 1N4148WS | C2128 | 2 | 0.0098 (qty 50) | Basic | +| U8 | Second-relay AND gate | SN74LVC1G08DBVR (UMW) | C434068 | 1 | 0.0421 | Extended | +| U9 | LED data 3.3 → 5 V | TI SN74AHCT1G125DBVR | C7484 | 1 | 0.1109 (qty 5) | Extended | | D3 | Input TVS | MDD SMBJ5.0A | C113974 | 1 | 0.0592 | Extended | -| U10-U12 | ESD arrays (12 lines) | Protek SRV05-4-P-T7 | C85364 | 3 | 0.2214 (qty 5 break) | Extended | +| U10, U11 | ESD arrays | Protek SRV05-4-P-T7 | C85364 | 2 | 0.2214 (qty 5) | Extended | | F1 | PTC fuse, 1.1 A hold | Littelfuse 1812L110PR | C163516 | 1 | 0.0529 | Extended | -| J2-J4 | LCD, button, LED headers (LED uses pin 4 as a spare GND) | JST B4B-XH-A(LF)(SN) | C144395 | 3 | 0.0522 | Extended (THT) | -| J5 | Reader header | JST B5B-XH-A(LF)(SN) | C157991 | 1 | 0.091 (qty 5 break) | Extended (THT) | -| J6 | M12 lead terminal, plug half | Cixi Kefa KF2EDGK-3.81-8P | C440864 | 1 | 0.4448 | Extended (THT) | -| SW1, SW2 | BOOT, EN buttons | XKB TS-1187A-B-A-B | C318884 | 2 | 0.0198 (qty 20 break) | Basic | -| (passives) | about 40 resistors and capacitors | e.g. UNI-ROYAL 0603 1 k/10 k (C21190/C25804), 100 nF 0603 (C14663), 10 µF 0805 (C15850) | | 40 | 0.0015 to 0.0311 | Basic | -| | **Priced subtotal per board** | | | | **9.62 + at most 1.24 passives = 10.86** | | +| J2, J3 | Button header; external LED header | JST B4B-XH-A(LF)(SN) | C144395 | 2 | 0.0522 | Extended (THT) | +| J4 | Wiegand reader header (fallback) | JST B5B-XH-A(LF)(SN) | C157991 | 1 | 0.091 (qty 5) | Extended (THT) | +| J5 | M12 lead terminal, plug half | Cixi Kefa KF2EDGK-3.81-8P | C440864 | 1 | 0.4448 | Extended (THT) | +| SW1, SW2 | BOOT, EN | XKB TS-1187A-B-A-B | C318884 | 2 | 0.0198 (qty 20) | Basic | +| (passives) | about 40 R and C | UNI-ROYAL 0603 (C21190, C25804), 100 nF 0603 (C14663), 10 µF 0805 (C15850) | | 40 | 0.0015 to 0.0311 | Basic | +| | **Priced subtotal** | | | | **6.98 + at most 1.24 passives = 8.22** | | -Not yet priced (small parts, to price at schematic time): the PCB header half of the 8-position -3.81 mm terminal (KF2EDGR/KF2EDGV, not found on LCSC), two auto-reset NPN transistors, the USB -VBUS Schottky, the 5 V bulk capacitor and the ferrite bead. The passive line uses 40 times the -most expensive passive priced, as an upper bound. +Not priced yet: PCF8574T, the G5V-1 in USD, the 8-position terminal header half, the 16-pin LCD +header, the ID-12LA socket (2 mm pitch [assumed]), the through-hole addressable LED, auto-reset +transistors, USB Schottky, bulk capacitor, ferrite. The passive line uses 40 times the most +expensive passive priced, as an upper bound. -AP7361C vs AMS1117-3.3: the AMS1117-3.3 (C6186, $0.2032, **Basic**) would save about $0.68 per -board plus one $3.07 loading fee per order, but its 1.1 V dropout is too close to the margin -after input protection (section 6). Kept AP7361C. +### Front-face and panel parts -### Carried over from V1 (unchanged) - -| Item | Price | Source | +| Item | Unit (USD) | Source | |---|---|---| -| 16x2 LCD with PCF8574 I2C backpack | $3.99 | V1 table, November 2025, **not re-checked** (no current PCF8574-backpack listing found at a distributor; Adafruit's 16x2 LCD alone is $8.96 at qty 10, adafruit.com/product/181, 2026-11-25) | -| Wiegand RFID reader | $6.26 | V1 table, November 2025, **not re-checked** (AliExpress) | -| 16 mm Oops button + cover | $5.49 | V1 table, November 2025, **not re-checked** | -| WS2812-type LED | $0.32 | V1 table, November 2025, **not re-checked** | -| M12 8-pin socket + 2 m cable | $9.80 + ~$15.49 | V1 table, November 2025, **not re-checked**; no verified US distributor price found on 2026-11-25 for the Phoenix Contact 1436343 Pg9 socket (EUR snippets only) | -| Enclosure + card holder | $9.90 | V1 table | +| ID Innovations ID-12LA (SparkFun SEN-11827) | 32.50 (1), 30.88 (25+), 29.25 (100+) | sparkfun.com, 2026-11-25 | +| 16x2 HD44780 LCD, bare (Adafruit 181) | 8.96 (10 to 99), 7.96 (100+) | adafruit.com/product/181, 2026-11-25; cheaper bare 1602 LCDs exist but no distributor price was found | +| 16 mm Oops button + cover | 5.49 | V1 table, Nov 2025, not re-checked | +| Addressable LED | 0.32 | V1 table, Nov 2025, not re-checked (12 mm string LED); through-hole part not priced | +| M12 socket + 2 m cable | 9.80 + about 15.49 | V1 table, Nov 2025, not re-checked; no US distributor price found for the Phoenix Contact 1436343 | +| Housing | 9.90 | V1 table (V1 printed enclosure) as a placeholder; the new housing is not designed yet | +| YHDC SCT-013-030 CT, only where current sensing is used | 12.90 to 15.33 | retailer search results [snapshot] | -Options for the hardened outdoor build: +### Option C reader parts (for the cost-down evaluation) | Item | Price | Source | |---|---|---| -| IP65 16 mm LED pushbutton, Olimex BUTTON-16MM-RED (LED 3 to 5 V) | EUR 1.80 at 10+ | olimex.com product page, from a search snippet, **unverified** | -| Adafruit 558 16 mm LED pushbutton (3 to 6 V LED; gasket, no IP rating) | $4.46 at 10 | adafruit.com/products/558, 2026-11-25 | -| YHDC SCT-013-030 CT (30 A, 1 V out), only when current sensing is wanted | $12.90 to $15.33 | retailer search snippets, **unverified**; no DigiKey/Adafruit listing found | +| EM Microelectronic EM4095HMSO16A+/B+ | about 2.85 at 100+ (LCSC, out of stock); EUR 4.30 at 1 (TME) | [snapshot] | +| Antenna | PCB copper, about 120 µH (EM demo board) | EM AN404 [confirmed] | +| Resonant and filter capacitors | about 6 C0G/X7R capacitors | Basic passives | ## 12. DFM, ordering and cost -* **Board:** 2 layers, 1.6 mm FR-4, HASL, about 100 x 80 mm or smaller, single panel per board (no - panelization needed at these quantities; JLCPCB's price is per board up to 100 x 100 mm). -* **Assembly:** JLCPCB **Economic** PCBA, single-sided. All SMT on one face. Through-hole parts - (relay, JST headers, terminal header) are either added by JLCPCB's hand-soldering service or - soldered by us; both keep a hand-solder path, and a fully hand-built board is possible because - the ESP32 module has castellated pads and every SMT part is 0603, SOT-23, SOIC or TSSOP. -* **Extended parts:** 12 unique SMT Extended part types (U1-U4, J1, U6-U9, D3, F1, and the SRV05-4 used three times), each - with a $3.07 loading fee per order on Economic PCBA ([assumed] per unique part; JLCPCB's page - does not say so explicitly). Swapping parts to Basic equivalents is the main lever on small-batch - cost; it is a schematic-time decision. -* **JLCPCB published fees** (jlcpcb.com/help/article/pcb-assembly-price, updated 2026-10-22, - read 2026-11-25): Economic setup $8.18, stencil $1.53, $0.0016 per SMT joint, $3.07 per - Extended part, $0.45 parts-placement confirmation, $3.58 hand-soldering labor per order. -* **PCB quote** (cart.jlcpcb.com/quote, 100 x 80 mm, page defaults, 2026-11-25): $4.00 for 5, - $5.00 for 10 (both marked "Special Offer"), $19.40 for 20. UPS shipping shown as $25.99. - The 2-layer / 1.6 mm defaults were [assumed], not re-checked on the form. -* **Lead time:** not looked up for this order shape; JLCPCB's Economic PCBA is typically days - plus shipping [assumed]. Get the real figure with the live quote in Milestone 2. -* **Supply risk:** the RFID reader (single AliExpress source) is the only part with real supply - risk; the board's 5 V-tolerant reader input and 5 V reader supply are there so a different - Wiegand reader with a card-present output can replace it. The ESP32-WROOM-32E has a long - longevity commitment and deep stock. The M12 socket and cables are multi-source. +* **Board:** 2 layers, 1.6 mm FR-4, HASL, about 150 x 85 mm, one board per panel. +* **Assembly:** JLCPCB Economic PCBA, single-sided (all SMT on the back face). Through-hole parts + (LCD header, reader socket, LED, relay, terminal, JST headers) by JLCPCB's hand-soldering service + or by us. A full hand build is possible: the module has castellated pads and the smallest parts + are 0603 and SOT-23. +* **JLCPCB fees** (jlcpcb.com/help/article/pcb-assembly-price, updated 2026-10-22, read + 2026-11-25): Economic setup $8.18, stencil $1.53, $0.0016 per SMT joint, $3.07 per Extended part + type ([assumed] per unique part), $0.45 placement confirmation, $3.58 hand-soldering labour per + order. With 11 Extended SMT part types (U1, U2, J1, U3, U5, U7, U8, U9, D3, U10/U11, F1; the PCF8574's class is [assumed] Extended) the fixed + fees are **$43.93 per order**. +* **PCB price at 150 x 85 mm: not quoted.** The quote calculator could not be read by the research + agent. The first revision's quote was $5.00 for 10 at 100 x 80 mm; above 100 x 100 mm the price + rises. Get a live quote in Milestone 2. +* **Supply risk:** the reader (4.3) is the main one. The ESP32 module is in deep stock with a long + longevity commitment; the M12 parts are multi-source. ### Cost comparison with V1 -V2 replaces only these V1 items: ESP32 dev board $5.66, screw-terminal breakout $8.13, level -converter $0.75, relay module $1.29, a total of **$15.83** (V1 table, November 2025 prices, not -re-checked). Everything else in the $67.08 control box carries over. +Per control box, using priced items only (the board subtotal of $8.22, fixed fees spread over the +order, the ID-12LA, the bare LCD, and V1 prices for the button, LED, M12 parts and housing +placeholder). The PCB itself, shipping, and the unpriced parts above are **not** included. -Rough V2 controller board cost, from the prices above (qty-10 LCSC prices used for both -quantities, which overstates the 20-board case slightly; about 250 SMT joints per board -[assumed]): +| | V1 | V2, 10 boards | V2, 25 boards | V2, 50 boards | +|---|---|---|---|---| +| Board parts | (dev board, breakout, level converter, relay module) $15.83 | $8.22 | $8.22 | $8.22 | +| JLCPCB fixed fees per board | n/a | $4.39 | $1.76 | $0.88 | +| Reader | $6.26 | $32.50 | $30.88 | $30.88 | +| LCD | $3.99 (with backpack) | $8.96 | $8.96 | $8.96 | +| Button, LED, M12 + cable, housing | $41.00 | $41.00 | $41.00 | $41.00 | +| **Total** | **$67.08** | **$95.07 + PCB + unpriced** | **$90.82 + PCB + unpriced** | **$89.94 + PCB + unpriced** | -| Line | 10 boards | 20 boards | -|---|---|---| -| PCBs | $5.00 | $19.40 | -| Economic PCBA setup + stencil + placement confirmation | $10.16 | $10.16 | -| Extended-part loading fees (12 × $3.07) | $36.84 | $36.84 | -| SMT joints (250 × $0.0016 per board) | $4.00 | $8.00 | -| Board parts ($10.86 per board) | $108.60 | $217.20 | -| Shipping (quoted UPS) | $25.99 | $25.99 | -| **Total** | **$190.59** | **$317.59** | -| **Per board** | **$19.06** | **$15.88** | - -Not included: the unpriced small parts listed under the BOM, THT soldering (our time, or -JLCPCB's $3.58 per order plus per-joint fees), tariffs/duties, and any CT clamp. - -So, per control box: - -| | V1 | V2 at 10 | V2 at 20 | -|---|---|---|---| -| Replaced electronics | $15.83 | $19.06 | $15.88 | -| Control box total | $67.08 | about $70.31 | about $67.13 | - -**Conclusion: V2 is roughly cost-neutral, not a saving.** The case for it is repeatable assembly, -input and ESD protection, a fail-safe relay driver, the GPIO12 boot fix, and the tamper/CT inputs, -not cost. The fixed fees dominate at these quantities, so ordering 20 instead of 10 costs about -$127 more for 10 extra boards. At the confirmed count of four units, 10 boards leaves six spares. +The reader is the whole difference: V2's board is cheaper than the V1 parts it replaces, and the +ID-12LA adds about $25 per unit. With option C the reader costs about $3 to $5 [snapshot], which +would bring V2 to about the V1 total or below. A 50-unit bulk buy does little for the board (fixed +fees are already small at 25) and saves nothing on the ID-12LA below the 100-unit break. ## 13. Safety and compliance notes for mains switching These are research notes on common practice, **not a certification or compliance claim**. -* **The external contactor stays mandatory** for motors and any load above the pilot relay's - rating. The box never carries mains (section 5 and 6). -* Junction box: a listed enclosure (V1 uses a Carlon PVC box), with cord grips or strain reliefs on - every cable, the machine's equipment-grounding conductor carried through and bonded, and +* **The external relay/contactor stays mandatory** for any load over 1 A [confirmed by Jason]. The + control box never carries mains (sections 5 and 6). +* Mains enclosure: a listed enclosure (V1 uses a Carlon PVC box), with cord grips or strain reliefs + on every cable, the machine's equipment-grounding conductor carried through and bonded, and contactors and supplies that are UL-recognized/listed parts rated for the load voltage and the motor's FLA (motor-rated, AC-3 or HP-rated contacts). * Switch every ungrounded conductor: both legs for 240 V machines (V1's 2-pole contactor option already does this), the hot (never the neutral) for 120 V. -* Overcurrent protection: the branch circuit protects the cord and contactor; the box's 5 V supply - is protected by its own internal fuse; a separate fuse on the 5 V supply's mains input is good +* Overcurrent protection: the branch circuit protects the cord and contactor; the 5 V supply is + protected by its own internal fuse; a separate fuse on the 5 V supply's mains input is good practice for supplies without one. * Clearance and creepage on any board that does carry mains: about 3 mm clearance and 4 mm creepage for basic insulation at 250 VAC, doubled for reinforced (from IEC 60664-1 tables, pollution - degree 2; check the exact figures before relying on them). This is why the recommendation keeps - mains off the board entirely. -* Labeling: label the junction box "controlled by access control; disconnect machine plug or + degree 2; check the exact figures before relying on them). This is why mains stays off the board. +* Labeling: label the mains enclosure "controlled by access control; disconnect machine plug or breaker before servicing", and label the machine with how to clear an Oops. The access-control relay is **not** a lockout/tagout disconnect and must not be used as one. * The access-control relay is also not an emergency stop. The Oops button is a request to the @@ -577,28 +525,23 @@ These are research notes on common practice, **not a certification or compliance ## 14. Open questions for Jason -1. **Unit count:** how many MAC units are in production now, and how many are planned? The repo's - `machines.json` is a test stub; the analysis docs name four. Board quantities in section 12 use - 10 and 20 boards (the four units named in the analysis docs plus spares and growth) [assumed] until this is answered. -2. **Machine list:** voltage, FLA, and current switching method (box relay direct, external relay, - contactor and its coil voltage, SSR) for each machine. -3. **Mains on M12:** does any deployed unit run mains (for example a 120 VAC contactor coil) through - M12 pins 3/4? -4. **Field failures:** have any V1 units failed from wiring, the screw-terminal breakout, or the - power feed (problem 4 is otherwise assumed)? -5. **Fob technology:** are the Neon fobs 125 kHz (EM4100-type)? That decides whether a 13.56 MHz - reader (PN532, which ESPHome supports with tag-removed events) is even an option later. -6. **Reader supply:** is the V1 AliExpress reader still orderable? If not, a 5 V Wiegand reader with - a card-present output is the fallback, which is why the board offers a 5 V reader supply. -7. **Wide-input power:** worth accepting 12/24 V on M12 pin 1 in a future revision, given that it - changes every junction box? -8. **Outdoor scope:** which movable tools are going outdoors, and do they need IP65 or is IP54 with - shade enough? This decides the LCD and button choice. -9. **Approval:** approve the recommendations (base-mounted board, keep M12 and pinout, ESP32-WROOM-32E, - pilot relay only, 5 V input, CT input and DNP watchdog footprints) so the implementation plan - below can start? -10. **Hardware layout:** OK to create `hardware/v2_mcu/` holding a KiCad project (schematic, PCB, - JLCPCB BOM/CPL exports, and a README) alongside the existing `hardware/v1_mcu/`? +1. **Reader:** approve rev A with the ID-12LA (about $31 per unit, small config change) plus the + Wiegand fallback header? And should option C (EM4095 + PCB antenna, about $27 per unit cheaper, + new ESPHome component) be evaluated on a small test board in parallel, given a possible bulk buy? +2. **V1 reader format:** can you confirm from a V1 ESPHome log that the reader sends 34-bit frames + (the log shows the bit count), or that a logged tag matches the 10-digit number printed on the + card? +3. **MCU:** OK with the module soldered on the board (section 3), with the whole board as the + field spare? +4. **Button and LED styles:** which button sizes should the faceplate design cover (16 mm only, or + 19/22 mm too), and is a through-hole 5 mm or 8 mm addressable LED on the board acceptable as the + default, with V1's 12 mm LED as the header option? +5. **Pilot relay:** G5V-1 signal relay (mechanical) or a PhotoMOS (TLP241A)? Do the 5 V relays in + the mains enclosures have flyback diodes? +6. **Hardware layout:** OK to create `hardware/v2_mcu/` holding a KiCad project (schematic, PCB, + JLCPCB BOM/CPL exports, README) alongside `hardware/v1_mcu/`? +7. **Approval:** approve the rest (lid-mounted board, M12 and V1 pinout, 5 V input, CT input and + not-fitted watchdog footprint, tamper on GPIO35) so the implementation plan can start? ## Implementation Plan @@ -607,28 +550,39 @@ before moving to the next. Commit prefix: `Custom MCU PCB - {Milestone}.{Task}`. ### Milestone 1: Schematic -* 1.1 Create `hardware/v2_mcu/` KiCad project and README (after question 10 is answered). -* 1.2 Schematic per sections 3 to 10, with LCSC part numbers on every SMT part. -* 1.3 Review: fresh reviewer checks pin map against the ESPHome config and the fail-safe relay path. +* 1.1 Create `hardware/v2_mcu/` KiCad project and README (after question 6). +* 1.2 Schematic per sections 3 to 10, with LCSC part numbers on every SMT part; price the parts + listed as not priced. +* 1.3 Review: a fresh reviewer checks the pin map against the ESPHome config and the fail-safe relay + path. ### Milestone 2: Layout and order files -* 2.1 Board outline and mounting per section 1.2; confirm the final outline back to the enclosure - effort. +* 2.1 Board outline, faceplate reference points and mounting per section 1; hand the outline to the + housing effort. * 2.2 Layout, DRC, JLCPCB BOM/CPL export. -* 2.3 Get a live JLCPCB quote; **Jason approves before any order is placed.** +* 2.3 Live JLCPCB quote; **Jason approves before any order is placed.** ### Milestone 3: Prototype bring-up -* 3.1 Flash the existing `hardware-test.yaml` and `no-current-input.yaml` unchanged; run +* 3.1 Flash `hardware-test.yaml` and `no-current-input.yaml` (with the reader diff from section 10 + in a copy, not in the committed config, until Jason approves a firmware change); run `esphome-configs/2025.11.2/hardware-test.md`. -* 3.2 Measure: relay state through power-up, EN reset, brown-out (variable supply) and with - GPIO14 toggled; 5 V current budget; RFID read range on a metal machine. -* 3.3 Fix-ups and a second revision if needed. +* 3.2 Measure: relay state through power-up, EN reset, brown-out and GPIO14 toggling; 5 V current; + ID-12LA Tag-in-Range behaviour and read range in the 3D-printed and metal housings; WiFi with the + 32E and 32UE modules. +* 3.3 Fixes and a second revision if needed. + +### Milestone 4 (optional): Option C reader evaluation + +* 4.1 Small test board: EM4095, PCB antenna per AN404, header to an ESP32 dev board. +* 4.2 Prototype ESPHome external component; measure read range and card-present reliability. +* 4.3 Decide with Jason whether a later revision moves to option C. -### Milestone 4: Acceptance Criteria +### Milestone 5: Acceptance Criteria -* 4.1 Update `docs/source/hardware.rst` with a Version 2 section (components, wiring, pinout). -* 4.2 Update `CLAUDE.md` if anything in it changes. -* 4.3 All nox sessions pass (no server code changes are expected). -* 4.4 Move this file to `docs/features/completed/`. +* 5.1 Update `docs/source/hardware.rst` with a Version 2 section (components, wiring, pinout). +* 5.2 Add a V2 ESPHome config (only after Jason approves the firmware change). +* 5.3 Update `CLAUDE.md` if anything in it changes. +* 5.4 All nox sessions pass. +* 5.5 Move this file to `docs/features/completed/`.