GLCD library version 3 (end of life - no longer supported)

dc42:

bperrybap:
Well, I did have a look. There really isn't anything that is "easy". What you are seeing is mainly the inefficiency of the
variable font format itself. (there are much faster ways to store and lookup the font data but it does require a bit more flash space)
With the current variable font format, to locate the data position for a character you have to
to add up the width of each previous character in the font. It is time consuming, especially on a Harvard Architecture
chip like the AVR since you have to call access functions. That is why you see each character taking longer and longer
to render. Each lookup and font width add for each character along the way
adds about 3us or so to the overall rendering.

I think it would be well worth using 1 additional byte of flash per character by ditching the byte count and instead having a table of pointers to the start of the data for each character, plus one extra pointer to enable the byte count of the last character to be calculated.

As a short term improvement, you could consider caching the address of the data for the character that is half way through the table, giving you an alternative place to start searching from.


I like the idea about having an offset value for a character that is half way through the table
This is an interesting idea that I may look further into as that can be calculated runtime and
saved in RAM as the font is selected. It also does not require modifying the existing font data format.


As far as font formats go, let me start of by saying I am not a fan of the current variable font data format.
Michael and I were painfully aware of its issues and limitations when we moved forward with it going into v3.
It existed before I started working on the glcd library and even before Michael converted
Thiele's original C library to C++ for Arduino.
There are other issues with the variable font data format that are also irritating and also cost time,
like the residual bits in a font data byte when the font is not exactly a multiple of 8 bits.
The bits in the font data are shifted the wrong direction for aligning with the glcd page byte.
(This is different from how bits are stored for fixed fonts and bitmaps)
This causes additional code and checks to have to be done, while rendering,
to detect when the last byte in a column is being rendered
and to shift the bits around when the font is a variable font and not a multiple of 8 bits in height.
Michael and I had some long discussions about changing the font data format to at least get rid of the incorrectly shifted bits.
I would be nice for rendering in that all the rendering would then
be the same whether the "glyph" was a fixed font, bitmap, or variable font.

The issue early on of the v3 development was that it would break compatibility with ks0108/glcd v2 library
since none of the v2 fonts would work and a major goal of v3 was backward compatibility with v2.

Having a new font format also means re-doing the fontcreator2 JAVA app to be able to generate the new format.
While its not that bad, we opted not to do that for v3.


With respect to the current variable font format, there is no "byte count" for each character.
The data byte for each character is the width of the given character. I assume that is what you meant.
(byte counts and widths are not the same for fonts that are taller than 8 pixels)
I didn't follow your comment about: "plus one extra pointer to enable the byte count of the last character to be calculated".
I assume you meant that the width could be replaced with 16 bit offset values.
And that the width could be back calculated fairly easily knowing the address of the "next" character
and the height of the font.
But it does require and offset value for a "next" character just after the real last character in the table.

Definitely worth considering going forward.

There is also the possibility of having the width and formatting information inside the "glpyh" data.
So the offsets point to a "glyph" and the glyph data has all the needed sizing and leading information
which is a closer match to some of the other font formats used in Operating systems.

I really want to get away from this font format. I also want to be able to either directly use BDF format or
write a small script/tool that can convert from BDF fonts to the embedded format.
That will instantly allow the creation of hundreds of fonts - which will ease the pain of people
having to deal with the loss of their existing font formats should the font data format be changed.
Yes it would be possible to support multiple formats, but that takes extra code since all the rendering for
all the formats would have to exist and be selected runtime
based on the font. It also adds to the maintenance and support load of the library.

There are several other issues such as the current way the font data is compiled & linked in that needs to be resolved.
Currently they are all "static" data arrays that are all compiled in and the linker removes
out the unused fonts.
This creates real problems for implementations that use more than a single source code module.
There are many ways to resolve this but most won't work with the Arduino IDE and its goofy way
of doing things.

I have many ideas and things that could be done, it is a matter of trying to pick the highest priority
items moving forward that can offer the best trade-off of new & improved functionality and backward compatibility.

--- bill

It becomes difficult to follow this HUGE thread, but let me allow to make some small notes.

BDF: Yes, i think BDF is an excellent source for fonts. It is easy to parse, there is a ttf to bdf converter (called OTF2BDF) and there are already very good open source BDF fonts in the X11 distribution: freedesktop.org git repository browser

