KS0108 LCD with Arduino

Hi,

My first post, please accept that i am a rooky in this area.

I was browsing the Arduino home page and found an example on the wiring configuration of a KS0108 LCD.
http://www.arduino.cc/playground/Code/GLCDks0108

I have used a Arduino Diecimila board with the ATmega168 and a KS0108 LCD but no luck.
I have connected all according to the wiring configuration for a pinout B KS01008 LCD.

Data sheet for my KS0108 LCD is:

I am using the code from the arduino example and have no problem to verify and download it to the board.
Still the LCD does not show anything.

Strange thing is that in the arduino wiring example pin 19 should be connected to the resistor that is connected to ground.
But pin 19 is the anode of the LED unit according to the LCD data sheet.
I did change the connection and the LCD light appeared, i can also change the contrast and see all the pixels. But still nothing else when i run the code.

When reading the LCD data sheet i also find that pin 4 (Register select signal) is used and has to be high when reading and writing to the LCD. Why is it not used in this wiring and the code?

The Lcd is a working unit and runs without problems on a parallel port with LCD studio so no problem there.

Could it be that the wiring is only attended for a max 232 Freeduino board?

Is there any simple Arduino code that i could run just to make sure that the connection is working by drawing a pixel or a line.

Thankful for all your help.

Hi HULK,

The D_I (Data/Instruction) pin is incorrectly indicated in the playground as pin 6 for your panel, it should be pin 4. D_I pin is sometimes referred to as RS, as it is on your datasheet.

Please try connecting your LCD pin 4 to the arduino D_I pin, in the posted library code D_I is defined as digital pin 17 (analog pin 3). Let me know if that fixes it and I will alter the playground description to address this. I will also post an updated diagram showing the correct backlight wiring.

Sorry for the trouble, I am sure you will get things working with your board.

Edit: playground diagrams corrected

Hi,

So i have connected the LCD pin 4 to analog pin 3 and still nothing on the LCD.
When i check the LCD pins with a multimeter there seems to be activity on all of the pins.

Any other good thoughts on what could be wrong?

Thanks

If your ks0108.h header file is exactly the same as the one on the playground then double check that the wiring matches the GLCD Panel Pinouts for panel B. I have updated the playground and the diagram should now be correct for your panel.

If you have changed the Arduino pin assignments in the header, check that logical pins are connected correctly. Also, remember that you do need to delete the ks0108.o object file in the library directory before re-compiling your sketch. This is a common cause for problems with an LCD not displaying correctly.

Hi,

I have checked all the connections and thay are all according to the pinout for panel B on the playground example.

I also connected the arduino board direct to a power supply instead of running it on the USB power.
No luck.

I can see a very slight activation of the pixels when uploading a new sketch and when the loading is completed it goes back to normal. Did get left side of the display to light up all the pixels once for a couple of seconds when downloading a sketch, so there is some kind of life .

I have used the sketch from the playground example and the attched example from the library download content, no luck.

Could it be the board that is faulty. Is there a self test software that i can run to check if all is working on the arduino board?

I have not done any changes to the header of the ks0108.h file. Still i have deleted the ks0108.o file to test if that would help after compiling again but no luck.
My header is listed below.

#include <inttypes.h>
#include <wiring.h> // for boolean
#include <avr/pgmspace.h>

#ifndef KS0108_H
#define KS0108_H

//
/
Configuration for assigning LCD bits to Arduino Pins /
/
/
/* Arduino pins used for Commands

  • default assignment uses the first five analog pins
    */
    #ifndef PUBLISH
    #define D_I 14 // D/I Bit
    #define R_W 15 // R/W Bit
    #define EN 16 // EN Bit
    #define CSEL1 18 // CS1 Bit // swap pin assignments with CSEL2 if left/right image is reversed
    #define CSEL2 17 // CS2 Bit
    #else
    // the following is is the distribution version
    #define CSEL1 14 // CS1 Bit // swap pin assignments with CSEL2 if left/right image is reversed
    #define CSEL2 15 // CS2 Bit
    #define R_W 16 // R/W Bit
    #define D_I 17 // D/I Bit
    #define EN 18 // EN Bit
    #endif

