# FirebaseOTA 3x6 carrier - Rev A

The carrier board for the 3 x 6 wall unit.  It takes a pre-made **30-pin ESP32
DevKit V1**, an **HLK-PM01** 5 V supply, a fused mains input, a PZEM-004T
header, an I2C OLED header and **four Songle SRD-05VDC-SL-C onboard relays**
with driver transistors.

| Parameter | Value |
|---|---|
| Size | **130 x 70 mm** |
| Layers | 2, 1.6 mm FR-4 |
| Copper | 1 oz |
| Surface finish | HASL |
| Mounting | 4 x M3 at `(14,14)`, `(116,14)`, `(116,56)`, `(14,56)` |
| Wall-screw clearance | 4 x 4.5 mm at the patress centres |
| Cable cut-outs | 20 mm at `(99,43)`, 12 mm at `(80,55)` |
| Nets | 58 |
| Pads | 118 |
| Footprints | 21 |

![top view](preview_top.png)

The enclosure, print settings and assembly order are in
[`../README.md`](../README.md).

## Files

| File | Purpose |
|---|---|
| `FirebaseOTA_3x6_RevA_easyeda.json` | EasyEDA **Standard** PCB file, ready to import |
| `generate_easyeda.py` | Generates the JSON: outline, footprints, nets, pre-routes, silkscreen |
| `check_board.py` | Geometry and clearance checks (pads, holes, tracks, bodies, mains) |
| `export_docs.py` | Regenerates the BOM, CPL and netlist from the JSON |
| `render_preview.py` | Renders `preview_top.png` |
| `BOM_RevA.csv` | Bill of materials |
| `CPL_RevA.csv` | Pick-and-place / assembly positions |
| `NETLIST_RevA.md` | Net summary, connector pinouts and DevKit pin map |

The JSON is the source of truth for the layout; the Python files are the
generator and the checks.  Edit the generator, then re-run it, rather than
hand-editing the JSON.

## Importing into EasyEDA

The file is an **EasyEDA Standard** (not EasyEDA Pro) PCB document.

1. Open EasyEDA Standard and create a new project.
2. **File -> Import -> EasyEDA** (or drag the `.json` onto the canvas).
3. Select `FirebaseOTA_3x6_RevA_easyeda.json`.
4. Open the imported PCB.  You should see the 130 x 70 mm outline, 16
   footprints and the pre-routed mains/5 V sections.
5. Check the layer stack is 2-layer, 1.6 mm, and the design rules match your
   fab (see below).
6. Run **Design -> Check DRC** before routing the remaining nets.
7. Route the logic nets with the autorouter, or by hand.  Re-run DRC.

Do not import this file into EasyEDA Pro; the JSON schema is the Standard
format.  If you only have Pro, create the schematic/PCB from the netlist and
BOM instead.

## Design rules

Recommended starting rules for a low-cost 2-layer fab:

| Rule | Value |
|---|---:|
| Track / space | 0.2 / 0.2 mm |
| Minimum drill | 0.3 mm |
| Minimum annular ring | 0.13 mm |
| Copper to board edge | 0.3 mm |
| Mains track width | 1.5 mm |
| 5 V / GND track width | 1.0 mm |
| Signal track width | 0.25 mm |
| Mains-to-SELV pad clearance | >= 4 mm |
| Mains-to-SELV track clearance | >= 3 mm |

The generator already respects these for the pre-routed sections.  The
autorouter needs the same rules loaded, otherwise it will happily route a GPIO
track through the mains area.

## What is pre-routed

* `AC_L`, `AC_L_F`, `AC_N` on the top layer, 1.5 mm wide.
* `5V_RAW -> D1 -> 5V` and the `GND` return from the HLK, 1.0 mm.
* A 1.2 mm **isolation slot** under the HLK-PM01 between the AC and DC pins.

O everything else - the DevKit fan-out, the PCB-mounted Songle SRD relays with driver transistors, the PZEM header, the OLED header, the LED and the expansion header -
OLED header, the LED and the expansion header - is left to the autorouter.
Check the autorouter result carefully around the mains section and the two
cable cut-outs; the cut-outs are board holes, so copper must stay clear of
them.

