IAN LANG ELECTRONICS

Although in the last piece we controlled the output of the LCD display we did not do much more than clear the screen and write some text and numbers to it. In this piece we're going to delve a little more deeply into what your LCD display can do and hopefully you should come out of it armed with some very impressive tools. Wire your display screen up according to how we did it in the last piece, and if you can't remember here's how:

 

 

 

 

 

The first question that is going to spring to

mind after that title is "what in the name of

God is a glyph????"

 

The dictionary defines it thus:

 

 

glyph [glif]

(plural glyphs)

n

1.  architecture carved groove in ancient Greek

architecture: an ornamental carved channel or groove

, especially a vertical one like those on a Doric frieze  

2.  ancient hist carved symbol or character: a symbol

 or character, especially one that has been incised or

carved out in a stone surface like the characters of the

 ancient Maya writing system  

3.  modern symbolic character: a nonverbal symbol,

e.g. one used on a road sign  

4.  comput character in font: the symbol or symbols that form a single character in a font  

 

 

[Late 18th century. Via French glyphe < Greek gluphē "carving" < gluphein "carve"]

Encarta ® World English Dictionary © & (P) 1998-2005 Microsoft Corporation. All rights reserved.

 

Well, we aren't be going to be making grooves in any ancient Greek architecture, at the time of writing the Greeks are busy rioting round it and probably doing it all by themselves. (The Euro- what a grand idea.)

Nor are we studying ancient Mayan texts or making road signs, so I'm going for definition number four.

In fact we can create and store up to eight non-standard characters that can be displayed on the LCD.  This is going to be most useful shortly. Here's some code to make five of them.

 

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte smile[8] = {B00000,B10001,B00000,B00000,B10001,B01110,B00000,};

byte stick[8] = {B00000,B10001,B00000,B11111,B01010,B01010,B00100,};

byte frown[8] = {B00000,B10001,B00000,B00000,B01110,B10001,B00000,};

byte bell[8] =  {B00100,B01010,B01010,B01010,B10001,B11111,B00100,};

byte ball [8] =  {B00000,B01110,B11111,B11111,B11111,B01110,B00000,};

void setup() {

 

  lcd.begin(16, 2);

  lcd.clear();

  lcd.createChar(0, smile);

  lcd.createChar(1, stick);

  lcd.createChar(2, frown);

  lcd.createChar(3, bell);

  lcd.createChar(4, ball);  

 lcd.setCursor (0,0);

 lcd.write(0);

 lcd.write(1);

 lcd.write(2);

 lcd.write(3);

 lcd.write(4);

}

 

void loop() {}

 

 

If you've slapped your board with this code what you'll get is five characters appearing in the top left of your LCD display. The first is the all pervasive smiley, the second looks like somebody making a rude gesture with his tongue, the third is a sad face. The next one looks like a bell, and the last a ball. We can do this because each block of your LCD display is made of pixels, there are five across and eight down and if you turn your contrast up enough you will faintly see them. We can control those pixels by assigning eight binary numbers to a character, giving it a number from 0 to 7 and writing it to the LCD display, just as above. This is the sense:

 

                                                 00000                                                                             00100                                      

 

                                                 10001                                                                             01010

 

                                                 00000                                                                             01010

 

                                                 00000                                                                             01010

                                               

                                                 10001                                                                             10001

 

                                                 01110                                                                             11111

 

                                                  00000                                                                            00100

 

                                                  unused                                                                          unused

 

 

There's no technical reason why you can't use the eighth row, it's just that we tend not to for the aesthetic, things look a bit distorted in 5 by 8. There are three distinct components to creating a character and they all work in exactly the same way so let's just consider one of them. I really like that bell, so that's the one we'll do. Firstly you have to denote the binary numbers for each row in order:

 

byte bell[8] =  {B00100,B01010,B01010,B01010,B10001,B11111,B00100,};

 

The byte just means 8 bits of data are being stored. Count them, go on. Yep. There's seven. But there's a comma after the last one and an empty space. That's equivalent to putting 00000 in there,so that's eight.

The observant among you will have noticed that you put a 1 where you want a pixel to be visible, and a zero where you don't. Exactly right, and that's the best way to remember it.

 

The second part is creating the character and assigning it a number:

 

 lcd.createChar(3, bell);

 

and here all we've told it to do is take the binary numbers given in array bell, (that's what the capital B in front means) read them one by one and create rows according to the values. Then give this character the number three, and stick it in the LCD module's controller memory.

 

The third part is to actually write it on the screen:

 

 lcd.write(3);

 

And that's it. However, I'm a bit fed up of them just sitting there staring blankly at me. Let's make them do some work.

 

 

 

 

 

Modify the code above by adding to void loop to make it look like the following:

 

void loop() {

for (int x=0;x<11;x++){

  delay (1000);

lcd.scrollDisplayRight();}

for (int x=0;x<11;x++){

  delay (1000);

lcd.scrollDisplayLeft();}

}

 

what should happen when you upload is that the glyphs should all now move one space to the left, and when the ball hits the right edge of the screen they all move back again. Then the smiley hits the left, and the whole shebang starts again.

This is due to the two for/next loops and the commands

 

lcd.scrollDisplayRight();}

 

unsurprisingly, this forces the output display to move one space right

 

lcd.scrollDisplayLeft();}

 

which equally unsurprisingly moves it one space left.

 

Change void loop ( ) to

 

void loop() {

  delay (300);

lcd.scrollDisplayRight();

 

}

 

and they'll whizz over to the right, disappear and eventually reappear on the left. If you change to:

 

void loop() {

  delay (300);

lcd.scrollDisplayLeft();

 

}

 

They'll do it the other way round.

 

Let's do something practical. When you set the cursor on the LCD display, you give it two numbers inside the brackets:    lcd.setCursor(0,1);  and the first is the column reading leftwards, the second the row. So:

 

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 

byte bell[8] =  {B00100,B01010,B01010,B01010,B10001,B11111,B00100,};

 

void setup() {

 

  lcd.begin(16, 2);

  lcd.clear();

  lcd.createChar(0, bell);

 lcd.setCursor (5,0);

 for (int t=0;t<6;t++){

 lcd.write(0);}

lcd.setCursor(0,1);

lcd.print ("Merry Christmas!");

delay (2000);

 

}

 

void loop() {

delay (200);

lcd.scrollDisplayLeft();

}

 

Now, there's absolutely nothing in there that you don't know how to do now, and by combining what you know you can come up with a good solid device that does something useful- well not particularly useful in this case but mildly amusing nonetheless and somebody'll like it. I bet if you put something like this on a Santa hat, loads of office workers would wear them at the Christmas do.

This is the essence of good design. Take what you know and pour it in, and if you don't know something find it out.  The more you know, the greater your projects become, and the greater your projects become, the more you can make, until comes the day when you make or discover something extraordinary.

And with that in mind, let's delve a bit deeper into the LCD display.

 

 

Controlling your LCD Display

Go Back

No. 1- Creating Glyphs

No. 2- Scroll Left and Right

More>

This link points you to a rather splendid website that lets you paint your glyph and then works out the binary code for you. Now, how good is that?

icontexto.com/charactercreator/