Arduino: a code library for MCP23S17 LCD


Arduino library for MCP23S17 LCD

The code library can be downloaded from

The goal of this library is to provide a set of high-level functions that mimic the existing Arduino LCD library:

The LCD object is initialized as follows:

MCP23S17_LCD object_name(uint8_t rst, uint8_t cs, uint8_t PORT);

  • object_name is any arbitrary name given to create the object (typically lcd)
  • parameters:
    • rst – RST pin for MCP23S17
    • cs – CS pin for MCP23S17
    • PORT – GPIO port of MCP23S17, where the LCD is connected
      • PORT can be either PORT A or PORTB

Then, all the high-level functions described at will work with the new LCd object, just like in the original LCd library.

Below is just a short example that writes “Hello world” on the LCD:

Deep inside the library

You might wonder what are the changes needed to make the LCD work with the MCP23S17. Below there are some of the major changes:

In MCP23S17.h, besides updating some function naming and parameters, you will find some #defines related to MCP23S17. Most registers names and values are explained in the datasheet.

In MCP23S17.c we have a new set of low-level functions for MCP23S17 and for communications with the LCD:

The expander_setup function configures the MCP23S17 according to the parameters indicated at LCD object creation. The following initializations are made:

  • the reset line is briefly flased, then kept at logical “1”
  • hardware addressing is enabled
  • the LCD port is configured as output and set at 0x00

Two new functions,  expander_sendByte and expander_SetOutput, are used to update the pins of the LCD port.

The write4bits and write8bits functions have been modified to call the expander_setOutput function.

Also, the begin function becomes:

One might observe that from the original code I have kept only the initialization in 4-bit mode. A call to expander_setup() was added.

That’s all, folks.

1 2

Leave A Reply