## Connectors

### J8 - mains in / out (4-way 5.08 mm)

| Pin | Net | Use |
|---:|---|---|
| 1 | `AC_L` | Mains live in |
| 2 | `AC_L_F` | Fused live out to the load |
| 3 | `AC_N` | Mains neutral out to the load |
| 4 | `AC_N` | Mains neutral in |

Mains in on 1/4; switched load on 2/3.  F1 is in series between 1 and 2.  The
MOV clamps L-N on the incoming side.

The terminal is a 5.08 mm pitch part with 3.0 mm pads.  The pad-to-pad gap
between adjacent mains pins is about 2.1 mm; the terminal block's internal
barriers provide the creepage.  Keep the mains area clean and do not fit a
smaller-pitch terminal.

### J1 - GPIO expansion (2 x 12, 2.54 mm)

| Pin | Net | Pin | Net |
|---:|---|---:|---|
| 1 | `3V3` | 2 | `5V` |
| 3 | `GND` | 4 | `GND` |
| 5 | `GPIO2` | 6 | `GPIO4` |
| 7 | `GPIO5` | 8 | `GPIO12` |
| 9 | `GPIO13` | 10 | `GPIO14` |
| 11 | `GPIO16` | 12 | `GPIO17` |
| 13 | `GPIO18` | 14 | `GPIO19` |
| 15 | `GPIO21` | 16 | `GPIO22` |
| 17 | `GPIO23` | 18 | `GPIO25` |
| 19 | `GPIO26` | 20 | `GPIO27` |
| 21 | `GPIO32` | 22 | `GPIO33` |
| 23 | `GPIO34` | 24 | `GPIO35` |

Pins 1/2 are power, 3/4 ground, the rest are GPIO.  `GPIO34`/`GPIO35` are
input-only on the ESP32.

### J2 - PZEM-004T (1 x 4, 2.54 mm)

| Pin | Net |
|---:|---|
| 1 | `5V` |
| 2 | `GND` |
| 3 | `GPIO16` (RX) |
| 4 | `GPIO17` (TX) |

The PZEM module is external; J2 is a logic-level header, not a mains
connection.  The CT clamp goes around the live feed.  Keep the PZEM wiring
away from the mains tracks.

### J3 - OLED I2C (1 x 4, 2.54 mm)

| Pin | Net |
|---:|---|
| 1 | `3V3` |
| 2 | `GND` |
| 3 | `GPIO21` (SDA) |
| 4 | `GPIO22` (SCL) |

J3 sits at the top right, next to the OLED frame's FPC slot.  The bare panel's
FPC is at the top of the panel, so the cable run is short.

### J4-J7 - relay driver GPIO headers (1 x 3, 2.54 mm)

| Header | Pin 1 | Pin 2 | Pin 3 |
|---|---|---|---|
| J4 | `5V` | `GND` | `GPIO25` |
| J5 | `5V` | `GND` | `GPIO26` |
| J6 | `5V` | `GND` | `GPIO27` |
| J7 | `5V` | `GND` | `GPIO32` |

These are **GPIO control headers** for the onboard relay driver transistors.
Pin 1 provides 5 V rail, Pin 2 is GND, and Pin 3 carries the GPIO signal
to the transistor base.  The actual power relays (K1-K4) are soldered onto
the carrier board; their coil pins connect to the 5 V rail and GND through
the transistor drivers, and their contact pins (COM/NO/NC) switch the mains
loads that are routed to the J9 switched-load terminal block.

### U1 - ESP32 DevKit V1 (2 x 15, 2.54 mm)

The carrier uses the **30-pin DOIT DevKit V1** pinout, antenna at the top and
USB at the bottom.  Fit two 15-way female headers to the carrier and plug the
DevKit in, or solder the DevKit directly with the supplied male headers.

The full pad-to-GPIO map is in [`NETLIST_RevA.md`](NETLIST_RevA.md).  The
important ones:

* `U1.1` = 3V3, `U1.30` = 5V, `U1.2`/`U1.29` = GND.
* `U1.4` = GPIO2, `U1.5` = GPIO4, `U1.8` = GPIO5, `U1.27` = GPIO12.
* `U1.16` = EN.