/* Arduino pins used for LCD Data

  • un-comment ONE of the following pin options that corresponds to the wiring of data bits 0-3
    */
    #define dataPins8to11 // bits 0-3 assigned to arduino pins 8-11, bits 4-7 assigned to arduino pins 4-7
    //#define dataPins14to17 //bits 0-3 assigned to arduino pins 14-17, bits 4-7 assigned to arduino pins 4-7. (note command pins must be changed)
    //#define dataPins0to3 // bits 0-3 assigned to arduino pins 0-3 , bits 4-7 assigned to arduino pins 4-7, this is marginally the fastest option but its only available on runtime board without hardware rs232.

/* NOTE: all above options assume LCD data bits 4-7 are connected to arduino pins 4-7 /
/
/
/
end of Arduino pin configuration /
/
*/

/* option: uncomment the next line if all command pins are on the same port for slight speed & code size improvement */
//#define LCD_CMD_PORT PORTC // Command Output Register

//#define HD44102 // uncomment this to build a 44102 version

#ifndef dataPins0to3 // this is the only option on standard arduino where all data bits are on same port
#define LCD_DATA_NIBBLES // if this is defined then data i/o is split into two operations
#endif

Mem,

By the way i see that the resistor for the backlight is on the ground side (pin 20 LCD) , should it not be on the positive side (pin 19 LCD).
Check the Playground example and you will se what i mean.
But i could be wrong so ignore this posty if so.

That looks right but to double check
Replace this

/* Arduino pins used for Commands 
 * default assignment uses the first five analog pins 
 */ 
#ifndef PUBLISH 
#define D_I                              14            // D/I Bit  
#define R_W                              15            // R/W Bit 
#define EN                              16[font=monospace][/font]            // EN Bit 
#define CSEL1                        18            // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed 
#define CSEL2                        17            // CS2 Bit 
#else 
// the following is is the distribution version  
#define CSEL1                        14            // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed 
#define CSEL2                        15            // CS2 Bit 
#define R_W                              16            // R/W Bit 
#define D_I                              17            // D/I Bit  
#define EN                              18            // EN Bit 
#endif

With this

// the following is is the distribution version  
#define CSEL1                        14            // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed 
#define CSEL2                        15            // CS2 Bit 
#define R_W                           16            // R/W Bit 
#define D_I                            17            // D/I Bit  
#define EN                              18            // EN Bit

Tomorrow I be able to make some time to reload the code thats on the playground and test it again with my panel.

Mem,

By the way i see that the resistor for the backlight is on the ground side (pin 20 LCD) , should it not be on the positive side (pin 19 LCD).
Check the Playground example and you will se what i mean.
But i could be wrong so ignore this posty if so.

it doesn't matter. its purpose is to limit the current through the LEDs and it makes no difference which side its on (the current through the resistor will be the same either way)

Mem,

Well you did something right, now i have star wars on the LCD. I can not see a clear letter, number or shape but a lot of pixels activated and flashing in random.

could you check that you have the data pins mapped as follows in the header file, just below the part you posted.

It should look like this:

#define dataPins8to11 // bits 0-3 assigned to arduino pins 8-11, bits 4-7 assigned to arduino pins 4-7
//#define dataPins14to17 //bits 0-3 assigned to arduino pins 14-17, bits 4-7 assigned to arduino pins 4-7.
//#define dataPins0to3 // bits 0-3 assigned to arduino pins 0-3 , bits 4-7 assigned to arduino pins 4-7, this is marginally

Mem,

Yes the data pins are mapped according to your post. Check post number 4 and you can actually see that the data pin mapping is attached there.

You may want to try a test sketch that sequences through all pixels on each of the 8 line blocks and see if you can determine anything from the displayed pixel pattern. You may be able to tell if some bits seem to have no affect on the pixels. It's a technique I have used when debugging garbled character displays to track down faulty wiring. In your case it sounds like the wiring is ok but the test may help determine if you have a faulty LCD panel.

Perhaps something like:

for(x=0; x < 128; x++)
for(y = 0; y < 64; y += 8)
GLCD.DrawLine( x, y, x, y+8, BLACK);

for(x=0; x < 128; x++)
for(y = 0; y < 64; y += 8)
GLCD.DrawLine( x, y, x, y+8, WHITE);

A oscilloscope would also help if you have access to one. It could help you verify that signals are actually arriving at the correct pins on the controller chip. I have had to resort to doing that on an LCD panel with non standard wiring.

