Rothschopf Werner

rowex ganz privat

Angebote

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 an 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 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
-      SI      D11 MOSI
-      SCL     D13 SCL         

If you face the MCP23S08 to the backside of the LCD and leave the contrast potentiometer R2 and the backlight transistor Q1 on the other side, you come up with a very simple PCB and you still can adjust the contrast when the backpack was soldered to the LCD:

 

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:

Sonderzeichen am LCD fr Arduino

(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 or in the German section of this site. 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("~√∝∞←→\\");

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_spi.h>     
LiquidCrystal_SPI lcd(addr, cols, rows, csPin);  

as mentioned earlier: the MCP23S08 also needs the information of the address pins and like you are used to 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 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

For my German readers: the default constructor enables the support for the small letters and . The large German umlauts will be converted to their counterpart A O U. If you want to try other variants, you can use following constructors:

LiquidCrystal_I2C lcd(lcdAddr, cols, rows);                            // use the standard converter ( gets A)
//LiquidCrystal_I2C_Ae lcd(lcdAddr, cols, rows, convert_ae);           // an Umlauts like  becomes Ae
//LiquidCrystal_I2C_small lcd(lcdAddr, cols, rows, convert_small);     // an Umlauts like  becomes 
//LiquidCrystal_I2C_special lcd(lcdAddr, cols, rows, convert_special); // an Umlauts like  becomes  using custom character 

Summary

If you need an easy support of the given character set of a HD44870 display, take the "Noiasca Liquid Crystal" library in consideration.


Links


Protokoll

First upload: 2020-09-02 | Version: 2020-09-07