## Cable cut-outs

Two non-plated holes let the cables pass from the back can to the front of the
board:

| Hole | Local position | Diameter | Can entry |
|---|---:|---:|---|
| Mains | `(99, 43)` | 20 mm | `(34, -8)` |
| Sensor | `(80, 55)` | 12 mm | `(15, -20)` |

They are modelled as `HOLE` shapes in the JSON, so EasyEDA treats them as
board cut-outs and the autorouter keeps copper away.  Do not place vias or
tracks in them.  The 20 mm hole sits in the free area between the HLK, the
relay headers and the C1/D1 pair; the 12 mm hole sits between the relay
headers and the OLED area.

## BOM and CPL

`BOM_RevA.csv` and `CPL_RevA.csv` are generated from the JSON.  The CPL uses
**EasyEDA/PCB coordinates**: X to the right, **Y up**, origin at the
bottom-left of the board.  If your assembler expects Y down (some do), mirror
the Y column: `Y_asm = 70 - Y_cpl`.

The BOM includes the through-hole parts and the accessories that have no
footprint:

* HLK-PM01, fuse, MOV, terminal blocks, headers, LED, resistor, capacitor,
  Schottky diode.
* Two 15-way female headers for the DevKit.
* Four M3 x 8 screws, four 3.5 x 12 screws + nuts, M20 and M12 glands.

The DevKit itself is not in the BOM; it is a pre-made module.

## Assembly notes

1. **Solder the low-profile parts first**: R1, D1, the headers, the terminal
   blocks.
2. **C1 and the HLK last.**  The HLK is 15 mm tall and sits under the OLED;
   check it is fully seated before soldering.
3. **Do not fit the DevKit until the carrier is screwed to the faceplate.**
   The tray and the OLED FPC are easier to handle with the DevKit out.
4. **Insulate the mains joints.**  Use heatshrink on the J8 and F1 wires; the
   terminal blocks do not cover the wire ends.
5. **Check the 5 V rail** before plugging in the DevKit.  With mains applied
   and no load, the HLK output should be 5.0-5.2 V.  If it is not, stop.
6. **Check the isolation slot** is clear of solder balls and copper slivers.

## Mains safety

> **Danger.** This board carries 230 V AC.  It is a prototype, not a certified
> product.  Build it only if you are competent to work with mains.

* Keep the mains area (left of the isolation slot, around J8, F1 and MOV1)
  clear of low-voltage wiring, fingers and the OLED FPC.
* Use a **500 mA slow-blow** fuse for the HLK and a fuse sized for the load.
* Use an RCD-protected supply when testing.
* The HLK-PM01 provides isolation, but the AC side is live whenever the unit
  is connected.  Do not touch it.
* The board has no earth plane or earth terminal.  If your installation
  requires an earth, add a separate earth stud and bond it to the metal
  enclosure; do not rely on the PCB.
* The 5.08 mm terminal blocks provide the mains spacing.  Do not substitute
  smaller-pitch connectors.
* Keep the mains and SELV cables separated inside the can; the 20 mm and 12 mm
  entries are deliberately at opposite ends of the board.
* The four Songle SRD-05VDC-SL-C relays (K1-K4) provide basic insulation
  (1500 VAC coil-to-contact).  PCB creepage between same-relay COM and coil
  pins is exempt from the ≥8 mm requirement because the component is the
  primary insulation barrier.  ≥8 mm creepage is enforced between different
  footprints and between mains and SELV nets from other components.

## Mechanical notes

* The carrier is held by four **M3 x 8** screws into the faceplate standoffs.
  The two left-hand screws also pass through the DevKit tray ears.
* The four **4.5 mm** holes at the patress centres are clearance for the
  faceplate-to-can screws.  They are not load-bearing; the carrier is held by
  the standoffs.
* The DevKit is supported by the printed tray; the tray slots clear the two
  15-way headers.  The module's USB end overhangs the tray, which is why the
  tray has a USB relief.
