An LCD or what Santa brought for Christmas

Today is all about a bright little 20 x 4 lcd screen that appeared under our tree. Since my sons are just getting started my youngest jumped head first into Scratch and my oldest is running through the Python samples in Simon Monk’s book. I thought I would help them venture into a tutorial in C and how they can use some sample code and make their own custom messages on the screen.

Just to get some perspective on the size of this board it’s the same size as our Adafruit PiBow case.

To get started there is an example on My Pi Shop that shows Gordon’s wiringPi LCD library it starts with updating Linux and installing wiringPi.

sudo apt-get update
Install Gordons wiringPi
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
then wait wait and wait for it to finish.
now
sudo apt-get install git-core
To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi

Shut down your system and install LCD.

cd wiringPi

./build

Don’t forget to adjust the trim pot (lots of turns)

cd examples

Now were can delve int the lcd.c program. The example code allows for both a 16 x 2 and a 20 x 4 lcd the lines that absolutely need changing looks like the following:

fd1 = lcdInit (4, 20, 4, 8,  9, 4,5,6,7,0,0,0,0) ;

fd2= lcdInit (2, 16, 4, 8, 10, 4, 5, 6, 7, 0,0,0,0);

Since fd1 already defines a 4 x 20 screen we will start by making this line compatible with our new gift.

fd1 = lcdInit determines a lot about your screen the first 2 segments define your screens size since we have a 20 x 4 we will change this to

fd1 = lcdinit (4, 20,

The next segment is the bits the screen can produce this is a 4 bit board so we have

fd1 = lcdInit (4, 20, 4,

The next 2 segments are the pins used on the lcd itself since this is a different board than what Gordon has provided in his example these pins are will need to be changed to 11, 10 so now we have

fd1 = lcdInit (4, 20, 4, 11, 10,

The last segment are the pins used on the GPIO of the Pi expressed in wiringPi or GPIO depending on which library is used. wiringPiSetup() or wiringPiSetupGPIO(). Since we are using pins defined in wiringPi 0, 1, 2, 3 (remember this is a 4 bit board so only 4 pins are used) and now we have the final code to define our screen.

fd1 = lcdInit (4, 20, 4, 11, 10, 0,1,2,3,0,0,0,0)

We now can interface with the board from My Pi Shop.

A lot of the examples found in led.c are for the 20 x 4 display below is how to work with the larger display.

The file has links to many standard libraries. The includes are stdio.h which is for Input and Output functions, stdlib.h which handles memory functions, conversions, and process control. stdint.h handles integers, unistd.h deals in system calls, string.h, time.h, wiringPi.h and lcd.h are fairly self explanatory.

The next section of code does some checks to make sure the wiringPi library is installed with either wiringPiSetup() or wirkingPiSetupGPIO() functions and that a screen is connected. This is done in the lcdinit() function and uses either the  GPIO pin numbers or the wiringPi pin layout.

The rest of the file defines variables used to hold the messages and loops to scroll the message across the screen by moving from the first character in the message and adding the next character to position 0 on the perspective lines. My kids nodded their heads at this point I guess it will be a while before I know they really get how this works.

The last part is very easy to catch on find the lines defined by buf1, lcdPosition (fd1, x, y), and lcdPuts(fd1)

We can add lcdHome(fd1) ; and lcdClear(fd1) ; as desired into the file to place the cursor at the top left of line 1 (Home) or clear the screen.

This post so far has mostly been a rewording of Gordon’s page while going over it with a 12 an 14 year old with no background in coding I saw their eyes blank out and needed to introduce it to them a little differently. I am having issues with poor camera’s and am trying to work on a video of what we have going on. The effect was something like this:
 
Big Brother 20 x 4 LCD
My Pi Shop & wiringPi
Thank you John and Gordon with your help we have managed to work on programming in C and are having a lot of fun. :) Hopefully we can get the buttons working soon.

This entry was posted in Blog. Bookmark the permalink.

Leave a Reply