Graphic LCD (KS0108) library now available

Here is the link to the Arduino playground page for a library that supports graphic LCDs directly attached to an Arduino using a parallel interface. It works with panels using the KS0108 controller chip or equivalent. It can also be compiled to drive the Hitachi HD44102 GLCD chip.

The KS0108 interface uses eight bit data bits and also needs 5 command pins, so this library is only practical if you are not using lots of pins for other things.

The playground article has a functional overview and describes how to wire up and control a Graphics LCD panel from an Arduino sketch. Please post in this thread any questions on the library and its use and documentation.

Have fun!

Nice. I linked to it from the libraries page.

analog and digital clock using the GLCD library

Hi mem,
Nice work! I looked for a list of KS0108 equivalents but couldn't find one. Do you know if the Epson SED1335F is compatible?

I looked for a list of KS0108 equivalents but couldn't find one. Do you know if the Epson SED1335F is compatible?

Hi Digger, the SED chip seems to be quite different. The KS0108 has internal memory support on the chip, the SED1335 uses external memory and has built in text support. I would think a panel using the SED1335 is unlikely to be compatible, but if you have a datasheet for a specific SED1335 panel that describes the interface, we can see just how different they are.

Here is the datasheet for the specific LCD I have:

http://www.glyn.de/data/glyn/media/doc/G121CxxP00C.pdf

Thanks.

Hi Digger, that's quite different from the KS0108. The commands and architecture looks sufficiently different that I think much of the low level access would have to be rewritten. I could try to help you do this if you are up for it, but it won't be easy if you have not done this kind of interfacing before.

Perhaps someone else here has some experience with the SED1335F chip that can help.

Hello i am new to Arduino i make an Adilson's serial Arduino with Atmega 8 mcu i am using the KS0108 library but i cant get any result in LCD. Did it work only Atmega168 board or not. If i try to upload sketch with LCD connected i get an error message. If i remove the LCD from the board it uploads the sketch but no result.

Thanks and sorry for my bad english :slight_smile: .

Hello i am new to Arduino i make an Adilson's serial Arduino with Atmega 8 mcu i am using the KS0108 library but i cant get any result in LCD. Did it work only Atmega168 board or not. If i try to upload sketch with LCD connected i get an error message. If i remove the LCD from the board it uploads the sketch but no result.

A problem with uploading only when the LCD panel is connected is most likely due to either incorrect wiring or a short circuit in the wiring or board. This could also prevent the LCD from displaying anything when running a sketch.

Double check all the connections to the LCD panel to ensure they are the same as the diagram in the playground.

Check there are no short circuited wires in the LCD connections. Also check that there is not a short circuit on your board. Check the trace that runs from digital pin 11 to the ICSP pin, it goes near the serial connections (pins 0 and 1) and if its touching it could cause your symptoms.

I don't think its an ATmega8 issue, I have not tested with one but would expect it would work.

Let me know if these tips solved your problem.

For now I just ordered an LCD with the KS0108 chip :slight_smile: Down the road I may tackle it. I know there are a couple programs on the pc that support both chips over the parallel port. I may be able to gain some insight from their code.

Hi Digger, let me know how you get on with the new chip.

And if you find some source code that supports both chips, please post a link, it will be interesting to see similar or different the read/write routines need to be.

Haven't had much time to look into this further, but I did find some code for the serialwombat that should provide some insight. If you want to take a look it can be found here: http://www.serialwombat.com/sdk/sdk_lcd101.htm

I've tried this on a graphic LCD I got from here: Blue Graphic LCD Display 128x64 Technical Data with no luck.

It's a "B" style pinout, and although the LCD lights up and I get contrast adjustment, I get no actual graphics from the Arduino. I do get a slight flicker running down the screen with a medium contrast, but that's it.

I've triple checked the wiring - the only thing I'm not sure of is the resistor to the backlight, but it's 180 Ohm (in the middle of the range given), and I can't see how that would affect data. Any clues?

I'm using a diecimila with Arduino v0010.

Thanks!

jai.
.

I've tried this on a graphic LCD I got from here: Blue Graphic LCD Display 128x64 Technical Data with no luck.

It's a "B" style pinout, and although the LCD lights up and I get contrast adjustment, I get no actual graphics from the Arduino. I do get a slight flicker running down the screen with a medium contrast, but that's it.

