# 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="https://3814073947-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8e8Y0oYz6ujS2c1GD1Qy%2Fuploads%2FJvbVN8vLkyL9jd5CAIMN%2Fpc3_ext_expander.png?alt=media&#x26;token=9cc83953-a24c-4c33-b3a2-02bfcd05b24b" alt=""><figcaption></figcaption></figure>

### Technical drawing

<figure><img src="https://3814073947-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8e8Y0oYz6ujS2c1GD1Qy%2Fuploads%2FkaiL1NIE9PU8cEi4k96I%2Fpc3_ext_expander_techdraw.png?alt=media&#x26;token=a7f676b3-01d5-45ca-9d5b-8d3b6972d953" 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="https://3814073947-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8e8Y0oYz6ujS2c1GD1Qy%2Fuploads%2FbN9C1IYKUSZMR8duxvp8%2Fpc3_ext_mcp_gpio_extender_schematics.png?alt=media&#x26;token=db8603db-d578-476d-b671-dd945fda6a47" 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