Inner glyph offset: After profiling of my font format i found that the searching for the glyph data start position required a big fraction of the overall time for rendering. I added the offset of the lower case 'a' and the upper case 'A', to my font format, which was great speedup (about overall factor 2, if I remember correctly).

Fonts in PROGMEM area: A big issue. In principle one can place one font in one C file (did not check C++ files), declared with the PROGMEM attribute. All other parts of the program will only see the external declaration from some .h file, e.g.

extern uint8_t my_font_data[] PROGMEM;

For the linker to be able to remove the font from the final hex file, it is required to place all fonts in separate C files. Unfortunately this becomes impractical as soon as there are several hundred fonts.
Simply the compile time of the Arduino IDE gets very high. After several hours of investigation of the gcc garbage collector I found that it is possible to put all fonts into the same C file, if the font data are assigned to different progmem sections.
This will look like this:

extern uint8_t my_font_data1[] __attribute__ (( section(".progmem.font1") ));
extern uint8_t my_font_data2[] __attribute__ (( section(".progmem.font2") ));

Oliver

I needed help with the GLCD library version 3 I am also new to the Ardunio world, I have an KS0108 (B pin setup) it is labeled JHD521M7 12864AB ,

I have been trying to get work for about two weeks now , i have cross checked the wring more than 1001 ( I have Tomas Edison beat on this one) and I have also learned how to labeling all wires makes things easy , the GLCD work on my PIC so I know its good, however with the Arduiono there are no pixels displayed, I could adjust the contrast and the back light is working fine , and I have ran GLCDdiags and i got this

Diag Loop: 3
Initializing GLCD
GLCD initialization Failed: RESET wait Timeout (status code: 2)

the pins are configured right, so is there any one brave enough to help me

GLCD data sheet

http://www.itron.com.cn/PDF_file/JHD12864AB.pdf

Akim14,
I'll post answers in your other thread:

--- bill

Hello:

I am very new to the forum and the Arduino products. I have just purchased a Mega2650 and it comes with a 128x64 display. I have tested the board with LED bulb with "Blink" and it work. But I can never get even the blacklight of the Display works, it is black. I been searching for document and now come to this GLCD library topic and find the download here, Google Code Archive - Long-term storage for Google Code Project Hosting., should I download the file and add to my Arduino program. it also states in the readme file that a sketchbook directory, I don't have a sketchbook directory should I just create one.

anyway, I am try to do the first step, to make the display lit up. Oh, I have follow the Point B for setup the pins.

Thank you.

cc

The google site you have if for the GLCD library, that I'm maintaining.
glcd v3 RC3 is the latest version.
There is also some information about the older v2 version here:
http://www.arduino.cc/playground/Code/GLCDks0108

You actually do have a sketchbook directory.
Bring up the IDE and click on [File]->Preferences

You sketchbook directory can be anywhere you want.
The location that the IDE is looking for you sketchbook is
in the text box right there at the top of the "preferences" dialog.

Wherever that directory is, you will need to create a directory called
"libraries", then extract the zip image into that directory.
So you will end up with
{sketchbook directory}/libraries/glcd ....

Make sure you have properly identified the glcd type as incorrect wiring up the glcd
could damage the glcd or the Arduino board.

Make sure the datasheet that you have for you glcd module is for the glcd that you have
by verifying that the part number on the back of the glcd matches what is in the datasheet.

Some glcds have labeled pins but many do not, make sure you properly identify pin 1.

If you need help, just ask additional questions and I'll be happy to help.

--- bill

Thank you for your prompt reply.

I have made the LCD display lit up. It is blue now. I have installed the glcd in the sketchbook location.

I got message "Done compiling" and "Binary sketch size: 6108 bytes (of a 258048 byte maximum) after upload the sketch,
I used the "HelloWorld" and "GLCDdiags" files Under File of IDE, Sketchbook>libraries>glcd> both of them got the above messages and the green light on the board blinks with "HelloWorld" and stay green with "GLCDdiags". Please advise how can I made "Hello World" or anything dispaly on my LCD display.

thanks again.
cc

Diags reports information out the serial port.

Unless the glcd is bad, incorrect wiring is always the cause for the glcd not working properly.

Since the backlight is now working, you have changed something with the wiring.

Make sure that you have the correct data sheet and wiring up the glcd according to the datasheet
and the documentation included with the library.
Wiring is not something you want to be guessing
as incorrect wiring can damage the glcd or the Arduino board.