Mem,

I have made up a simple sketch, attached below. Hopefully it is correct and not totaly rooky made.

#include <ks0108.h>

int x;
int y;

void setup()                   
{
  GLCD.Init(NON_INVERTED);
}

void loop()                     
{
  for(x=0; x < 128; x++) 
  for(y = 0; y < 64; y += 8) 
     GLCD.DrawLine( x, y, x, y+8, BLACK); 
 
  for(x=0; x < 128; x++) 
  for(y = 0; y < 64; y += 8) 
     GLCD.DrawLine( x, y, x, y+8, WHITE);                 
}

After running it you can see vertical lines (8 pixels high) on the LCD going from left to right true to whole LCD.
First the whole LCD will be active then only the right and then blank when the loop is done with 128X64 pixels.

Question is why the LCD is working 100% using the printer port and LCD Studio software.
I will check with another arduino board and then also with another LCD when i find one.
Thanks for your help, if you have any other thoughts they are welcome.

After running it you can see vertical lines (8 pixels high) on the LCD going from left to right true to whole LCD.
First the whole LCD will be active then only the right and then blank when the loop is done with 128X64 pixels.

Could you clarify if you are seeing "vertical lines (8 pixels high) on the LCD going from left to right true to whole LCD" when running that sketch?

I am not clear what you see when you say: "First the whole LCD will be active then only the right and then blank when the loop is done with 128X64 pixels."

Mem,

What i can see is vertical lines moving from left to the right side of the screen. They are 8 pixels high lines and do not move one pixel at a time in the x direction. They can skip one x pixel and can pair in to two or more randomly. Confused, well i would also be if i was reading this, check the picture to see if it gives you a better idea.

http://public.fotki.com/HULK77/ks0108/

So after a while left screen is empty and the right one continues for awhile and then all goes blank

I will try to post a youtube clipp soon as well.

It would help to see a video. I am wondering if only the x axis is wrong (i.e. do all of the 8 pixel lines get drawn in the correct sequence from top to bottom, ignoring the fact that the x location is wrong).

If that is the case then the fauls is probably somewhere in the higher numbered data lines, if not in the connection/configuration then perhaps a fault on the lcd board or controller chip.

Mem,

Well if you think that the pictures where bad the video is even worse.
Ignore the nice THX sound in the bakground ;D
What happend this time is that both left half side and right half side where not active at some point of time not at all as before. Not changed anything and all connections are good, i have checked them several times with my multimeter. This should only be a faulty arduino board or somethimg wrong in the time coding.
But i could be wrong, i have been before...

Same LCD with running on LCD Studio true the parallel port, 10 minutes ago.

One thing we could try is to slow everything down to see if there is a pattern to what is happening.

If you uncomment the following line in the ks0108.cpp file it will slow everthing down to a crawl and you can see each pixel being written

//#define GLCD_DEBUG // uncomment this if you want to slow down drawing to see how pixels are set

Remember to delete the ks0108.0 file in the library directory before you recompile your sketch.

If no pattern emerges then perhaps the data is being written too quickly, although the datasheet you posted indicates that the 450ns delay should be enough. The debug code above changes the time between writes, not the delay within a write so that may be the next thing to try. Do you know how long the delay is on the enable pulse in the code that works?

Mem,

Well, now i can see a pattern that allways starts in the same way. You can see that it starts all the way from upper left side and then continues with the right side true all 64 pixels. Then it starts to run true the whole LCD over and over again.
Did try to use the GLCD.ClearScreen() command before the loop but no luck, also included the command in the loop and still no luck.

#include <ks0108.h>

int x;
int y;

void setup()                   
{
  GLCD.Init(NON_INVERTED); 
}

void loop()                     
{
  GLCD.ClearScreen();

  for(x=0; x < 128; x++) 
  for(y = 0; y < 64; y += 8) 
     GLCD.DrawLine( x, y, x, y+8, BLACK); 
 
  for(x=0; x < 128; x++) 
  for(y = 0; y < 64; y += 8) 
     GLCD.DrawLine( x, y, x, y+8, WHITE);                 
}

What is the next step?

Was looking at a schematic pruposal from the distrubitor. According to distrubitor this should improve the signal quallity on the controll pins CSEL1, CSEL2 and D_I. What do you think?