Update to Raspberry Pi Components

This morning I uploaded a new version of my Raspberry Pi components for use with Windows 10 IoT on Raspberry Pi 2.

What’s new:

  • New class that controls an HD4478OU Dot Matrix Liquid Crystal Display Controller/Driver attached to a MCP23017 I/O expander.
  • Updates to the MCP23017 class to support multiple chips chained together.

A large chunk of the code for the HD44780U class came from an existing Hackster.IO project for an interactive LED game called SmartFaire. I made modifications to work with my existing MCP23017 class and added a method that outputs wiring information for connecting an LCD panel to the MCP23017.

Using multiple MCP23017 chips

The MCP23017 class constructor has been updated to allow an index value to be passed in that indicates which MCP23017 that the class will control. If your MCP23017 is the only one connected then you would wire it to have a hardware address of 0x20 which is considered index 0 in the MCP23017 class. A hardware address of 0x21 would be index 1, and so forth. This enables you to chain up to 8 MCP23017 chips together.

Printing to the LCD

Wiring the LCD to a MCP23017 chip is pretty straight forward. 4 data lines and 3 control lines are connected. The LCD is also attached to power and ground for both driving the HD44780U and the backlight. See the SmartFaire project for an example on how to wire up the LCD. The HD44780U class has a GetWiringInfo() method you can call which will print out the pins for a LMB162ABC 2 line LCD display with HD44780U driver. Other LCD displays that utilize the HD44780U driver should also work. If you use a different display, ensure you follow the LCD displays wiring diagram instead of the information from the GetWiringInfo() method.

Printing to the LCD with the HD44780U and MCP23017 classes is very simple. First I create a new instance of the MCP23017 class for the I/O expander I am using with the LCD.

//Configure the second I/O port expander (location 1)

private MCP23017 i2cLCD = new MCP23017(1);

Next I create a variable to hold an instance of my HD44780U object.

//Create a variable to hold our LCD object

private HD44780U lcdScreen;

Once the MCP23017 has been initialized, I create a new HD44780U object and assign it to my lcdScreen variable. I pass in the MCP23017 object along with a value indicating which series of pins on the I/O expander the LCD is connect to. In this case I have wired the LCD to the “B” ports on the I/O expander.

await i2cLCD.Init();

lcdScreen = new HD44780U(i2cLCD, MCP23017.Register.GPIOB);

Now that I have an lcdScreen object, I can start to interact with it. I recommend first calling the LcdReset() method to ensure that the LCD screen is properly initialized and ready to go.


The LCD panel I am using has only 2 display lines. Currently my HD44780U class is configured to only work with up to 2 display lines. If your LCD has more lines you will need to modify the class to support the additional lines. To select which line I want to print to, I use the MoveToLine() method, passing in a 0 based index of the line.


Now that I have selected a position for my text, I can print to the LCD using the PrintLine command.

lcdScreen.PrintLine(“Hello World!”);

If I wish to clear the LCD screen I can use the LcdClear() method.


One last thing… remember to properly dispose of the MCP23017 object when you are done using it.


Grab the code and give it a try yourself!

Download the latest code

Leave a Reply