> For the complete documentation index, see [llms.txt](https://makermoekoe.gitbook.io/picoclick-c3/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://makermoekoe.gitbook.io/picoclick-c3/extension-boards/gpio-expander.md).

# GPIO expander

The GPIO expander extension board is based on the **MCP23008** by Microchip. The expander uses I2C to communicate with the Picoclick (SDA = GPIO2, SCL = GPIO8). It can be used with the on board ultra low power voltage regulator or with the 3.3V output of the Picoclick, which is only present when the Picoclick is activated. By using the 3.3V output the soldering jumper J1 has to be closed and the voltage regulator has to be removed.

Soldering jumper J2 connects the interrupt signal of the MCP23008 to the extension connector in order to let the expander activate the Picoclick by firing an interrupt.

The pinout of the pinheaders is labeled on the bottom of the PCB.

## Hardware

### Overview

<figure><img src="/files/wwnkc9m7f2zNxRzRLkDt" alt=""><figcaption></figcaption></figure>

### Technical drawing

<figure><img src="/files/LI1A934ZlLo4JA7g9n4o" alt=""><figcaption><p>Measurements in mm, grid is 0.5mm</p></figcaption></figure>

* PCB: 18mm x 18mm
* Thickness: 1mm
* Mounting holes: 3.2mm
* Corner radius: 2mm
* The pinheaders are breadboard compatible (12.7mm distance between the rows)

### Schematics

<figure><img src="/files/Ju5z17BlfHnUYGTkilyS" alt=""><figcaption></figcaption></figure>

## Software

Hardwaretest can be found on [Github](https://github.com/makermoekoe/Picoclick-C3/tree/main/code/Picoclick_C3/PC3_Hardwaretest_Expander).

```
#include <Arduino.h>
#include <WiFi.h>
#include <FastLED.h>
#include <Wire.h>
#include <Adafruit_MCP23X08.h>
#include "config.h"

Adafruit_MCP23X08 mcp;

void setup(){
  pinMode(BUTTON_PIN, INPUT);
  pinMode(ADC_ENABLE_PIN, OUTPUT);
  pinMode(ADC_PIN, INPUT);
  analogReadResolution(12);
  digitalWrite(ADC_ENABLE_PIN, HIGH);

  btStop();
  WiFi.mode(WIFI_OFF);

  FastLED.addLeds<APA102, APA102_SDI_PIN, APA102_CLK_PIN, BGR>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(160);
  delay(50);

  set_fastled(CRGB::Blue);

  Wire.begin(SDA_PIN, SCL_PIN);
  delay(100);

  if(!mcp.begin_I2C()){
    printf("Error.\r\n");
    set_fastled(CRGB::Red);
    delay(3000);
    esp_deep_sleep_start();
  }

  for(int i=0; i<8; i++) mcp.pinMode(i, OUTPUT);
}

unsigned long t_expander = millis() + 300;

int counter = 0;
bool dir = true;

void loop() {
  if(digitalRead(BUTTON_PIN) == 1){
    set_fastled(CRGB::Red);
    delay(500);
    esp_deep_sleep_start();
  }

  if(millis() >= t_expander + 1000){
    t_expander = millis();
    if(dir) mcp.digitalWrite(counter, 1);
    else mcp.digitalWrite(counter, 0);

    counter++;
    if(counter == 8){
      counter = 0;
      dir = !dir;
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://makermoekoe.gitbook.io/picoclick-c3/extension-boards/gpio-expander.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
