Arduino: LCD with SPI Expander MCP23S08

I2C costs quite a lot of SRAM and program memory on an Arduino UNO. If you are already using SPI for other devices, you could consider to use a SPI IC as LCD driver.

The MCP23S08 8-Bit I/O Expander with Serial Interface

For a project already using SPI, I wanted to spare some memory and therefore also use SPI for the LCD communication. The MCP23S08 is a SPI version of an I/O Expander and could be used as substitute for the PCF8574. Despite of being a SPI chip, the MCP23S08 has also two address pins. If you tie these pins to ground the address is 0x40. Additionally don't forget to pullup the Reset of the IC - otherwise the communication with the MCP will not be possible.

I keep the pin wiring of the MCP23S08 very close to the PCF8574 and I use the same data pins:

LCD    MCP     UNO
--------------------------
VSS    GND     GND
VDD    Vin      5V
V0     -       -         contrast - connect a potentiometer to GND
RS     P0 RS   -
RW     P1 RW   -
E      P2 EN   -
DB0    -       -
DB1    -       - 
DB2    -       -
DB3    -       -
D4     P4 DB4  -
D5     P5 DB5  -
D6     P6 DB6  -
D7     P7 DB7  -
LEDA   -       -         GND of backlight circuitry controlled by P3 (HIGH signal enables backlight using a simple NPN transistor)
LEDK   5V
-      RES     -         must be pulled up to high
-      A0      -         pull down (GND)
-      A1      -         pull down (GND)
-      CS      D10 SS    (or another free pin)
-      SO      D12 MISO  (currently not used)
-      SI      D11 MOSI
-      SCL     D13 SCL         

If you face the MCP23S08 to the backside of the PCB and leave the contrast potentiometer R2 and the backlight transistor Q1 on the other side, you come up with a very simple PCB:

SPI port expander for LCD

My LCD SPI backback with a fixed contrast resistor mounted to a LCD:

SPI port expander LCD

And by the way: SPI communication is so much faster than I2C that I really wonder, why we have used so much I2C the last years.

The Character Set of the HD44780U A00 ROM

The "Noiasca Liquid Crystal" library does a character mapping from UTF-8 to the existing characters in the Hitachi HD44780U A00 ROM. As example some special characters in the second row of the display:

special characters on LCD

(Degree, Division, middle Point, n with tilde, Pound, Yen, Tilde, Sqareroot, Proportional to, Infinity, Left Arrow, Right Arrow, Backslash)

You can read more about this character mapping in the Introduction and on the LCD Language page. For the beginning you should know that you don't need to enter the octal ROM addresses of the special characters manually and these print can be done by a simple:

lcd.print("°+.n~√∝∞←→\\");

The Hardware Driver for the SPI Expander

The library offers a class for displays connected with an MCP23S08. It uses the 4bit mode only.

The necessary #include and the constructor are:

#include <NoiascaLiquidCrystal.h>
#include <NoiascaHW/lcd_MCP23S08.h>
LiquidCrystal_MCP23S08 lcd(addr, csPin, cols, rows);  

as mentioned earlier: the MCP23S08 also needs the information of the address pins and like you are used from other SPI devices, a dedicated chip select pin (csPin).

Remember to add a SPI.begin() to your setup() like in the examples, as this will not be done in the library.

Your own Character Converter

If you need a different converter for the characters you can hand over a callback to your own function as optional last parameter.

Obviously - you also have to implement the callback function to do all the magic.

See the general example how to write your own character converter.

German Umlauts and Other Languages

Please read the dedicated page for LCD Language Letters how your language specific letters with diacritics are supported in this Arduino library.

Summary

If you need an easy support of the given character set of a HD44870 display, want to spare SRAM and flash memory - switch over to SPI and take the "Noiasca Liquid Crystal" library in consideration.

Links

(*) Disclosure: Some of the links above are affiliate links, meaning, at no additional cost to you I will earn a (little) comission if you click through and make a purchase. I only recommend products I own myself and I'm convinced they are useful for other makers.

 

Protokoll

First upload: 2020-09-02 | Version: 2024-03-22