Graphic LCD 128x64

Hi

This is my first time using GLCD.

I received this GLCD but I have no idea about its driver.

I have installed U8glib.h

I have watched number of videos and have tried a few but failed to get any display.

The last I tried is:

GLCD Nano
1 GND
2 5V
3 Wiper of contrast POT
4 (RS) D4
5 (RW) D5
6 (E) D6

15 (CS1) GND
17 (RST) D7

19 3.3V
20 GND

This is the code portion which I included in the Graphic Test example sketch.

#include <U8glib.h>
#include <Wire.h>
U8GLIB_ST7920_128X64_1X u8g(6, 5, 4, 7); //Enable, RW, RS, RESET

I would appreciate if anybody could guide me how to get my GLCD work.

It looks like a KS0108 controller.

david_prentice:
It looks like a KS0108 controller.

Yes, that would be my assumption too. You need to connect 8 more Arduino pins to D0-D7. And use the appropriate constructor for ks0108.

19 3.3V

What is 19? I forget... but whatever it is, Nano's 3.3V pin can only supply a small current. Why are you using that?

EDIT: is 19 the backlight anode? Definately don't use the Nano 3.3V for that, it can draw a lot of current and damage the Nano! The displays usually have a built-in series resistor. But in case your display does not, connect to 19 to 5V and put 100R in there and measure the current drawn. From that reading we should be able to tell if there is a built in series resistor and whether you need to keep the 100R in there.

PaulRB:
Yes, that would be my assumption too. You need to connect 8 more Arduino pins to D0-D7. And use the appropriate constructor for ks0108.

But in most of the videos I have watched, they have been using only 4 Arduino pins (eliminating D0-D7). If there's no way around then I might need to switch to Arduino Mega because I need at least 7 more digital pins.

These displays do not all have the same controller chips. The two most common are st7920 and ks0108. St7920 has both 8 bit parallel and 4 wire SPI interfaces. Ks0108 has only 8 bit parallel interface. The videos you watched probably used the SPI interface on a st7920 display.

You can buy i2c backpack modules that will fit on to ks0108 displays and allow you to update the display using 2 wire i2c interface. Unfortunately I think these backpacks are not compatible with u8glib library, so you would need to use a different library such as one written by Nick Gammon. That library has only basic features compared to u8glib.

Okay. For testing, I am still using a Nano.

The U8Glib has only one constructor for KS0108 controller.

U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); 		// 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16

The connections I made are shown in the attached diagram but I can’t find pin di on the display which has to be connected to A3 (17) of Nano. As can be seen in the diagram the RS pin and the /RST pin of the display are not connected.

If I connect A3 to RS and then remove I can see some momentarily activity on the display (straight horizontal lines and some flickering pixels).

If I connect A3 to /RST, no activity.

"di" is "RS". I guess "di" is shorthand for "display data/instruction data".

Connecting RST to a pin is optional. If you don't use a pin, connect it to 5V.

Also you should not be using u8glib. It is old and no longer being worked on by its developer (who is a member of this forum). You should switch to using u8g2.

RS, DC, DI, A0, ... are all common names for a RegisterSelect, DataCommand, DataInstruction, Address0 pin.

They all do exactly the same thing: i.e. differentiate between lcd_data() and lcd_command() functionality.

This applies to a whole range of LCD, GLCD, OLED, TFT, ... controllers.

From the U8g Wiki:

U8GLIB_KS0108_128(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw [, reset])

So there is an optional RST pin argument.
I suggest that you connect the RST pin to a spare GPIO pin on your Nano. And add the appropriate optional argument

You must connect the RS pin to A3 (17).

Most modules have a weak pullup on the /RST pin. So omitting any connection will probably work. After all, Oliver made the reset argument optional.

It is wise to put pin functions as a comment to your constructor e.g.

//U8GLIB_KS0108_128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw);
U8GLIB_KS0108_128 u8g(   8,  9, 10, 11,  4,  5,  6,  7, 18,  14,  15, 17, 16);

or if you connect RST pin to A5 (19) on a Nano

//U8GLIB_KS0108_128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, rst);
U8GLIB_KS0108_128 u8g(   8,  9, 10, 11,  4,  5,  6,  7, 18,  14,  15, 17, 16, 19);

Personally, I am happier with using the names printed on the Nano e.g.

//U8GLIB_KS0108_128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, rst);
U8GLIB_KS0108_128 u8g(   8,  9, 10, 11,  4,  5,  6,  7, A4,  A0,  A1, A3, A2, A5);

David.

p.s. Note that U8g is deprecated. You should really be using U8g2

david_prentice:
RS, DC, DI, A0, ... are all common names for a RegisterSelect, DataCommand, DataInstruction, Address0 pin.

They all do exactly the same thing: i.e. differentiate between lcd_data() and lcd_command() functionality.

This applies to a whole range of LCD, GLCD, OLED, TFT, ... controllers.

From the U8g Wiki:
So there is an optional RST pin argument.
I suggest that you connect the RST pin to a spare GPIO pin on your Nano. And add the appropriate optional argument

