> ## Documentation Index
> Fetch the complete documentation index at: https://docs.glifo.cat/llms.txt
> Use this file to discover all available pages before exploring further.

# GPIO pinout

> GPIO assignments, bus configurations, and connector pinouts for the ED1 board.

Quick reference for GPIO assignments on the ED1 Citilab Board.

## GPIO assignment table

| GPIO  | Function     | ID                   | Dir | Notes                          |
| ----- | ------------ | -------------------- | --- | ------------------------------ |
| 0     | Boot/Flash   | -                    | I   | Boot mode select               |
| 2     | Touch Left   | `btn_left`           | I   | Capacitive touch               |
| 4     | Touch Up     | `btn_up`             | I   | Capacitive touch               |
| 5     | TFT CS       | `internal_display`   | O   | SPI chip select                |
| 9     | TFT DC       | `internal_display`   | O   | Data/Command                   |
| 10    | TFT Reset    | `internal_display`   | O   | Display reset                  |
| 12    | LED Matrix   | `led_matrix_light`   | O   | WS2812 data                    |
| 13    | Touch Down   | `btn_down`           | I   | Capacitive touch               |
| 14    | Touch X      | `btn_x`              | I   | Capacitive touch               |
| 15    | Touch OK     | `btn_ok`             | I   | Capacitive touch               |
| 18    | SPI CLK      | `spi`                | O   | SPI clock                      |
| 19    | SPI MISO     | `spi`                | I   | SPI data in                    |
| 21    | I2C SDA      | `bus_i2c`            | I/O | I2C data                       |
| 22    | I2C SCL      | `bus_i2c`            | O   | I2C clock                      |
| 23    | SPI MOSI     | `spi`                | O   | SPI data out                   |
| 26    | Buzzer       | `buzzer_output`      | O   | PAM8301 amp                    |
| 27    | Touch Right  | `btn_right`          | I   | Capacitive touch               |
| 34    | Light Sensor | `light_sensor`       | I   | ADC input                      |
| 32    | IR TX        | `remote_transmitter` | O   | Rev 1.0 only                   |
| 33/35 | IR RX        | `remote_receiver`    | I   | GPIO33 Rev 1.0, GPIO35 Rev 2.3 |

**ID** = ESPHome component ID. **Dir** = I (input), O (output), I/O (bidirectional).

## Bus assignments

### SPI bus

GPIO18 (CLK), GPIO23 (MOSI), GPIO19 (MISO). Used by TFT Display (ST7735).

### I2C bus

GPIO21 (SDA), GPIO22 (SCL).

**Rev 2.3:**

| Device    | Address | Function                      |
| --------- | ------- | ----------------------------- |
| MXC6655XA | 0x15    | Accelerometer                 |
| MCP23009  | 0x20    | I/O Expander (stepper motors) |

**Rev 1.0:**

| Device   | Address | Function                    |
| -------- | ------- | --------------------------- |
| LIS3DH   | 0x19    | Accelerometer               |
| MCP23017 | 0x20    | I/O Expander (16 GPIO pins) |

### MCP23009 GPIO mapping (stepper motors)

| GPIO | Coil | Driver      | Motor |
| ---- | ---- | ----------- | ----- |
| GP0  | D    | ULN2004A U8 | M2    |
| GP1  | C    | ULN2004A U8 | M2    |
| GP2  | B    | ULN2004A U8 | M2    |
| GP3  | A    | ULN2004A U8 | M2    |
| GP4  | D    | ULN2004A U7 | M1    |
| GP5  | C    | ULN2004A U7 | M1    |
| GP6  | B    | ULN2004A U7 | M1    |
| GP7  | A    | ULN2004A U7 | M1    |

## Touch button mapping

<div
  style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