I've triple checked the wiring - the only thing I'm not sure of is the resistor to the backlight, but it's 180 Ohm (in the middle of the range given), and I can't see how that would affect data. Any clues?

I'm using a diecimila with Arduino v0010.

Thanks!

jai.
.

Hi jai,

Try adding the following line to the ks0108.h file
#define PUBLISH

Just before the line
#ifndef PUBLISH

delete the ks0108.o file and recompile your sketch.

I've tried this on a graphic LCD I got from here: Blue Graphic LCD Display 128x64 Technical Data with no luck.
...

Hi jai,

Try adding the following line to the ks0108.h file
#define PUBLISH

Just before the line
#ifndef PUBLISH

delete the ks0108.o file and recompile your sketch.

Brilliant, works a charm, thank you very much. Did I miss something in the playground how-to, or is that undocumented?

jai.
.

Brilliant, works a charm, thank you very much. Did I miss something in the playground how-to, or is that undocumented?

jai.
.

It's not documented, I will update the the header file in the playground. Thanks for letting me know.

edit: the playground download file has been updated so there is no longer any need to #define PUBLISH

Brilliant, works a charm, thank you very much. Did I miss something in the playground how-to, or is that undocumented?

jai.
.

It's not documented, I will update the the header file in the playground. Thanks for letting me know.

You're very welcome. Thank you very much for writing the library, and making it available.

jai.
.

Welcome back Mem,

Remember that i had some problems with a type B pinout KS0108, could this solve the problem?
Are there anyways yet to use this library to display decimal numbers like 3.14 ?

Welcome back Mem,

Remember that i had some problems with a type B pinout KS0108, could this solve the problem?
Are there anyways yet to use this library to display decimal numbers like 3.14 ?

Hi, good to be back :wink:

Its worth trying to compile using the header file I uploaded to the playground yesterday (the cpp file is not changed).

Here is as sketch that shows how to print floating point to the GLCD.

/*
 * GLCDprint
 *
 * Basic print function test code for the Arduino KS0108 GLCD library.
 */

#include <ks0108.h>
#include <Arial14.h>  // font definitions 

#define txtTopLine   2  
#define txtBottomLine   48


void printDouble( double val, byte precision){
  // prints val with number of decimal places determine by precision
  // precision is a number from 0 to 6 indicating the desired decimial places
  // example: printDouble( 3.1415, 2); // prints 3.14 (two decimal places)

  GLCD.PrintNumber( (long)val);  //prints the int part
  if( precision > 0) {
    GLCD.PutChar('.');
    unsigned long frac;
    unsigned long mult = 1;
    byte padding = precision -1;
    while(precision--)
       mult *=10;
       
    if(val >= 0)
      frac = (val - int(val)) * mult;
    else
      frac = (int(val)- val ) * mult;
    unsigned long frac1 = frac;
    while( frac1 /= 10 )
      padding--;
    while(  padding--)
      GLCD.PutChar('0');
    GLCD.PrintNumber(frac) ;
  }
}

float drawSine(int angle){
  float sine;
//    if(angle <= 0)   
        sine = sin(PI / 180 * angle);
  return sine;      
        
}

void setup(){
  GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
  GLCD.SelectFont(Arial_14); // you can also make your own fonts, see playground for details  
}

unsigned long startMillis;

void  loop(){
  startMillis = millis();
  for( int i = 0; i < 128; i ++){
    float s =  sin(PI / 180 * i * 4) * 16;    
    GLCD.DrawLine(i, 32, i, 32+s,BLACK); 
  } 
 
  GLCD.GotoXY(4,txtBottomLine);         // positon cursor  
  GLCD.Puts("Dur= ");               // print a text string
  float f = (millis() - startMillis) / 1000.0;
  printDouble(f,3);           // print a floating point number with 3 digits of precision
  GLCD.Puts(" secs");         
  delay(2000);
  GLCD.ClearScreen();               // clear the screen  
}

I intend to enhance the GLCD library with a routine that clears the text background but I will wait for arduino version 0012 to be released because I want to use the print class that is planned for that release. Doing that will enable similar print methods in the text and graphic LCD libraries. But for now you need to explicitly clear the area where text is written as per the playground example using FillRect()

Thanks,

Code works fine :slight_smile:
I will try my pinout B lcd when i find it, was looking for it yesterday but no where to be found.
I am anyways busy with my cheap lcd from Ebay, i noticed thet the new header is the same as my modefied so there should not be a diffrence if i try it.