KS0108B. GLCD Library to use for recent Uno's, Mega's and Nano's

Hello and Merry Xmas,

I bought a KS0108B compatible GLCD from eBay recently.

I saw that there had been hundreds of sales of this item for the Arduino and I have seen projects that include this GLCD so I was expecting things to be fairly straightforward (as it was when I played around with a 16x2 and 20x4 HD44780 display).

I’ve connected this device up to a Uno but I’m not even getting beyond the first stage which is to successfully compile a program that includes the GLCD library.

I’ve downloaded the glcd-v3-20111205.zip library from https://code.google.com/p/glcd-arduino/downloads/list and placed it in the arduino library directory.

I then tried to compile the below program.

// Project 26 - Seeing the Text Functions in Action
#include <glcd.h> // include the graphics LCD library
#include "fonts/SystemFont5x7.h" // include the standard character fonts for it

int j = 7;

void setup()
{
  GLCD.Init(NON_INVERTED);
  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7);
}

void loop()
{
  GLCD.ClearScreen();
  GLCD.CursorTo(1, 1);
  GLCD.Puts("Hello, world.");
  GLCD.CursorTo(1, 2);
  GLCD.Puts("I hope you are ");
  GLCD.CursorTo(1, 3);
  GLCD.Puts("enjoying this");
  GLCD.CursorTo(1, 4);
  GLCD.Puts("book. ");
  GLCD.CursorTo(1, 5);
  GLCD.Puts("This is from ");
  GLCD.CursorTo(1, 6);
  GLCD.Puts("chapter ");
  GLCD.PrintNumber(j);
  GLCD.Puts(".");
  do {} while (1);
}

In response I am getting the following error message:

Arduino: 1.6.6 (Windows 10), Board: “Arduino/Genuino Uno”

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,

from C:\Users\Tony\AppData\Local\Temp\build489197967d89429f53b54a1244d73c37.tmp\sketch_1_.ino.cpp:1:

C:\Program Files (x86)\Arduino\libraries\glcd/fonts/SystemFont5x7.h:48:28: error: variable ‘System5x7’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’