gridTemplateRows: 'auto auto auto auto',
gap: '8px',
maxWidth: '360px',
margin: '1.5rem auto',
textAlign: 'center',
fontSize: '0.85rem'
}}
>
  <div />

  <div style={{
    padding: '10px',
    borderRadius: '8px',
    backgroundColor: 'var(--tw-prose-pre-bg, #1e1e2e)',
    border: '1px solid #444',
    fontWeight: 600
  }}>UP<br /><span style={{ opacity: 0.6, fontSize: '0.75rem' }}>GPIO4</span></div>

  <div />

  <div style={{
    padding: '10px',
    borderRadius: '8px',
    backgroundColor: 'var(--tw-prose-pre-bg, #1e1e2e)',
    border: '1px solid #444',
    fontWeight: 600,
    display: 'flex',
    flexDirection: 'column',
    justifyContent: 'center'
  }}>LEFT<br /><span style={{ opacity: 0.6, fontSize: '0.75rem' }}>GPIO2</span></div>
  <div style={{
    gridRow: 'span 2',
    padding: '16px 10px',
    borderRadius: '8px',
    backgroundColor: '#7aa2f7',
    color: '#1a1b26',
    fontWeight: 700,
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    fontSize: '0.9rem'
  }}>TFT Display</div>
  <div style={{
    padding: '10px',
    borderRadius: '8px',
    backgroundColor: 'var(--tw-prose-pre-bg, #1e1e2e)',
    border: '1px solid #444',
    fontWeight: 600,
    display: 'flex',
    flexDirection: 'column',
    justifyContent: 'center'
  }}>RIGHT<br /><span style={{ opacity: 0.6, fontSize: '0.75rem' }}>GPIO27</span></div>

  <div style={{
    padding: '10px',
    borderRadius: '8px',
    backgroundColor: 'var(--tw-prose-pre-bg, #1e1e2e)',
    border: '1px solid #444',
    fontWeight: 600
  }}>OK<br /><span style={{ opacity: 0.6, fontSize: '0.75rem' }}>GPIO15</span></div>
  <div style={{
    padding: '10px',
    borderRadius: '8px',
    backgroundColor: 'var(--tw-prose-pre-bg, #1e1e2e)',
    border: '1px solid #444',
    fontWeight: 600
  }}>X<br /><span style={{ opacity: 0.6, fontSize: '0.75rem' }}>GPIO14</span></div>

  <div />

  <div style={{
    padding: '10px',
    borderRadius: '8px',
    backgroundColor: 'var(--tw-prose-pre-bg, #1e1e2e)',
    border: '1px solid #444',
    fontWeight: 600
  }}>DOWN<br /><span style={{ opacity: 0.6, fontSize: '0.75rem' }}>GPIO13</span></div>

  <div />
</div>

## Analog inputs

| GPIO | Function     | ADC       | Attenuation   |
| ---- | ------------ | --------- | ------------- |
| 34   | Light Sensor | ADC1\_CH6 | 12dB (0–3.3V) |

## LED matrix

* **Data Pin**: GPIO12
* **Type**: WS2812X (GRB color order)
* **Count**: 256 LEDs (32 columns x 8 rows)
* **Layout**: Serpentine (zigzag) pattern

### Pixel mapping

```text theme={null}
Column:  0   1   2   3  ...
Row 0:   0   15  16  31 ...
Row 1:   1   14  17  30 ...
Row 2:   2   13  18  29 ...
...
Row 7:   7   8   23  24 ...
```

Formula:

```cpp theme={null}
if (x % 2 == 0)
    pixel = (x * 8) + y;
else
    pixel = (x * 8) + (7 - y);
```

## Expansion connectors

### Analog ports - J5 (left side)

Input-only ADC pins, directly connected to ESP32. Active-low.

| Port | GPIO   | ADC       | Notes |
| ---- | ------ | --------- | ----- |
| A1   | GPIO36 | ADC1\_CH0 | SVP   |
| A2   | GPIO37 | ADC1\_CH1 | -     |
| A3   | GPIO38 | ADC1\_CH2 | -     |
| A4   | GPIO39 | ADC1\_CH3 | SVN   |

All analog ports share a 3-pin connector: **S** (signal), **+** (3.3V), **-** (GND).

### Digital ports - J2 (right side)

| Port | GPIO   | ADC       | Notes           |
| ---- | ------ | --------- | --------------- |
| D1   | GPIO12 | ADC2\_CH5 | LED matrix data |
| D2   | GPIO25 | ADC2\_CH8 | DAC1            |
| D3   | GPIO32 | ADC1\_CH4 | -               |
| D4   | GPIO26 | ADC2\_CH9 | Buzzer output   |

All digital ports share a 3-pin connector: **S** (signal), **+** (5V), **-** (GND).

**Note:** D1 (GPIO12) and D4 (GPIO26) are used internally. D2 (GPIO25) and D3 (GPIO32) are available for external use.

### I2C/serial - J6 (bottom left)

| Pin | Label | GPIO   | Function |
| --- | ----- | ------ | -------- |
| 1   | DA    | GPIO21 | I2C SDA  |
| 2   | CL    | GPIO22 | I2C SCL  |
| 3   | TX    | GPIO1  | UART TX  |
| 4   | RX    | GPIO3  | UART RX  |

### Grove connector (J11)

| Pin | Signal | Connection |
| --- | ------ | ---------- |
| 1   | VDD33  | 3.3V       |
| 2   | GND    | Ground     |
| 3   | SDA    | GPIO21     |
| 4   | SCL    | GPIO22     |

## Stepper motor connectors

### M1 & M2 (28BYJ-48)

| Pin | Signal        |
| --- | ------------- |
| 1   | Coil A        |
| 2   | Coil B        |
| 3   | Coil C        |
| 4   | Coil D        |
| 5   | VDD5 (common) |

Controlled via MCP23009 I/O expander and ULN2004A drivers.

## Reserved/internal GPIOs

These GPIOs are used internally by the ESP32 or board hardware:

| GPIO   | Internal Use       |
| ------ | ------------------ |
| 6-11   | Flash (do not use) |
| 16, 17 | Flash CS/SDO       |
| 36, 39 | Sensor VP/VN       |
