Skip to main content

IO expanders

What this example shows​

Control extra GPIO pins through the two IO expanders on the Inkplate 10. The sketch blinks an LED on the external expander (expander2) for 5 seconds, then an LED on the internal expander (expander1) for 5 seconds, and repeats. Both LEDs sit on pin IO_PIN_B7, which the sketch calls P1-7 (GPB7).

Expander pins are numbered GPA0 = 0 to GPA7 = 7 and GPB0 = 8 to GPB7 = 15.

Example code​

The external IO expander pins are all free to use. The internal IO expander is different: do not use GPA0 to GPA7 or GPB0, and use only pins 9 to 15 (P1-1 to P1-7). The example header says that using the restricted pins may permanently damage the display.

You need two LEDs and two 330 Ω resistors. Connect one LED with a 330 Ω resistor to P1-7 (GPB7) on the external expander and the other to P1-7 (GPB7) on the internal expander. In the Arduino IDE, choose the Inkplate 10 board under Tools, Board, Inkplate Boards before you upload.

Select Board
Inkplate10_IO_Expanders.ino
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
#endif

#include "Inkplate.h"

// We are going to use pin P1-7 (GPB7)
// GPA0 = 0 ... GPA7 = 7
// GPB0 = 8 ... GPB7 = 15
#define LED_PIN IO_PIN_B7

Inkplate display(INKPLATE_1BIT);

void setup()
{
display.begin();

// Configure LED pin on both IO expanders
display.expander2.pinMode(LED_PIN, OUTPUT); // IO Expander 2
display.expander1.pinMode(LED_PIN, OUTPUT); // IO Expander 1
}

void loop()
{
// External IO Expander (IO Expander 2)
for (int i = 0; i < 5; i++)
{
display.expander2.digitalWrite(LED_PIN, HIGH);
delay(500);
display.expander2.digitalWrite(LED_PIN, LOW);
delay(500);
}

delay(1000);

// Internal IO Expander (IO Expander 1)
for (int i = 0; i < 5; i++)
{
display.expander1.digitalWrite(LED_PIN, HIGH, IO_INT_ADDR);
delay(500);
display.expander1.digitalWrite(LED_PIN, LOW, IO_INT_ADDR);
delay(500);
}

delay(2000);
}

Trimmed from Inkplate10_IO_Expanders.ino: the file header comment is left out. The code is otherwise unchanged.

Functions used​

Inkplate(uint8_t mode)returns None

Creates the Inkplate object and chooses the display mode. `INKPLATE_1BIT` is black and white and supports partial updates. `INKPLATE_3BIT` is grayscale and only supports full updates.

ReturnsConstructor; no return value.

Parameters

TypeNameDescription
uint8_tmodeDisplay mode: INKPLATE_1BIT (0) or INKPLATE_3BIT (1).
display.begin()returns void

Initializes the library, the peripherals and the frame buffers. Call it once in `setup()`, later calls are ignored.

ReturnsNothing.

display.expander2.pinMode(uint8_t _pin, uint8_t _mode, bool _bypassCheck = false)returns void

Sets the mode of a pin on an IO expander. The sketch calls it on `expander2` (the external expander) and on `expander1` (the internal one) in the same way.

ReturnsNothing.

Parameters

TypeNameDescription
uint8_t_pinExpander pin, for example IO_PIN_B7.
uint8_t_modePin mode: INPUT, OUTPUT or INPUT_PULLUP.
bool_bypassCheckSetting this to true bypasses the library block on pins it reserves for itself. Defaults to false.
display.expander2.digitalWrite(uint8_t _pin, uint8_t _state, bool _bypassCheck = false)returns void

Sets an output pin on an IO expander to `HIGH` or `LOW`. The sketch calls it on `expander2` (the external expander) and on `expander1` (the internal one). For `expander1` it passes `IO_INT_ADDR` as the last argument, and any nonzero value counts as `true`.

ReturnsNothing.

Parameters

TypeNameDescription
uint8_t_pinExpander pin, for example IO_PIN_B7.
uint8_t_stateHIGH or LOW.
bool_bypassCheckSetting this to true bypasses the library block on pins it reserves for itself. Defaults to false.
delay(unsigned long ms)returns void

Arduino function that pauses the sketch.

ReturnsNothing.

Parameters

TypeNameDescription
unsigned longmsTime to wait, in milliseconds.

What to expect​

The LED on the external expander blinks 5 times (half a second on, half a second off), then the LED on the internal expander blinks 5 times. The sketch pauses between the two groups and repeats forever. The sketch does not use Serial.