You must connect the RS pin to A3 (17).

Most modules have a weak pullup on the /RST pin. So omitting any connection will probably work. After all, Oliver made the reset argument optional.

It is wise to put pin functions as a comment to your constructor e.g.

//U8GLIB_KS0108_128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw);

U8GLIB_KS0108_128 u8g(   8,  9, 10, 11,  4,  5,  6,  7, 18,  14,  15, 17, 16);



or if you connect RST pin to A5 (19) on a Nano 


//U8GLIB_KS0108_128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, rst);
U8GLIB_KS0108_128 u8g(   8,  9, 10, 11,  4,  5,  6,  7, 18,  14,  15, 17, 16, 19);



Personally, I am happier with using the names printed on the Nano e.g.


//U8GLIB_KS0108_128 u8g(d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, rst);
U8GLIB_KS0108_128 u8g(   8,  9, 10, 11,  4,  5,  6,  7, A4,  A0,  A1, A3, A2, A5);





David.

p.s. Note that U8g is deprecated. You should really be using U8g2

Thanks David, for your detailed explanation.

I simulated in Proteus and found that D13 of Nano was issuing signal so I tested connecting D13 with /RST pin and it worked.

If I switch to U8g2 the constructor would be:

//////////////////////////////////D0,D1, D2, D3,D4,D5,D6,D7, EN, RS, CS1, CS2 /////////////////////////////////////////////////
U8G2_KS0108_128X64_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, A4, A3, A0,  A1, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/  U8X8_PIN_NONE); // Set R/W to low!
////////////// RST = 5V, R/W = GND /////////////////

Though it worked on Proteus, but not properly on the breadboard. Here is how it looks. I tried shaking the jumper wires but nothing improved.

One more question. Is there any way to use the KS0108 GLCD with fewer pins, my requirement is mainly to display text and bitmap image?

From the U8g2 wiki:

U8G2_KS0108_128X64_F(rotation, d0, d1, d2, d3, d4, d5, d6, d7, enable, dc, cs0, cs1, cs2 [, reset]) [full framebuffer, size = 1024 bytes]

This constructor copes with a 192x64. That is why it has 3 CS arguments. You do not need CS2 for a 128x64

Otherwise, the constructor is almost the same as U8g. Just rotation and CS2 are new arguments.

No, you always need 14 GPIO pins for a KS0108. Which does not leave you much spare.

Buy a ST7920 and use SPI mode if you want less pins.
Same applies to TFT projects. Parallel uses lots of pins. SPI uses less pins.

David.

p.s. ST7920 does not play cricket on the SPI bus.

One more question.

Aswered in post #5.

I did once get ks0108 working with u8g2 and fewer pins, using 2 x 74hc595 with a wemos mini:

Thanks all of you for your inputs.

How do I mark this post as [solved]?

Edit the Title.

I was intrigued by the Gammon I2C library but assumed that I2C would be far too slow and cumbersome for a KS0108 Graphics display.

When someone posted a link to the DIYMORE backpack I thought that I would buy one e.g. IIC I2C TWI SPI Serial Interface ExpandedBoard 1602/2004/12864 – diymore

Anyway, the Display works pretty well on I2C but the class methods are a little unusual.

So I have written an Adafruit GFX style library that makes it almost the same as the Adafruit_SSD1306 128x64 displays. i.e. familiar text, graphics, fonts, images, ...

Note that KS0108 can not do the SSD1306 hardware scrolling.
And LCDs look smeary when you animate pictures.

I have posted the project on GitHub GitHub - prenticedavid/Adafruit_KS0108_kbv: KS0108 library for DIYMORE 16-bit backpack

The adapter makes an old KS0108 display practical to use on an Arduino. i.e. 2 I2C pins vs 14 GPIO pins for Parallel.

David.

+1 karma @David.

Did you try 400KHz speed?

But as you mentioned, the very slow response time of these displays means that continual high speed updates just result in a blurry mess.

Yes it runs at 400kHz. The MCP23017 can run up to 1.7Mhz. A Uno can manage about 750kHz but you have to worry about the other slaves on the bus.

I use a SRAM buffer like Adafruit_SSD1306 but only update the smallest screen rectangle.
I could probably reduce to each minimised page rectangle.

Please put it through its paces. As you can see, it is easy to port existing SSD1306 projects.

David.

When I was playing with the KS0108 I found this library for the “other” GLCD GitHub - cbm80amiga/ST7920_SPI: ST7920 SPI 128x64 LCD library

I rather liked the example Demo. Although it writes to the LCD quite fast you don’t get upset by smearing.

Since it appeared to use GFX methods, I thought:

This must be easy to write a GLUE class for Adafruit style libraries

Well actually it was a bit messy.

However the result was ok. You can run the same ST7920 Demo on Adafruit_KS0108_kbv hardware or on a regular SSD1306 I2C display (or the intended ST7920 SPI display)

Obviously the Demo runs faster on SSD1306 or ST7920 but is respectable on the KS0108 with DiyMore backpack.

David.

ST7920_Demo.zip (4.72 KB)