When things are not yet working. Use the diags sketch.
Until diags pass, there is no reason to try to run any other sketch.
Diags will display useful information on the serial port
about how the library is configured and any potential testing failures.

--- bill

Hi, Bill:

Thanks again.

Here is the datasheet I used to do the wiring
http://fritzing.org/projects/128x64-lcd/
I also read the the ks0108mega.h file
#define glcdDI 36 // D/I Bit
// Reset Bit - uncomment the next line if reset is connected to an output pin
#define glcdRES 30 // Reset Bit

it seems the only difference for the datasheet I used and those states at the config file is those I copied above, is there a difference of D/I bit and RS. My reset is 17 not 30, should I use 30 instead.

When I compile the sketch, do I need to disconnect the reset, let the sketch upload and connect the reset.

I have used the GLCDdiags and nothing happen to the LCD display. you mentioned about using the diag and until it pass, is this diag the same as the GLCDdiags sketch I used. When I compiled the GLCDdiags, other than the comment regarding the byte, there is no other information. You also said diag reports information out the serial port, where can I find the serial port, bear with me, I know it sounds kind of stupid.

thanks
cc

carrieklchow:
Hi, Bill:

Thanks again.

Here is the datasheet I used to do the wiring
128x64 LCD

That is not a data sheet. That is a wiring diagram.
A data sheet will show all the technical information about the lcd panel
and will have the pinout for the lcd panel.
There are many different pinouts for ks0108 glcds and if things are improperly hooked up
it can damage the glcd or the Arduino board.
That is why it is very important to locate a proper datasheet for a glcd to see
the functions for each of the 20 pins to ensure that the pin connections to the Arduino are correct.
Here is what a couple of ks0108 datasheets look like:
http://www.longtech-display.com/produts/LCD%20MODULES/longtech%20pdf/LGM12864B.pdf
http://docs.bgmicro.com/pdf/lcd1030.pdf

Pretty much all glcds have their model silk screened on the back of the board.
Look at the back of the board and you should see the lcd model.
It will usually have "12864" somewhere in the model name.
You can do a google search with the model name to locate a datasheet for the glcd.

I also read the the ks0108mega.h file
#define glcdDI 36 // D/I Bit
// Reset Bit - uncomment the next line if reset is connected to an output pin
#define glcdRES 30 // Reset Bit

it seems the only difference for the datasheet I used and those states at the config file is those I copied above, is there a difference of D/I bit and RS. My reset is 17 not 30, should I use 30 instead.

Sorry about any confusion here.
RS and DI are the same. Some data sheets call the pin RS and some call it DI.
They are the same thing.

The numbers like 36 for glcdDI and 30 for glcdRES are Arduino pin#s.
All the numbers you see in the glcd pin config files like ks0108_Mega.h are arduino pin #s.
Numbers like "17" for reset are the glcd pin number.

If you want the glcd library to control the reset signal on the glcd, you hook
the arduino pin number for glcdRES to the reset signal pin number on the glcd.
In your case that would be hooking up Arduino pin# 30 to glcd pin #17.
Make sense?

When I compile the sketch, do I need to disconnect the reset, let the sketch upload and connect the reset.

Unfortuantely there are some issues with AutoReset on certain Arduino boards
which can cause uploads to fail when the the Arduino reset line is hooked directly to the glcd
reset pin.
The real issue is that some glcd modules need a reset pulse and some don't.
On the glcds that don't need a reset some glcds can work with the glcd reset pin tied to vcc
as shown in your wiring diagram. Some glcds will work when the glcd reset signal is left unconnected.

For the glcds that need a reset pulse the problem is that
some Arduino boards will not auto reset if the glcd reset pin is hooked up to the Arduino board reset pin.
For those glcds you must control the glcd with an arduino pin.

The safest thing to do at this point would be to eliminate any potential reset issue by letting
the library control the reset pin.
To do that you uncomment the line like you did and then hook Arduino pin 30 to the glcd reset signal pin.

After the glcd is working, if you don't want to use an arduino pin to reset the glcd, you can
try connecting the glcd reset pin to VCC instead. But if you do that make sure to go into the
ks0108_Mega.h header file and comment out the glcdRES line to make sure the glcd library
does not try to use the pin.

I have used the GLCDdiags and nothing happen to the LCD display. you mentioned about using the diag and until it pass, is this diag the same as the GLCDdiags sketch I used.