* The OLED is a bare 26 x 14 mm panel in the faceplate frame.  The carrier's
  J3 header is at the top right, next to the frame's FPC slot.
* The status LED is at local `(66, 44)`, which lines up with the faceplate LED
  hole and the light pipe at enclosure `(1, -9)`.

## Checks

Run the geometry checks after any layout change:

```bash
python3 generate_easyeda.py
python3 check_board.py
python3 export_docs.py
python3 render_preview.py
```

`check_board.py` parses the generated JSON and reports:

* minimum pad-to-pad gap (different nets)
* minimum pad-to-hole and track-to-hole gap
* minimum track-to-pad and track-to-track gap
* minimum mains-to-SELV clearance at pads and tracks
* component body overlaps
* DevKit header rows inside the body outline
* every pad has a net

Current Rev A result: **PASS**.  The tightest numbers are:

* pad-to-pad: 0.34 mm (2.54 mm pitch headers with 2.2 mm pads)
* pad-to-hole: 2.27 mm
* track-to-pad: 0.94 mm
* track-to-hole: 1.90 mm
* track-to-track: 3.58 mm (mains)
* mains pad-to-SELV: 5.73 mm
* mains track-to-SELV: 5.42 mm

The component body outlines in `check_board.py` are duplicated from the
generator on purpose.  If you move a part, update both.

## Known limitations (Rev A)

* The board is **not** a certified mains product.  Have the mains section
  reviewed before connecting it to anything permanent.
* The logic nets are left to the autorouter.  Route them, run DRC, and inspect
  the result; the generated file is a starting point, not a finished board.
* The J8/F1 terminal pads are on a 5.08 mm pitch with 3.0 mm pads.  The
  pad-to-pad gap is about 2.1 mm; the terminal barriers provide the creepage.
  If your safety reviewer requires more, use a terminal with a larger body or
  add routed slots between the pads.
* There is no ground plane.  Add one if you have EMC concerns; the current
  board is a prototype.
* The PZEM and the relay modules are external.  Check they fit the can before
  you commit to the enclosure.
* The 20 mm mains cut-out is close to the C1/D1 group.  Keep the cable
  sleeved and strain-relieved; do not let it rub on the capacitor.

---

## Rev A v2 (2026-11-05) — firmware-verified corrections

All artifacts regenerated and validated by `check_board_v2.py` (all
production-grade checks PASS: mains-SELV pad creepage 8.65 mm, mains-track
to SELV-pad 9.34 mm, no body overlaps, every pad on a net).

Canonical files:

* `generate_easyeda_v2.py`  — corrected board generator (Source of truth)
* `.. /../../src/OledUI.h`  — OLED firmware (GPIO21/22 I2C, 6-line status)
* `check_board_v2.py`       — production-grade geometry checker
* `FirebaseOTA_3x6_RevA_easyeda.json` — EasyEDA Std import (regenerated)
* `BOM_RevA.csv` / `CPL_RevA.csv` / `NETLIST_RevA.md` (regenerated)
* `preview_top.png` (regenerated)

Fixes vs the earlier draft:

