# 2x4 Programming Header Pinout

## Header J2 - 2x4 Programming Header (8 Pins Total)

This is a standard 2-row, 4-column header (2.54mm pitch) commonly used for programming headers.

### Physical Layout

```
Top View:
┌─────────────┐
│ 1  2  3  4  │  ← Top row
│ 5  6  7  8  │  ← Bottom row
└─────────────┘
```

**Pin Numbering:**
- Top row (left to right): Pins 1, 2, 3, 4
- Bottom row (left to right): Pins 5, 6, 7, 8

### Pin Assignment

| Pin | Signal | ESP32 Connection | Description |
|-----|--------|------------------|-------------|
| **1** | **+3V3** | +3V3 Power Rail | Optional - Power ESP32 from programmer |
| **2** | **GND** | GND | Ground reference (required) |
| **3** | **UART_TX** | GPIO1 (UART0 TX) | ESP32 transmits to programmer |
| **4** | **UART_RX** | GPIO3 (UART0 RX) | ESP32 receives from programmer |
| **5** | **DTR** | GPIO0 | Data Terminal Ready (auto-reset) |
| **6** | **RTS** | EN | Request To Send (auto-reset) |
| **7** | **NC** | - | Not connected (spare) |
| **8** | **NC** | - | Not connected (spare) |

### Connection to USB-to-Serial Adapter

| USB-to-Serial Pin | J2 Pin | Signal | Notes |
|-------------------|--------|--------|-------|
| VCC (3.3V) | Pin 1 | +3V3 | Optional - only if powering ESP32 from adapter |
| GND | Pin 2 | GND | **Required** - always connect |
| RX | Pin 3 | UART_TX | Adapter RX receives from ESP32 TX |
| TX | Pin 4 | UART_RX | Adapter TX sends to ESP32 RX |
| DTR | Pin 5 | DTR | Auto-reset control |
| RTS | Pin 6 | RTS | Auto-reset control |
| - | Pin 7 | NC | Spare (not used) |
| - | Pin 8 | NC | Spare (not used) |

**Important Notes:**
- **RX/TX are swapped** - Adapter RX connects to ESP32 TX (Pin 3), and vice versa
- **Do NOT connect VCC** if ESP32 is already powered from J1 (JST connector)
- **Always connect GND** - critical for proper operation
- **DTR and RTS** enable automatic reset (no button pressing needed)

### Advantages of 2x4 Header

1. **Standard layout** - Common 2.54mm pitch header format
2. **More stable** - 2-row design is more mechanically stable
3. **Spare pins** - Pins 7 and 8 available for future expansion
4. **Easy to connect** - Standard programming cable format
5. **Prevents wrong orientation** - 2-row design makes it harder to connect backwards

### KiCad Symbol

**Library:** `Connector_PinHeader_2.54mm`  
**Symbol:** `PinHeader_2x04_P2.54mm_Vertical`

### Optional Pull-up Resistors

For maximum reliability, add pull-up resistors:
- **R5**: 10kΩ between J2 Pin 5 (DTR) and +3V3
- **R6**: 10kΩ between J2 Pin 6 (RTS) and +3V3

Most USB-to-Serial adapters have built-in pull-ups, but adding them on the board ensures reliable operation.

### Flashing Process

1. Connect USB-to-Serial adapter to J2 header (pins 1-6)
2. Power the board (via J1 JST connector or J2 Pin 1)
3. Use `esptool` or ESPHome to flash:
   ```bash
   esptool.py --port /dev/ttyUSB0 write_flash 0x0 firmware.bin
   ```
4. DTR/RTS signals automatically put ESP32 into boot mode
5. No button pressing required!

### Future Expansion

Pins 7 and 8 are spare and can be used for:
- Additional UART (if needed)
- I2C (SDA/SCL) for debugging
- SPI (MISO/MOSI) for additional peripherals
- GPIO monitoring
- Or leave as NC (Not Connected)

---

## Summary

**2x4 Header Layout:**
```
Top Row:    VCC  GND  TX   RX
Bottom Row: DTR  RTS  NC   NC
```

**6 pins used** (1-6) for programming  
**2 pins spare** (7-8) for future use

This is a standard, stable, and convenient programming header configuration!