Yes sorry about my wording.

When I compiled the GLCDdiags, other than the comment regarding the byte,

"byte"? Not sure what you mean by this.

there is no other information. You also said diag reports information out the serial port, where can I find the serial port, bear with me, I know it sounds kind of stupid.

In the IDE if you click on the serial monitor icon, it will bring up the serial monitor.
Set the baud rate to 9600 and you will see the diagnostic messages from the GLCDdiags sketch.

If you post the information from diags, it will help to diagnose what is happening.

--- bill

Hi, Bill:

thanks a lot.

I have checked the wiring with datasheet, the board is SG12864J4. I have followed the pinoutB from this link :Arduino Playground - GLCDks0108

I have complied the GLCDdiags again, and here is the information from the Serial Monitor, I can only read that is a problem with the initialization of the GLSD and issue of reset. I don't know how to fix it.

Following is an extract the information from the serial monitor, it doesn't allow me to cut and paste and I just typed it out.

Reported Arduino Revision: 1.0

GLCD Lib Confirguration: glcd ver: 3 dlrd_Device ver: 1 gText ver: 1
GLCD Lib build date: Mon Dec 5 10:50:07 CST 2011
GLCD Lib build number: 442
panel Configuration:ks0108
pin Configuration:ks0108-Mega

GLCD:ks0108 DisplayWidth:128 DisplayHeight:64
Chips:2 ChipWidth:64 ChipHeight:64
CSEL1:33 (PIN_C4) CSEL2:34 (PIN_C3)
RW:35 (PIN_C2) DI:36 (PIN_C1) EN:37(PIN_C0)
DO:22 (PIN_A0) D1:23 (PIN_A1) D2:24 (PIN_A2) D3:25 (PIN_A3)
D4:26 (PIN_A4) D5:27 (PIN_A5) D6:28 (PIN_A6) D7:29 (PIN_A7)
Delays: tDDR:320 tAS:140 tDSW200 twH:450 twL:450
ChipSelects: CHIP0: (33, 0x1, 34, 0x0) CHIP1: (33, 0x4, 34, 0x1)
Date mode: byte

Diag Loop: 9
Initializing GLCD
GLCD initialization failed: RESET wait Timeout (status code: 2)

Can you teach me how to cut and paste from the serial monitor. BTW, I tried to open the Mega.h file but I cannot open it from my file directory, i.e. users/xxxxx/Document, how can I modify the .h file. I know probably in the future I need to uncomment the reset or change the file.

thanks again
have a nice weekend.
cc

You can copy and paste from the terminal window.
Just highlight the text in the terminal window,
then move to the window where you want to paste it and click the middle mouse button
to paste the highlighted text.

See this thread for some information about that error:

(ignore his information and just scroll down to my explanation of the error)

That error is always due to a wiring error.
Look at the diag output and wire up the glcd panel according the pins you see in the output.

You can see that glcd RW should be hooked up to arduino 35
glcd DI to Arduino 36
glcd CS1 to Arduino 33
glcd D4 to Arduino 26
etc...
Make sure that the wiring to the glcd is using the reported arduino pins for each glcd function.

Make sure you pot is wired correctly:

----- GND
------------------------------------- Vo (glcd pin 3)
----- Vee (glcd pin 18)

I don't know what you mean by this:

BTW, I tried to open the Mega.h file but I cannot open it from my file directory, i.e. users/xxxxx/Document, how can I modify the .h file. I know probably in the future I need to uncomment the reset or change the file.

I assume you mean {sketchbook directory}/libraries/glcd/config/ks0108_Mega.h ?
You showed some text from that file in your previous posts. Can't you open the file for editing using your favorite
text editor

--- bill

Good Day, Bill:

Thank you so much. The GLCDdiags finally works :slight_smile:

cc

What was the issue?
So, if possible, I can update the documentation to be clearer.

--- bill

is there a chance to use a shift register with the glcd library?
i ran out of free digi io´s, so i want to use a shift register (shiftout).

thanks
moe

Not right now.

While a simple shift register can be made to work, there are couple of technical hurdles.
The first is that it requires a frame buffer, the code already supports this but it does
consume quite a bit of: RAM 1024 bytes for a 128x64 display. This would preclude its use
on a m168 - (maybe thats not that big of an issue) but it may also not be acceptable
in some other environments.

