RSS

Getting Data Out – 16 x 2 LCD

This week I decided to move my attention to displaying data from the Netduino. Whilst you can use Debug.Print statements to display data on the PC it defeats the object o0f having a micro controller if you have to have it hooked up to a PC in order to see what it is doing. So I decided to purchase a 16 character by 2 line LCD display like the one found here– in fact this is the one I purchased.

Objective

Hook up theNetduinoto the LCD display and show a message to the user.

Hardware

The interface on the display uses 16 pins although it is not necessary to use all of them. The LCD is being driven by a HD44780 (or equivalent) chip and so there is plenty of examples of wiring/code to control this device. The pin usage is as follows:

LCD PinDescription
1Ground
2+5V
3Operating voltage for LCD (the contrast)
4RS (High for data, Low for instructions)
5R/W (High for read, Low for write)
6Chip enable
7DB0 – Data Bus line 0
8DB1 – Data Bus line 1
9DB2 – Data Bus line 2
10DB3 – Data Bus line 3
11DB4 – Data Bus line 4
12DB5 – Data Bus line 5
13DB6 – Data Bus line 6
14DB7 – Data Bus line 7
15Back light +ve
16Back light ground

A little bit of internet searching and I found a site discussing connecting this device to the Arduino to this type of device along with some code. After a little more searching I found this blog by Szymon Kobalczyk discussing interfacing these types of devices to the Netduino using shift registers. Interestingly, he has published a library on Codeplex (Micro Crystal Library) which allows the control of these devices by the Netduino. Sounded perfect.

Szymon’s blog post discusses the use of shift registers to control the LCD display. This makes it possible to reduce the number of outputs required in order to control the display. At the moment I am just concerned with displaying data. Optimisation of the number and type of ports will come later.

The following Fritzing diagram shows how the Netduino and the LCD are wired up:

The 10K potentiometer is used to control the contrast on the display. The wiring is as follows:

LCD PinDescriptionConnection
1GroundGround (taken from Netduino)
2+5V+5V (taken from Netduino)
3Operating voltage for LCDCentre pin of the 10K potentiometer
4RS (High for data, Low for instructions)Netduino digial pin 12
5R/W (High for read, Low for write)Ground
6Chip enableNetduino digital pin 11
7DB0 – Data Bus line 0
8DB1 – Data Bus line 1
9DB2 – Data Bus line 2
10DB3 – Data Bus line 3
11DB4 – Data Bus line 4Netduino digital pin 2
12DB5 – Data Bus line 5Netduino digital pin 3
13DB6 – Data Bus line 6Netduino digital pin 4
14DB7 – Data Bus line 7Netduino digital pin 5
15Back light +ve+5V
16Back light groundGround

Software

As previously mentioned, the main library for controlling this device can be found on Codplex. A little digging around in the examples gave me the code I needed to control the LCD. So leaving the examples behind I compiled the library into a DLL. Next step was to create a new project and add a reference to the DLL. I added the following code to the new project:

GpioLcdTransferProvider lcdProvider;
Lcd lcd;

lcdProvider = new GpioLcdTransferProvider(rs: Pins.GPIO_PIN_D12, enable: Pins.GPIO_PIN_D11, d4: Pins.GPIO_PIN_D2, d5: Pins.GPIO_PIN_D3, d6: Pins.GPIO_PIN_D4, d7: Pins.GPIO_PIN_D5);
lcd = new Lcd(lcdProvider);
lcd.Begin(columns: 16, lines: 2);
lcd.Write("Hello, world!");
while (true)
{
    lcd.SetCursorPosition(column: 0, row: 1);
    lcd.Write(Utility.GetMachineTime().ToString());
    Thread.Sleep(100);
}

Observations

For some reason, the initial run of the project did not function as expected. For a while I was sitting there looking at a blank display. Playing around with the potentiometer did not correct the problem. At some point I disconnected the backlight and again tried to change the contrast and a few dim letters appeared. A little more playing and I soon had a working display with the backlight working.

The image above shows the application running without the backlight connected. One further enhancement would be to use the transistor as a switch idea to allow the back light to be controlled from the software.

And the next step is to follow Szymon’s blog to reduce the number of pins required. But first a trip to Farnell’sweb site for some parts.

Tags: ,

Saturday, January 15th, 2011 at 6:24 pm • Electronics, NetduinoRSS 2.0 feed Both comments and pings are currently closed.

Comments are closed.