static uint8_t System5x7 PROGMEM = {

^

Using library glcd in folder: C:\Program Files (x86)\Arduino\libraries\glcd (legacy)
exit status 1
Error compiling.

And I’ve tried to compile a different program that shares the same include and setup commands and I get a different error message:

Arduino: 1.6.6 (Windows 10), Board: “Arduino/Genuino Uno”

error: ‘include’ does not name a type

include “fonts/SystemFont5x7.h” // include the standard character fonts for it

^

C:\Users\Tony\Documents\Arduino\GLCD_2__2_.ino: In function ‘void setup()’:

2:10: error: ‘System5x7’ was not declared in this scope

GLCD.SelectFont(System5x7);

^

Using library glcd in folder: C:\Program Files (x86)\Arduino\libraries\glcd (legacy)
exit status 1
‘include’ does not name a type

This issue is complicated by the fact that I’ve only just found out that there are different PinOut settings for these GLCD’s. I believe that Pinout D applies to my device (I’ve attached the specs) but at this stage I’m not even able to get beyond the point where I am able to compile a program that uses the GLCD library.

If anybody is able to help, it would be much appreciated as I would like to be able to use this screen.

Cheers

Tony

I'd suggest reading the notice I provided at the top of the description on the google code zip image download page. It specifically states that this library no longer works and provides a link to where you can find further information and alternative libraries.

In terms of pinouts yes there are many different pinouts for ks0108 glcd modules. You must use the correct datasheet to determine how to wire up the signals. If you wire it up incorrectly, you can damage the glcd for the arduino board. That is why I recommend always using a datasheet and not trying to use a type A, B, C, D etc.... The datasheet will clearly show what pin is used for each signal. The critical thing is to make sure that the datasheet being used is for the glcd module you have.

--- bill

Hello,

I have to apologise as I’m new to electronics although I have a programming background.

Yes, I see that the glcd library has been discontinued. The only reason I have given it attention is because on Adafruit, where they sell KS0108 GLCD’s, they provide a link to this outdated library and not the newer openGLCD library.

I have downloaded the openGLCD library and I’ve imported it into the Arduino IDE.

I’ve obtained the Pin Assignments for my specific KS0108B device. I’ve attached a word document and the Pin Assignment appears on the bottom of page 2. I take your point that I should look at each pin assignment and not assume that my device will fall under a mapping configuration such as Pinout A or Pinout B.

In the doco attached to the openGLCD zip file I’ve gone into
openGLCD/doc/html/page_ks0108_family.html

I have no trouble matching most of the the KS0108 pin functions on this webpage to the Pin Assignment for my particular device.

My problem is understanding the Vee/Vout Contrast out pin function.

To explain, Pin 5 on my particular device handles the operating voltage for LCD. I have this pin going into the wiper of a 10k trimpot. I have one leg of the trimpot going to ground with the other leg going to 5V via a 330ohm resistor.

The description for the Vee/Vout Contrast out pin function is “connect to 1 leg of Contrast pot”. This is where I become lost. The pin assignment for VEE on my device is pin 18.

Is it saying that I need to connect pin 18 to one of the trimpot legs? If so, which leg given that one leg is going to ground and the other to 5V?

This is where my lack of an electronics background fails me and I don’t understand what to do next.

I’ve also attached a couple of pictures of my project.

KS0108.zip (1.11 MB)

The contrast pot is a bit confusing, particularly since most of the datasheets are a bit sloppy and often wrong in the their pin descriptions for the contrast circuit related pins.

There seems to be some confusion over the contrast pot and a backlight resistor.

The simple answer is that there are 3 connections to the pot

  • leg1 directly connected to (GND or +5V)
  • wiper directly connected to (VR/Vo input)
  • leg2 directly connected to (Vee)

One leg can be either GND or +5v, The reason being that GND works for “normal” temperatures and uses a little less power than using +5v.
I believe that the openGLCD documentation always recommends using GND on the leg.
(That was the intent, let me know if you saw something else and I’ll correct it)

There is no additional resistor used on the contrast circuit.
In some cases there is a resistor needed on the backlight power connection to limit the current to the backlight, but that is separate and different from the contrast pot circuit.
I’m not familiar with that display to know if a resistor is needed and what value to use.
Most LCDS no longer need them, but if you have a module that needs one, and don’t use one, it will burn up the backlight LED very quickly if not immediately.
The backlight resistor goes between (in series) with the power to the backlight.
In your case, “A” Backlight power supply (Pin 19) ------ resistor ----- +5v

Not sure where you read about +5v and GND going to the pot legs.
That would be a bad typo that I need to correct.
There is a warning section above that mentions this for a hd44780 lcd but that warning was trying to explain how +5 and GND is used on the legs when using a hd44780 LCD but it is not connected that way for a ks0108 display.
Let me know if you saw this somewhere else.


Long explanation

The “VEE” signal (pin 18) on your display is an output. It is a negative voltage provided by the module.
Your datasheet is one of the many that is incorrect since it designated it as both an input and output.
However, if you look at the block diagram you can see the arrow for the VEE signal showing it is an output from the power supply block.

The “VR” signal (pin 5) on your display, is the “Vo” signal or the “Contrast in” (name in openGLCD tables)

The key to understanding how to wire up the pot is to understand what it is doing and how it works.
The pot is used to vary the voltage being fed to the “VR” input pin.
A pot has 3 connections.
2 “legs” and a “wiper”.
On each end is a connection (leg) and there is a resistor between them.
Then there is a connection that slides across the resistor to vary the resistance between the wiper and each of the end “leg” connections.
The result of this is that pot acts as voltage divider. It will provide a variable voltage that varies from the voltage on one leg to that of the voltage on the other leg as you turn the nob.

So the GLCD needs nagative voltage but the exact voltage varies depending on conditions.
Vee will be too low and +5v will be too high. Typically even GND will be too high.
So the pot is used to crate a tunable voltage from Vee up to the voltage on the other leg.
GND or +5v will work; however, GND is typically high enough and that is why GND is recommended as it will save a little bit of power over using +5v.

— bill

Hi Bill,

I appreciate the time you have taken to give me such a detailed response.

I’ve tried again to connect everything up. I’ve used the openGLCD html page “Wiring” to give me the pin descriptions and the pins to connect to on the Uno. And I’ve used the Pin Assignments provided for my particular device.

I’ve attached a zip file.

It contains a spreadsheet.

The two blue highlighted columns show how I have mapped the pins on my KS0108 to the Uno.

I’ve also attached a couple of photos. One has the trimpot removed so that you can see how it is wired underneath.

For pins 1-2 and 5-16 on my device, I’m marrying up the pin on my device with the pin on the Uno based on the Pin Functions.

Pin 3 is going to ground
Pin 4 is going to 5V
Pin 5 is going into the wiper for the trimpot
Pin 17 is going to 5V
Pin 18 is going into one of the legs on the trimpot. The other leg is going to ground.
Pin 19 is going to 5V via a 330ohm resistor
Pin 20 is going to ground.

I’ve uploaded the hello world program in Examples - openGLCD on the Arduino IDE to the Uno.

And nothing appears to be happening. I also tried DrawHBarGraph example.

Have I misunderstood something that you have said?

Pin 17 is the Reset pin. I don’t connect it to the reset pin on the Uno?

I’m sure that I’m making a very basic mistake somewhere. I just don’t know what it is.

100CANON.zip (589 KB)

From looking at the photos and spreadsheet everything looks ok. However, from the photos I can't verify that the wires from the glcd actually go to where the spreadsheet says they are going.

When brining up a glcd for the first time, the best tool to use is the GLCDdiags sketch. It will test verify the connections and the glcd module RAM and report any issues. While it can't always pin point the exact issue since many wiring issues can cause nothing to work, it is very useful for helping diagnose issues.

Run the GLCDdiags sketch and post the serial output here. It would also be useful to see a wider photo so that the connections from the glcd to the uno can be seen and verified. If you are running IDE 1.6.6 then you will have to make a small tweak to the diag sketch to get it compile as the new IDE function prototype parser in 1.6.6 breaks when used on certain valid code that should work. The work around is pretty minimal and I've already fixed it but have not created a new library release yet. If using 1.6.6 you will need to add a prototype to the code to keep the IDE from trying to do prototype processing. Insert this line of code into the code at line 125 with the other prototypes:

void SerialPrintP(PGM_P str );

Another thing to check is to verify that each of the 5 holes in each of the grouped holes in the bus bar row connections for power and ground are connected to each other because some bread boards oddly enough keep each 5 holes separate from each other.

--- bill

Hi Bill,

I double checked the wiring and it all seemed fine.

So I uploaded GLCDdiags.

It initially reported failures on each loop. I did a screen capture (couldn’t work out how to copy and paste directly from the Serial Monitor) and put the screen shots in a word document, which is attached.

When I received this unit in the mail, it came unsoldered.

I soldered on the header pins for this unit myself as I did for the two HD44780 LCD’s that came in the mail previously. They’re working fine.

I had a feeling that it was something very simple that I had got wrong.

So, I went and looked at my soldering handiwork under a magnifier and sure enough, I had a bridge of solder joining pins 7 and 8.

I went and fixed that up and re-ran the GLCDdiags program and not only isn’t it reporting any errors but I’m now getting output appearing on the screen.

I took a few snapshots which I’ve included in the zip.

I thought initially that everything was done and dusted but looking at the output I thought that maybe it was printing things at the half way point (with output then wrapping around) as opposed to flush to the left.

I uploaded the Hello World program and you can see that “hello, world” is staring at the half way point with d! wrapping around to the left of the screen.

Is this something that I align in software or could it be that I have a faulty unit?

I appreciate your help in all this.

Cheers

Tony

KS0108.zip (707 KB)

Hi Bill,

Google is truly a blessing.

I did a google search on “GLCD Display Half way” or something like that and it came back with a hit on the below link.

In it, the guy swapped the CS1 and CS2 wires around.

http://www.protonbasic.co.uk/showthread.php/58405-GLCD-LCD-Not-Centered

I did the same and it’s working brilliantly.

And I understand now that one chip CS1 and CS2 relate to separate chips. One chip handling one half of the display and the other the other half.

I’ve attached fresh pics. All but three of them are blurry. My camera, not the GLCD.

Thanks so much for your help.

Cheers

Tony

2015-12-30 001.zip (607 KB)

Very Cool! Often it is simple stuff that creates the most annoying and difficult issues to solve. Glad you got it all working.

BTW, there is a small trouble shooting section in the openGLCD documentation that covers some of the more common issues including chip select left/right swap issue.

If you notice the diag sketch paints a triangle when it first comes up. You can see it paint from upper left to lower right. The value of that is that if the chip select configuration or wiring is not quite correct then you will not see a smooth fill from left to right / top to bottom. However, from looking at the pattern that is painted and how it fills, you can often determine how to re-configure the chip selects. This is very helpful with some of the 192x64 displays which vary quite a bit as to how they do their chip select signals. Some use 2 signals and some use 3, and there is quite a bit of variation within the 2 signals vs the 3.

Soon I'll be pushing out another version of the library with some minor updates but mainly to work around some issues that came up in IDE version 1.6.6 - although most of these have been fixed with the recently released 1.6.7 IDE.

--- bill