The second is a performance issue.
The Arduino shiftout() routine implementation is not very fast.
There are better ways to write the code to make it much faster and
there are also other ways to clock out serial data than the way the Arduino guys implemented
their shiftout() routine that are even faster.

I've thought about designing a backpack board and offering it for sale.
The biggest challenge is that there are so many different glcd pinouts
that you can't make just one board.
I could make it where it has 2 sets of 20 pin holes on it and you pick
the correct set, but that is error prone and if the incorrect set is picked
it can blow up the glcd.
I'd really rather provide it as full solution (display & backpack combination)
to ensure it all works with the display

In the mean time, there is another library that works
with a SPI or I2C interface:
http://arduino.cc/forum/index.php/topic,52271.0.html

There is also this project which is pretty interesting but I'm not sure if works
with the latest glcd library.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284207458

--- bill

hi bill,

thanks for your reply.

to use the i2c bus is very interesting. i´m a arduino beginner, so it seems a little bit difficult at first sight.
also to purchase the MCP23017 is not that easy in germany.
i ll try to get one.

my glcd type is a CFAG12846B-TMI-V

i hope the code will work with that kind of glcd type too
what do u think?

---moe

Nick's library was done on a ks0108 which is the same type of module that you pointed to.
The pinouts for his module may be different from yours, but it is the same controller on the
glcd module.

Keep in mind that Nick's library is different from this one and is a simpler design
so it doesn't have as much functionality as the glcd v3 library.

--- bill

Hello,

I am having a little bit of trouble with my GLCD, any help would be greatly appreciated.
I am using the GLCD Library and running the Diag tool and I am getting the same output as the guys before:

Reported Arduino Revision: 1.0

GLCD Lib Configuration: glcd ver: 3 glcd_Device ver: 1 gText ver: 1
GLCD Lib build date: Mon Dec 5 01:50:07 CST 2011
GLCD Lib build number: 442
Panel Configuration:ks0108
Pin Configuration:ks0108-Mega

GLCD:ks0108 DisplayWidth:128 DisplayHeight:64
Chips:2 ChipWidth:64 ChipHeight:64
CSEL1:33(PIN_C4) CSEL2:34(PIN_C3)
RW:35(PIN_C2) DI:36(PIN_C1) EN:37(PIN_C0)
D0:22(PIN_A0) D1:23(PIN_A1) D2:24(PIN_A2) D3:25(PIN_A3)
D4:26(PIN_A4) D5:27(PIN_A5) D6:28(PIN_A6) D7:29(PIN_A7)
Delays: tDDR:320 tAS:140 tDSW:200 tWH:450 tWL:450
ChipSelects: CHIP0:(33,0x1, 34,0x0) CHIP1:(33,0x0, 34,0x1)
Data mode: byte

Diag Loop: 1
Initializing GLCD
GLCD initialization Failed: RESET wait Timeout (status code: 2)

I have checked the wiring again and again and I'm sure it is correct. I am using the Pinout A from the Arduino Playground - GLCDks0108 tutorial. Last night I got the GLCD to show the example from the old library. Today I rewired the wires to make them more accessible and now nothing. (quick note: when the screen was displaying last night, the image seemed to be moved to the right, such that position 0,0 was in the middle of the screen and the image would go all the way to the right and then finish the image starting from the left to the middle, strange)

I am using the the HQM1286404.

Any suggestions on what the problem might be? I just hope its not burnt out. and if so how do I check for that?

It sounds like the glcd was working before, which is very good.
The included documentation has some tips for resolving a swapped screen.
(bring up the html documentation and go to the troubleshooting section)
A swapped screen is due to the chip select lines being swapped.

A non working display is wiring %99+ of the time.

The display now not working means something is now wired differently than before.
The RESET failed message is due to the library waiting for the glcd to be complete with reset
and it thinks the display isn't ready after waiting longer than should be necessary.
This almost always do to improper wiring.

Any ideas what might have changed?

Do you have a link to a datasheet for the glcd so that the wiring can be verified?
(I couldn't locate one for a HQM1286404)

If you look closely at the diags output, it indicates where each pin should be wired.
Have you verified that each pin reported by diags is wired to the glcd function indicated?
EX:
RW on the glcd should be connected to Arduino pin 35
glcd D0 to Arduino pin 22
glcd EN to Arduino pin 37
etc...

Can you post a few clear closeup pictures of your wiring?

--- bill