1. **OLED I2C stays on GPIO21/22** (v2.1 final decision — the DevKit's
   native I2C position). Two logical light channels (factory *light 1/*light 3)
   are consumed by the display; the firmware marks GPIO21/22 reserved
   (`isReservedGpio()`, per v2.1 update + OLED support added in `src/OledUI.h`)
   so neither controller can drive them as relays.
2. **GPIO12 never broken out** (flash strap, `isReservedGpio()`).
3. **GPIO25/26/27/32 exposed on J1 only** (rows 13/14, 2x14 header):
   the same nets drive the on-board SSRs AND give external relay/SSR
   modules a plug-in point (5V/GND/GPIO groups).
4. **J4-J7 relay-module headers removed**; the 4x SSR row (Crydom
   ODN2225) with R2-R9 driver resistors is on-board. COM pins share
   `AC_N` (J8.3/4); NO pins carry `L1..L4` directly to J9.
5. **K1/K3 and K2/K4 footprint stacking removed** (they shared identical
   coordinates), ghost driver pads deleted, duplicated J9 deleted.
6. **J2 PZEM header moved** away from the KV zone / mains rows.
7. D1+C1 repositioned clear of J9 pads (>= 8 mm rule honoured).
8. Creepage checker (v2) note: pads inside the same SSR channel cluster
   (SSR_Kx + its 1k/2.2k resistors) are exempt from the 8 mm surface rule
   — the 4000 VAC barrier is the SSR's moulding, the industry-standard
   module topology. Everything else keeps the full rule.

Signal nets (GPIO expansion, OLED I2C, PZEM serial, GPIO25-32 -> R2/R4/R6/R8)
are left as EasyEDA ratlines for the autorouter; the net list is complete,
so the connectivity intent is unambiguous.

---

## Rev A v2.1 sync (2026-11-23) — every artifact regenerated together

`generate_easyeda_v2.py` had picked up the 2026-11-07 "Pro edit"
(commit `5a6aed6`) but only *part* of it had ever been regenerated into
the shipped files: the four full exports, the KiCad board, the BOM/CPL
and the preview still carried the pre-edit layout, and the generator's
own output failed `check_board_v2.py`. All artifacts are now regenerated
from the source of truth in one pass, every file agrees on the same
geometry, and `check_board_v2.py` PASSes.

Kept from the Pro edit:

* the three **mount/probe holes** — `(17.8, 11.4)` Ø2.55 mm,
  `(114.3, 15.2)` Ø2.55 mm, `(109.2, 58.4)` Ø3.2 mm;
* the **R1 / LED1 nudge** (+1.7 / +0.8 mm), with the `BODIES` table in
  `check_board_v2.py` updated to match;
* **J1 2x14** and the **SSR_K4 row** change (already in the v2 outputs).

Rejected from the Pro edit — F1 moved east to `(68.55, 16.5)`:

* pad 1 (`AC_L`) landed on top of J8.3 (`AC_N`): a **dead mains short**
  (pad-pad gap −1.24 mm) and a holder body that overlapped J8;
* the rerouted mains copper also dropped the `AC_N` feed to U2.2 and
  left F1.1 with no copper at all.

F1 therefore stays at its verified position `(64.46, 16.0)` with the
original, connectivity-checked mains routing (J8.1 → F1.1 vertical,
J8.2 → F1.2, J8.2 → U2.1, MOV1.2 → J8.3 → U2.2). If you move F1 or any
mains part again, re-run `generate_easyeda_v2.py && check_board_v2.py`
before committing — the two must land together.

The four full exports (`_current` / `_master` / `_v2_1_fixed` /
`_v2_1_plus`) now carry the identical canonical shape list. Their TEXT
glyph paths were carried over from the previous contents (delta-
translated for the moved texts); the only pathless text is the board
title line, which the older exports never contained — EasyEDA rebuilds
it from the string on load. The legacy checkers (`check_board.py`,
`check_board_A.py`, `check_board_SSR.py`) predate the v2 SSR-cluster
creepage rule and fail on `L4 / SSR_K4_CAT` by design; use
`check_board_v2.py`.
---

## Rev B (2026-11-23) — ESP32-WROOM-32E soldered module

`FirebaseOTA_3x6_RevB_wroom.json` is the same 130 x 70 carrier with the
30-pin DevKit replaced by a soldered **ESP32-WROOM-32E** module plus the
support circuit the DevKit used to carry on-board:

* **U1 ESP32-WROOM-32E** — official Espressif land pattern (38 castellated
  pads at 1.27 mm on three sides + centre ground pad, datasheet v2.1 /
  KiCad `RF_Module:ESP32-WROOM-32`); module at the top edge so the PCB
  antenna overhangs the same way the DevKit's did. `check_board_v2.py`
  enforces the keep-out: no copper under the antenna band.
* **U3 AMS1117-3.3** (SOT-223, tab = VOUT) — the 5 V rail now makes
  3.3 V on-board; J1, J3 and U1 all run from `3V3`.
* **EN / reset**: R10 10k pull-up + C2 1 uF delay + SW1 button — the RC
  the Espressif datasheet asks for (R = 10k, C = 1 uF).
* **BOOT**: R11 10k pull-up on GPIO0 + SW2 button.
* **J5 1x6 UART header** — TX/RX/EN/IO0 + 3V3/GND for flashing with any
  USB-UART adapter (hold BOOT, tap RESET to enter the serial loader).
* **C3 / C4 / C5** — LDO input and output 10 uF (AMS1117 stability) plus
  100 nF decoupling at U1.

Nets are unchanged from Rev A (same GPIO map for J1 / J2 / J3 / SSRs) —
only the MCU-side pads moved, so signal copper stays as EasyEDA ratlines
for the autorouter exactly like Rev A, and no mains copper changed
(mains-to-SELV 8.63 mm verified on Rev B as well).

Regenerate and check:

    python3 generate_easyeda_v2.py --revb
    python3 check_board_v2.py FirebaseOTA_3x6_RevB_wroom.json
    python3 export_docs.py FirebaseOTA_3x6_RevB_wroom.json    # BOM/CPL/NETLIST RevB
    python3 render_preview.py FirebaseOTA_3x6_RevB_wroom.json

Artifacts: `FirebaseOTA_3x6_RevB_wroom.json`, `BOM_RevB.csv`,
`CPL_RevB.csv`, `NETLIST_RevB.md`, `preview_top_revb.png`.
Rev A stays the default of every script — plain
`python3 generate_easyeda_v2.py` reproduces `FirebaseOTA_3x6_RevA_easyeda.json`
byte-for-byte.
---

## Signal routing (2026-11-23) — the board ships pre-routed

Importing the board and pressing "auto route" produced23 DRC errors
(Hole to Track / Hole to TH Pad / two unconnected GPIO26 pads) — but
every one of them measured against objects the *autorouter had just
created*. The shipped file itself passes the same rules with a wide
margin: hole-to-track44 mil, hole-to-pad33 mil, hole-to-copper50 mil,
all against the6.9 mil rule.

To make the download DRC-clean out of the box, the signal nets are now
pre-routed:

* **`route_selv.py`** — a deterministic two-layer maze router (A* with
  negotiated-congestion history and rip-up/retry) that routes every
  non-mains multi-pad net with margins satisfying `check_board_v2.py`
  *and* EasyEDA's DRC: >=0.5 mm to foreign pads, >=0.3 mm to foreign
  tracks and vias, >=1.0 mm to holes/board edge, and **>=8 mm to mains
  copper on both layers** — the mains-to-SELV creepage rule the
  autorouter does not know at all. Narrow passages (the single-cell gate
  east of J1's pad column, the gaps in the DevKit's pad wall) are priced
  into the path cost, so through-traffic prefers the wide lanes and only
  the net that lives in a pocket pays for the final approach.
* **`scripts/route_production_pcb.py`** — precomputes the routed
  production document into `flashhub/data/production_pcb_routed.json`
  (routing takes minutes, far too slow per HTTP request; `student.py`
  swaps the routed shape list in for the production kit). The Django
  test `ProductionRoutedPcbTests` fails the moment the board builder
  drifts from that artifact — rerun the script after changing
  `build_production_board`.
* Pipeline: `generate_easyeda_v2.py [--revb]` → `route_selv.py [file]`
  → `check_board_v2.py [file]` → `export_docs.py` / `render_preview.py`
  / `generate_kicad_v2.py`. The KiCad exporter now emits B.Cu segments
  and vias (it used to silently drop bottom-layer copper).
* `check_board_v2.py` validates the router's output too: via copper and
  via drill rules, bottom-layer tracks (track-track is layer-aware —
  top and bottom may cross), and vias join the8 mm mains-SELV checks.

### L1..L4 stay ratlines — route them by hand, never by autorouter

The switched-load nets `L1..L4` (SSR NO → J9) are deliberately **not**
pre-routed: there is no on-board path for them that keeps the required
8 mm from the SSR row's SELV pins — the strip between that row and the
board edge is too narrow — and letting the autorouter do it would pass
its own6.9 mil DRC while running mains copper within a hair of SELV
pads. Route them yourself with the largest gap you can keep (design
target8 mm) or wire them point-to-point.
