Arduino Forum

Forum 2005-2010 (read only) => Hardware => Interfacing => Topic started by: mem on May 10, 2008, 03:58 pm

Title: Graphic LCD (KS0108) library now available
Post by: mem on May 10, 2008, 03:58 pm
Here is the link to the  Arduino playground page  (http://www.arduino.cc/playground/Code/GLCDks0108)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!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mellis on May 10, 2008, 09:25 pm
Nice.  I linked to it from the libraries page (http://www.arduino.cc/en/Reference/Libraries).
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 11, 2008, 03:17 pm
analog and digital clock using the GLCD library
(http://farm3.static.flickr.com/2380/2483178192_abeac640d3.jpg)
Title: Re: Graphic LCD (KS0108) library now available
Post by: Digger450 on May 12, 2008, 06:11 am
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?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 12, 2008, 09:53 am
Quote
 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.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Digger450 on May 12, 2008, 07:44 pm
Here is the datasheet for the specific LCD I have:

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

Thanks.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 12, 2008, 08:04 pm
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.
Title: Re: Graphic LCD (KS0108) library now available
Post by: kuzgun_38 on May 14, 2008, 02:57 am
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 :) .
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 14, 2008, 09:32 am
Quote
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.

Title: Re: Graphic LCD (KS0108) library now available
Post by: Digger450 on May 15, 2008, 08:45 pm
For now I just ordered an LCD with the KS0108 chip :)  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.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 15, 2008, 09:34 pm
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.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Digger450 on May 27, 2008, 12:42 am
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
Title: Re: Graphic LCD (KS0108) library now available
Post by: tyggerjai on Sep 01, 2008, 12:14 pm
I've tried this on a graphic LCD I got from here: http://futurlec.com/LED/BLUE128X64LCD.shtml 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.
.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 01, 2008, 12:53 pm
Quote
I've tried this on a graphic LCD I got from here: http://futurlec.com/LED/BLUE128X64LCD.shtml 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.
Title: Re: Graphic LCD (KS0108) library now available
Post by: tyggerjai on Sep 01, 2008, 12:58 pm
Quote
Quote
I've tried this on a graphic LCD I got from here: http://futurlec.com/LED/BLUE128X64LCD.shtml 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.
.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 01, 2008, 01:15 pm
Quote


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
Title: Re: Graphic LCD (KS0108) library now available
Post by: tyggerjai on Sep 01, 2008, 01:17 pm
Quote
Quote


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.
.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Sep 02, 2008, 02:17 pm
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 ?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 02, 2008, 03:17 pm
Quote
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  ;)

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.
Code: [Select]

/*
* 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()
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Sep 03, 2008, 10:21 am
Thanks,

Code works fine  :)
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.



Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 03, 2008, 11:32 am
Thanks for the report. Sounds like your other panel will work but I will wait until you actually get it going before adding it to the playground as a tested panel.

Hope you are having fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mbenitob on Sep 23, 2008, 12:24 pm
Hello!
I am developing some electronics for a little sailboat based on arduino diecimilia. I have decided to include a display and use the library for the KS0108.
I have been searching for a display and I have bought the following reference: LCD12864C from ledsee.com
You can find the datasheet searching the reference in the ledsee website
As you can imagine, I have had to change the wiring (hardware) and adapt the interface following the pinout detailed in the datasheet and the article in the Arduino Playground as they did not match.
Everything has worked reasonably well but the text or lines in the display do not look well. Text and Graphics move randomly and the text is hard to read. The example proposed in the library runs but the images are garbled.
I have reviewed the wiring three times.
What may I do to isolate the problem?
Thanks in advance,
Mario.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 23, 2008, 12:43 pm
Hi Mario, sorry to hear you are having trouble.

That's a pin configuration I have not seen before but lets see if we can get it going.

Can you take some pictures that show the problem. It will be easier for me to comment if I can see what is happening on the display. You can't directly post the pictures here but if you can put them on a site like flickr you can add links to the pictures in a post.

Also, did you change the ks0108.h file or did you just wire the pins so it matches the information in the playground?

Edit: My guess is that if you can read the text then your panel is probably wired to the correct pins. But I need to understand more about what  you mean by "Text and Graphics move randomly and the text is hard to read"
Title: Re: Graphic LCD (KS0108) library now available
Post by: mbenitob on Sep 23, 2008, 04:17 pm
Hello Mem,
I have posted a short video in youtube:
http://www.youtube.com/watch?v=MmTjW_n3K4o
I also insert here the code for the sample program.

Code: [Select]
#include <ks0108.h>
#include <Arial14.h>  // font definitions
int n=0;
int m=0;

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  
}

void  loop()
{
 if (n>128)
   {
     n=0;
     m++;
    }
 if (m>64)
 {
   n=0;
   m=0;
  }
 GLCD.ClearScreen();
 GLCD.GotoXY(n,m);  // position cursor  
 GLCD.Puts("Hi Mem!");     // write a string to the current cursor position
 n++;
 delay(100);
}


Thanks,
Mario
Title: Re: Graphic LCD (KS0108) library now available
Post by: mbenitob on Sep 23, 2008, 04:37 pm
In the hardwired connections I just have respected the pins identityes and connect with the corresponding arduino layout.
The only software change in pinout has been to swap the chipselect pins.
Thanks again.
Mario.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 23, 2008, 04:51 pm
Very strange!  Two things come to mind as a possible cause:

1. There is a short (or open) circuit (perhaps intermittent) that is interfering with the signal lines, this could be on the LCD PCB or in the wiring.
2. The LCD is not able to respond  to the timings provided by the library code.


I don't think its timing because the datasheet timings appear to be standard ks0108 values that have worked on other boards. That said, it may be that your board is overly fussy about timing. You can try to slow the library down by adding some extra delay in the delay450ns function in the ks0108.cpp file, but I would be surprised if that fixed it (but happy for you if it did). Don't forget to delete the ks0108.o file after a change:
Code: [Select]


static void delay450ns(void){   // delay 450 nanoseconds
   asm volatile("nop\n\t"
      "nop\n\t"  // add these two more nops to slow things down a little
      "nop\n\t"

            "nop\n\t"
            "nop\n\t"
            "nop\n\t"
            "nop\n\t"
            ::);
}



Not sure what else to suggest, other than have a look a what happens when the pixel rate is slowed right down. You do that by uncommenting the following line in ks0108.cpp

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


You should then see each vertical block of up to 8 pixels being drawn. Perhaps a video of that may tell us more.

You may also want to modify your test so there is a fixed black rectangle somewhere on  the screen so we can see if any of these are erased at random. Try this without clearing the screen on every write ( move your call to clearscreen  in the  if(m> 64) block and change n++ to n = n + 32, change m++ to M + = 12;
Title: Re: Graphic LCD (KS0108) library now available
Post by: mbenitob on Sep 23, 2008, 06:28 pm
...If the number of "nop\n\t" increase your surprise, prepare for this...
To remove all little dots and leave the original example inside the library runing clearly, I have had to add 26. :o
The FPS are 6 and works perfect.
I appreciate very much your help and now I can keep on programming on mi project.
If I can help somehow to add this lcd module in the arduino playground for example, please let me know as I would collaborate gladly. I prefer you to do it after you find an explanation about what has happened with the signals timming in this model.
Thanks for everything,
Mario.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 23, 2008, 07:15 pm
I am very happy you got it going and am surprised that your LCD needs such a long delay. Adding 26 nops makes the delay around 2 microseconds, the spec sheet says it that 450ns should be sufficient.

Anyway, I wonder if you can test some code that I could add to the library that would make it easier to support panels that need a long delay.

Could you comment out all the nops that you added and instead replace the code in the Enable function in ks0108.cpp with the following :  
Code: [Select]
#define XTREME_ENABLE_DELAY  4

__inline__ void ks0108::Enable(void) {  
   fastWriteHigh(EN);      // EN high level width: min. 450ns
     delay450ns();
     fastWriteLow(EN);
#ifdef XTREME_ENABLE_DELAY
     for(volatile uint8_t i=0; i< XTREME_ENABLE_DELAY; i++);  
#else
     delay450ns();
#endif
}


You may need to increase the value of XTREME__ENABLE_DELAY from 4 to 5 or perhaps even 6, but if a value of 8 isnt' enough then I will suggest a slightly different place to add the delay.

Keep me posted.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mbenitob on Sep 24, 2008, 12:22 am
Hello Mem,
I have made the changes in the .c file as you suggested, the delay seems not to be placed in the right position. The text is not working properly again even with the variable set to 10.
I have returned to the previous "26 nops" version.
Tell me what else we can do.
Regards,
Mario.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 24, 2008, 10:13 am
Ok, lets put  the Enable(void) method back the way it was and increase the generic delay. This will do the same things as your added nops but uses less code, and it can be easily enabled or disabled if I put it into the distributed file.
Code: [Select]
#define BIG_DELAY  4   // uncomment this to increase the delay to by a few microseconds

static void delay450ns(void){   // delay 450 nanoseconds
#ifdef BIG_DELAY  
     for(volatile uint8_t i=0; i< BIG_DELAY  ; i++);  
#else
   asm volatile("nop\n\t"
      "nop\n\t"
      "nop\n\t"
      "nop\n\t"                           "nop\n\t"
      ::);
#endif
}

Title: Re: Graphic LCD (KS0108) library now available
Post by: gubgub on Sep 24, 2008, 12:01 pm
First post - so here goes. Firstly many thank mem for a great library - my project would not be possible without this.

I have a very similar problem to Mario_B so thought I would chip in my findings.

I am using a KS0108B based 128x64 lcd from Sure Electronics
(type B pinout ). Bought from ebay - cheap as chips IF it can be made to work OK.

I had to add 48 (yes count them!) nop instructions to get a steady display at which point my FPS count is 5.

Like Mario_B using XTREME_ENABLE_DELAY method did not work even when using large values (e.g. 200)

Using the BIG_DELAY method works a treat and I can decrease BIG_DELAY to 1 - at which point my FPS is 5.

Other thoughts/advice needed-

Is an FPS of 5 likely to impact my project - ie should I look for a better lcd before proceeding?

Could my wiring be too long. I'm running on a solderless breadboard currently and the wires between arduino and lcd are about 5 inches long.

Similar problem (with a different lcd) reported in sparkfun forum

A responder thinks that this might be due to "reflections" and that "terminating with a couple of 50 ohm resistors might help". I can try this out if someone can tell me in detail how to wire this up.

Thanks
(had included links to sparkfun and sure electronics but system wont allow me to post these in first post :-( )
Title: Re: Graphic LCD (KS0108) library now available
Post by: gubgub on Sep 24, 2008, 12:04 pm
If helpful sure electronics spec (minimal )here
http://www.sure-electronics.net/mcu,display/DE-LM112_Ver1.0_EN.pdf

Sparkfun post here
http://forum.sparkfun.com/viewtopic.php?p=54266&sid=8780ce9c9529416bb23df535091842b5
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 24, 2008, 12:33 pm
Hi Rower, thanks for the information. It is possible that very long cable lengths could be an issue,  but I use 5 inch long wires and mine works great,  so I think it unlikely that is the problem.  Anyway, don't use 50 ohm resistors, that will put much too much load on the arduino pins.

I think I may have a CFAG12864B LCD buried away somewhere here, if that is the same as yours I will try it and see if I also need the big delay.

Running with an FPS of 5 is not a problem if your sketch runs fast enough.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 24, 2008, 05:18 pm
I found the GLCD panal I got from Sure electronics a while ago but it's not the same as Rower's (mine is a type 'A'  Crystalfontz panel), so I am no clearer on why some of the type 'B' panels need extra delays.

For those reading this thread looking to decide which panel to get, I think the type 'A' panels (+v on pin 1, data0 on pin4 etc) have been easier to integrate then type 'B' panels.

I wonder if there would be much interest if I offered to supply a full performance ready to run 128x64 GLCD panel that included wired connectors and the little PCB with contrast and backlight resistors

I think I could probably do them for around $20 plus shipping if there was enough interest.  PM me if you want one (don't post here, lets keep this thread to technical discussions)

(http://www.arduino.cc/playground/uploads/Code/ks0108-small.jpg) Arduino not included
Title: Re: Graphic LCD (KS0108) library now available
Post by: mbenitob on Sep 26, 2008, 01:46 pm
Hello Mem,
Your last proposed delay450ns(void) function works overally well but I want to make the following remarks:
-The BIG_DELAY definition can be lowered down to 1 and it still works.
-The frames per second is decreased from 6 to 5 comparing this version with the "26 nops" version. It Seems it can be fine tuned better adding nops.
That is all I have found.
Thanks,
Mario.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 03, 2008, 11:13 pm
Mem,

Found my LCD washing my clothes this week in a pair of pants, lucky i did check my pockets before washing. Allways check your pockets before washing, never know what you can find  ;D .
So after my PopDuino creation today i continued with connecting the LCD.
So i have updated my H-file to this:
Code: [Select]
#define CSEL1                        31            // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed
#define CSEL2                        30            // CS2 Bit
#define R_W                              29            // R/W Bit
#define D_I                              28            // D/I Bit
#define EN                              37            // EN Bit

/* 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.


Using digital pins 0-7 and analog pins 0-4 that are supposed to be pins 31-27. But no luck, wrong pin assignment by me?
http://sanguino.cc/useit
Could it be the sanguino code that is missing nedeed code to complete the task?
http://code.google.com/p/sanguino/downloads/list
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 03, 2008, 11:48 pm
Hi Hulk,

The mapping of pins to ports won't work for pin numbers that are different than the arduino. Also, arduino digital pin numbers are not the same as the chips pin numbers.

When I can find some time I will look at the chip you are using and post some macros for you. But it would be easier of you can connect the LCD using the pins that correspond to the standard arduino pins.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 04, 2008, 08:57 am
Morning Mem,

Was reading your post about the ATMega 644 and the arduino compatibillity.
So i guess i will not be able to change around pins using the existing Atmel ATmega specification?
Or could i use the PC, PD, PB pin indications as referance?
Or should i use ADC0... for analog and T0, T1, AINO, AIN1, ICP, OC1, SS, MOSI for digital.

By the way the updated Ks0108 Library compiles with out problems with my Arduino 0012 software and Windows XP, just having problems viewing the update on the LCD  ;D
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 04, 2008, 09:20 am
Did you try it on the ATMega 644 using the default pins (the pins as defined in the library header file)? If that works then perhaps you could use the extra pins on the chip for your other interfaces. If the standard arduino pins as defined in the header don't work or it's not convenient to use the other pins for your other interfaces, I would question the sanguino folks about the claimed compatibility with the arduino.

If the issue is sanguino compatibility with arduino code, lets move this discussion to another thread where others more experienced in this area can contribute. I don't have an ATMega 644  and have no direct experience with it so am not in a good position to help.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 04, 2008, 10:09 am
Mem,

I did connect the LCD Ks0108 pinout type B to the ATMega 644 as follows:
Digital pins 0-7 and analog pins 0-4 to pins 31-27 and therefore i updated the header to:
Code: [Select]
#define CSEL1                        31            // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed
#define CSEL2                        30            // CS2 Bit
#define R_W                              29            // R/W Bit
#define D_I                              28            // D/I Bit
#define EN                              27            // EN Bit

/* 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


Using digital pins 8-11 would be a problem due to tx and rx being pin 8 and 9.
But what you are saying is that if i try it may work? Should i keep the analog pins 27-31 or use the default 18-15?
So the code should be exactlly:
Code: [Select]
#define CSEL1                        15            // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed
#define CSEL2                        14            // CS2 Bit
#define R_W                           16            // R/W Bit
#define D_I                            17            // D/I Bit  
#define EN                              18            // EN Bit

/* 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.


I think i need to make sure that it is not me that is doing something wrong before posting the sanguino compatibility...
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 04, 2008, 11:05 am
Quote
Using digital pins 8-11 would be a problem due to tx and rx being pin 8 and 9...
I think i need to make sure that it is not me that is doing something wrong before posting the sanguino compatibility...

I think the sanguino guys are much better positioned to answer your question than me, I really have no idea how to map pins on the ATMega 644 chip for use with arduino software.

I hope the following helps you phrase your questions to them:

A specific question is: given that this arduino library uses thirteen of the twenty arduino defined digital pins, eight accessed through direct port io, five through arduino digital pin mappings, should this code work unchanged on the sanguino, if not, where can guidelines be found for running arduino code to the sanguino

This question expressed more generally is:
What are the issues with arduino software (such as different mappings to ports and/or resources) using digital pins 0-19 on the ATmega644, either with digitalWrite or using direct port access?  

As I mentioned above, I think this discussion is better placed in a thread on sanguino and/or ATmega644 compatibility. I will be happy to post any conclusions here that relate to the  GLCD library, but the issue you raise is how to get a chip that claims arduino compatibility working with arduino code, and I think this is an interesting and potentially involved discussion that doesn't belong in a thread dedicated to the Graphics LCD library.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 04, 2008, 07:43 pm
Quote
Quote:
Using digital pins 8-11 would be a problem due to tx and rx being pin 8 and 9...
I think i need to make sure that it is not me that is doing something wrong before posting the sanguino compatibility...
I think the sanguino guys are much better positioned to answer your question than me, I really have no idea how to map pins on the ATMega 644 chip for use with arduino software.

I hope the following helps you phrase your questions to them:

A specific question is: given that this arduino library uses thirteen of the twenty arduino defined digital pins, eight accessed through direct port io, five through arduino digital pin mappings, should this code work unchanged on the sanguino, if not, where can guidelines be found for running arduino code to the sanguino

This question expressed more generally is:
What are the issues with arduino software (such as different mappings to ports and/or resources) using digital pins 0-19 on the ATmega644, either with digitalWrite or using direct port access?  

As I mentioned above, I think this discussion is better placed in a thread on sanguino and/or ATmega644 compatibility. I will be happy to post any conclusions here that relate to the  GLCD library, but the issue you raise is how to get a chip that claims arduino compatibility working with arduino code, and I think this is an interesting and potentially involved discussion that doesn't belong in a thread dedicated to the Graphics LCD library.


Moved this issue to:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1223141170/0#0
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 08, 2008, 01:50 pm

Here is an updated version of the ks0108.cpp file for those that want to play with modifying the timing delays for displays that can't handle the 450ns updates.

I am making some other changes to the library to make it compatible with other chips, like the ATmega644 and will wait until this is completed before updating the playground code. I would appreciate if anyone that has had trouble with slow displays could try this code and see if it fixes the problem.
The delays can be tweeked by changing some constants added at the beginning of the file.
#define DELAY_EN_ON  10  // tweek these two to optimize speed
#define DELAY_EN_OFF 10


#define DELAY_RD_ON   2 // these two probably don't need tweeking for any display
#define DELAY_RD_OFF  2

The values above work on my 'slow' LCD, my fast LCD works with all constants equal to 2

Don't forget you need to delete the .o file before each recompile

There isn't room for the entire file here so I have removed all the methods at the start of the file. You will need to past these back if you want to test this code,
Here is the fragment:
Code: [Select]

// ks0108.cpp fragment

// the following four defines determine delays on the enable pin
// values as below work on my slowest display, my fastest works with all values of 2
// 2 is around 0.5us, 4 = 1us, 8 = 2us 10= 2.5us
#define DELAY_EN_ON  10  // tweek these two to optimize speed
#define DELAY_EN_OFF 10

#define DELAY_RD_ON   2 // these two may not need tweeking for any display
#define DELAY_RD_OFF  2

#include "ks0108.h"
extern "C" {
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <wiring.h> // added 18 Sept 2008 for Arduino release 0012
}

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

// all methods before delay450ns have been removed here to fit the post.
// You need to past these in here from you existing file

/*
static void delay450ns(void){   // delay 450 nanoseconds
asm volatile("nop\n\t"
       "nop\n\t"
       "nop\n\t"
       "nop\n\t"  // todo, remove some nops if clock is less than 16mhz
       "nop\n\t"
       ::);
}
*/
__inline__ void ks0108::Enable(void) {  
 fastWriteHigh(EN);                              // EN high level width min 450 ns
 asm volatile( "ldi  r24, %0 \n\t"
   "subi r24, 0x1 \n\t"
   "and  r24, r24 \n\t"
   "brne .-6      \n\t"
   ::"M" (DELAY_EN_ON) :
 "r24" );
 //      delay450ns();
 fastWriteLow(EN);
 asm volatile( "ldi  r24, %0 \n\t"
   "subi r24, 0x1 \n\t"
   "and  r24, r24 \n\t"
   "brne .-6      \n\t"
   ::"M" (DELAY_EN_OFF) :
 "r24" );
 //      delay450ns();

}

uint8_t ks0108::DoReadData(uint8_t first) {
 uint8_t data;

 lcdDataOut(0x00);
 lcdDataDir(0x00);                              // data port is input

 if(this->Coord.x < CHIP_WIDTH) {
   fastWriteLow(CSEL2);                  // deselect chip 2
   fastWriteHigh(CSEL1);                  // select chip 1
 }
 else if(this->Coord.x >= CHIP_WIDTH) {
   fastWriteLow(CSEL1);                  // deselect chip 1
   fastWriteHigh(CSEL2);                  // select chip 2
 }
 if(this->Coord.x == CHIP_WIDTH && first) {            // chip2 X-address = 0
   this->WriteCommand(LCD_SET_ADD, CHIP2);       // wuff wuff
 }

 fastWriteHigh(D_I);                        // D/I = 1
 fastWriteHigh(R_W);                        // R/W = 1

 fastWriteHigh(EN);                   // EN high level width: min. 450ns
 asm volatile( "ldi  r24, %0 \n\t"
   "subi r24, 0x1 \n\t"
   "and  r24, r24 \n\t"
   "brne .-6      \n\t"
   ::"M" (DELAY_RD_ON) :
 "r24" );
 //      delay450ns();
#ifdef LCD_DATA_NIBBLES
 data = (LCD_DATA_IN_LOW & 0x0F) | (LCD_DATA_IN_HIGH & 0xF0);
#else
 data = LCD_DATA_IN_LOW;                     // low and high nibbles on same port so read all 8 bits at once
#endif

 fastWriteLow(EN);
 asm volatile( "ldi  r24, %0 \n\t"
   "subi r24, 0x1 \n\t"
   "and  r24, r24 \n\t"
   "brne .-6      \n\t"
   ::"M" (DELAY_RD_OFF) :
 "r24" );
 //      delay450ns();

 lcdDataDir(0xFF);

 this->GotoXY(this->Coord.x, this->Coord.y);

 if(this->Inverted)
   data = ~data;
 return data;
}

inline uint8_t ks0108::ReadData(void) {  
 this->DoReadData(1);                  // dummy read
 return this->DoReadData(0);            // "real" read
}

void ks0108::WriteCommand(uint8_t cmd, uint8_t chip) {
 if(chip == CHIP1) {
   fastWriteLow(CSEL2);            // deselect chip 2
   fastWriteHigh(CSEL1);            // select chip 1
 }
 else if(chip == CHIP2) {
   fastWriteLow(CSEL1);            // deselect chip 1
   fastWriteHigh(CSEL2);            // select chip 2
 }
 fastWriteLow(D_I);                  // D/I = 0
 fastWriteLow(R_W);                  // R/W = 0      

 lcdDataDir(0xFF);
 lcdDataOut(cmd);
 this->Enable();                  // enable
 lcdDataOut(0x00);
}

void ks0108::WriteData(uint8_t data) {
 uint8_t displayData, yOffset;
#ifdef LCD_CMD_PORT      
 uint8_t cmdPort;      
#endif

#ifdef GLCD_DEBUG
 volatile uint16_t i;
 for(i=0; i<5000; i++);
#endif

 if(this->Coord.x >= DISPLAY_WIDTH)
   return;

 if(this->Coord.x < CHIP_WIDTH) {
   fastWriteLow(CSEL2);                  // deselect chip 2
   fastWriteHigh(CSEL1);                  // select chip 1
 }
 else {
   fastWriteLow(CSEL1);                  // deselect chip 1
   fastWriteHigh(CSEL2);                  // select chip 2
 }

 fastWriteHigh(D_I);                              // D/I = 1
 fastWriteLow(R_W);                          // R/W = 0      
 lcdDataDir(0xFF);                              // data port is output


 yOffset = this->Coord.y%8;
 if(yOffset != 0) {
   // first page
#ifdef LCD_CMD_PORT
   cmdPort = LCD_CMD_PORT;                                    // save command port
#endif
   displayData = this->ReadData();
#ifdef LCD_CMD_PORT             
   LCD_CMD_PORT = cmdPort;                                    // restore command port
#else
   fastWriteHigh(D_I);                              // D/I = 1
   fastWriteLow(R_W);                              // R/W = 0
   if(this->Coord.x < CHIP_WIDTH) {
     fastWriteLow(CSEL2);                  // deselect chip 2
     fastWriteHigh(CSEL1);                  // select chip 1
   }
   else {
     fastWriteLow(CSEL1);                  // deselect chip 1
     fastWriteHigh(CSEL2);                  // select chip 2
   }
#endif
   lcdDataDir(0xFF);                                    // data port is output

   displayData |= data << yOffset;
   if(this->Inverted)
     displayData = ~displayData;
   lcdDataOut( displayData);                              // write data
   this->Enable();                                                // enable

     // second page
   this->GotoXY(this->Coord.x, this->Coord.y+8);

   displayData = this->ReadData();

#ifdef LCD_CMD_PORT             
   LCD_CMD_PORT = cmdPort;                                    // restore command port
#else            
   fastWriteHigh(D_I);                              // D/I = 1
   fastWriteLow(R_W);                               // R/W = 0      
   if(this->Coord.x < CHIP_WIDTH) {
     fastWriteLow(CSEL2);                  // deselect chip 2
     fastWriteHigh(CSEL1);                  // select chip 1
   }
   else {
     fastWriteLow(CSEL1);                  // deselect chip 1
     fastWriteHigh(CSEL2);                  // select chip 2
   }
#endif
   lcdDataDir(0xFF);                        // data port is output

   displayData |= data >> (8-yOffset);
   if(this->Inverted)
     displayData = ~displayData;
   lcdDataOut(displayData);            // write data
   this->Enable();                              // enable

     this->GotoXY(this->Coord.x+1, this->Coord.y-8);
 }
 else {
   if(this->Inverted)
     data = ~data;
   lcdDataOut(data);                        // write data
   this->Enable();                              // enable
   this->Coord.x++;
 }
 lcdDataOut(0x00);
}

// class wrapper

ks0108::ks0108(){
 this->Inverted=0;
}

// Make one instance for the user
ks0108 GLCD = ks0108();
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 09, 2008, 12:54 pm
Mem,

I will check during the weekend and give you feedback.

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 09, 2008, 02:48 pm
Hi Hulk, I look forward to hearing about your results.

I wonder if Mario and Rower are still around to give this a try?
Title: Re: Graphic LCD (KS0108) library now available
Post by: bplturner on Oct 10, 2008, 12:57 am
Hmm
Title: Re: Graphic LCD (KS0108) library now available
Post by: seratechi on Oct 10, 2008, 01:44 am
Got some supply of KS0108 LCDs, check them out if they would be helpful: http://www.seeedstudio.com/depot/parts-lcd-c-32_8.html
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Oct 15, 2008, 10:31 pm
Hi!
I downloaded the KS0108 library and it works like a charm with my type B 'ATM12864D' LCD.
Thanks for the good work on converting it to be Arduino friendly :-)

After looking at the code of the library I discovered that in many of the functions there is a call to a function ReadData(). This function is also used in the WriteData() function.
What data arrives from the LCD and why is it needed?
Is this data vital to be able to send the correct commands to the LCD or would it be possible to use a one way communication (meaning never read from LCD, only send to it)?
\Frisken
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 16, 2008, 04:05 am
Hi Frisken, good question, here is the answer.

Each write to the lcd  affects 8 pixels. But when setting a specific pixel, the state of the other 7 pixels need to be known so that the value of the unchanged pixels can be re-written. That's what the read is for, there  isn't enough RAM on the Arduino to store the state of the entire display.  
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Oct 17, 2008, 09:54 am
Ok, I see.
Theoretically if I clear the LCD before each update and never write the same 8 pixels area twice it should be possible to update the LCD without reading from it.
Is the 8 pixels vertically or horizontally added to the display area?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 17, 2008, 12:15 pm
Frisken,
The data is written in vertical blocks of 8 pixels. If you only ever write to any of the 8 adjacent pixels once, then you don't need to read the LCD data.

The actual architecture of the LCD controller uses the concept of vertical pages, a 64 pixel high panel has 8 pages. Vertical pixels 0-7 are on page zero, pixels 8-15 page one etc. So again, if you only write once per page to a specific x address then you don't need to read the data.

Hope that helps.

I am curious to know what your application is?
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Oct 17, 2008, 02:41 pm
Hehe, well there is not much of an application yet (almost only your library code and a small testapp). I am thinking on using a 74HC595 IC for sending the data to the LCD.
This will save 5 pins on the arduino hence the 595 IC only needs 3 pins to send 8 bit parallel but it can not receive any data.
I will only present text and numbers on the display and therefore I don't think that I will need to write the same 8 bit part more then one time for each update.

The project is to control the cooling fans in the computer depending on the heat to make it as quiet as possible. I got the idée from a friend that used the arduino in another project of his. It seemed to be easy to use and a lot of projects were already available on the net.
It would be nice with a GLCD to show values and to manually change some fan and heat limits.

I started with the GLCD because it seemed like it would be the most difficult part in the project.
\Frisken
Title: Re: Graphic LCD (KS0108) library now available
Post by: walterr on Oct 21, 2008, 04:23 am
Due to a shipping error I now own a graphic LCD, but it doesn't look like the right kind to use with the Arduino.

http://www.topwaydisplay.com/Pub/Manual/LM6063AFW-Manual-Rev0.1.pdf

I think I could deal with the 3.3v power, but the different controller is probably a deal killer.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 21, 2008, 11:41 am
Quote
Due to a shipping error I now own a graphic LCD, but it doesn't look like the right kind to use with the Arduino.


It won't work with the KS0108 library but you may be able to get it to work if you can find some AVR code for your controller, try a search on the controller: ST7565 or ST7565R

Good luck!
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 23, 2008, 10:39 pm
Mem,

I have tested my new KS0108 LCD from Seeedstudio and can say that it works good with the Library.
So you could add it as a tested unit in the playground area.
I am not really sure what the brand is but i think Eric at seeedstudio could provide us with an seeedstudio artical number that can be used or point out the product name.
Could it be called the bluemoon lcd ?
Datasheet i have is found here: http://www.bluemoon-lcd.com/english/pdf/G12864C.pdf

I am runnig the following setup for smooth displaying:
#define DELAY_EN_ON  0  
#define DELAY_EN_OFF 15

My other one from http://www.fractronics.com/12864b_full.pdf had to be set as you know to as slow as:
#define DELAY_EN_ON  0  
#define DELAY_EN_OFF 27

Eric, at what settings did you manage to run the same lcd before shipping to me?

The green one from ebay that we have Mem is running at:
#define DELAY_EN_ON  4
#define DELAY_EN_OFF 6
I do ask my self why the above two have to be slowed down to a big enable off value but not on the enable on value.

Maybe something that will be solved when and if there will be an automized set up of speed in your library?

Title: Re: Graphic LCD (KS0108) library now available
Post by: seratechi on Oct 24, 2008, 04:09 am
HULK - It's the right datasheet you have found.

While we test the LCD, it's not displaying good for the spinning lines. I didn't change the settings, but added delays as discussed in some posts here until we see it work fine. FPS=6

Thanks for the review:)
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 24, 2008, 06:14 pm
Intresting.
After some more testing i got the lcd to work with following settings:
FPS = 2
#define DELAY_EN_ON  15
#define DELAY_EN_OFF 0

FPS = 2
#define DELAY_EN_ON  0  
#define DELAY_EN_OFF 15

FPS = 1
#define DELAY_EN_ON  0  
#define DELAY_EN_OFF 0

Strange thing is that this was tested by seeedstudio but with ATMega 168 i assume and FPS was 6.
I will do some more testing with my ATMega644 and maybe also connect it to a ATMega 168 to check.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Oct 24, 2008, 06:33 pm
hmmm, could it be the ports that i am using
//bits 0-7 assigned to sanguino pins 0-7
Title: Re: Graphic LCD (KS0108) library now available
Post by: Argo on Nov 01, 2008, 07:18 am
Hello all,
Just wondering if anyone has tested or gotten to work the Graphic LCD from Sparkfun.
part # LCD-00710

My GLCD has garble even though I checked every connection at least 4x and followed the KS0108 Graphics LCD library page carefully.  
I'm using the example code given on the Arduino library page.

thanks...
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Nov 01, 2008, 09:23 am
Argo,

If this is a KS0108 panel i am sure you will get to work.

Have you tested to add more "nop\n\t" to the ks0108.cpp file, any diffrence?

I had some trouble with one of my panels as you can read in this thread and in the end i got it working using a new updated KS0108 library.
If you wait for couple of days i am sure that mem will realese this updated version so it can be downloaded and used.
He is working on it right now and have improved it so it will adjust according to your panel hardware speed.

But then i am not the one to say what mem will do and not   :) .
I am sure he will jump in this thread soon and give us all more news on the updated version.

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 01, 2008, 09:51 am
Hi Argo,

If your panel is wired correctly then the most likely cause of garbled display is that its being driven too quickly.  You can add delays into the library (there is information here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210427907/42#42) but it is not easy to do if you are not an experienced programmer.

As hulk says, I am working on a new version of the library that adapts to the speed of the panel that should  get you going. I expect to have a version you could try in the next few  days, I will post here when it is available.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Argo on Nov 01, 2008, 01:33 pm
thanks for the quick replies.  I'll follow the suggested link post ( lcd driven to quickly...) and also be on the look out for the updated library.

thanks again, :)

Title: Re: Graphic LCD (KS0108) library now available
Post by: Argo on Nov 01, 2008, 02:37 pm
Hello all,
Interesting find.  I had to add about 46  "nop\n\t" to the ks0108.cpp file for it to finally work.  thanks for the solution and still will download your latest update mem.  

The GLCD I bought is from sparkfun.  http://www.sparkfun.com/commerce/product_info.php?products_id=710

thanks again.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Nov 02, 2008, 06:20 pm
I wanted to get the GLCD to work with the 74HC595 to be able to save 5 pins on the arduino. To test this fast I just did a fask hack to try if it was possible to do.
The answer to that is that it is possible. The big loss with this is that it is not possible read from the GLCD and therefor if you write to the same area more then one time with different data only the last data will show.
For me that has not been a big problen because I mostly present text in the display and I use a font with fixed width. Therefor all the old characters are coverd with the new ones if the same amount of characters are used.

If someone is interested in how I did this fast hack here is the answer.
This is what I did in the ks0108.h file:
1.      I defined the pins needed for the 74HC595 to work.
Code: [Select]

#define DataPin      2
#define ClockPin      3
#define LatchPin      4


2.      I added the ShiftOut macro from MartinFick that he posted in the thread "Arduino Forum ? Software ? Bugs & Suggestions ? Higher Performance IO".
Code: [Select]

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#define sbipin(pin) sbi((pin)<8 ? PORTD:PORTB, (pin) - ((pin)<8 ? 0:8))
#define cbipin(pin) cbi((pin)<8 ? PORTD:PORTB, (pin) - ((pin)<8 ? 0:8))

#define bitWrite(pin, val) { \
 if ((val) == LOW) cbipin(pin); \
 else              sbipin(pin); \
}

#define shiftOutBit(dataPin, clockPin, val, bit) { \
 bitWrite(dataPin, ((val) & (1 << (bit))) ? HIGH:LOW); \
 bitWrite(clockPin, HIGH); \
 bitWrite(clockPin, LOW); \
}

#define shiftOutByte(dataPin, clockPin, bitOrder, val) { \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?0:7); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?1:6); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?2:5); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?3:4); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?4:3); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?5:2); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?6:1); \
 shiftOutBit(dataPin, clockPin, val, (bitOrder) == LSBFIRST ?7:0); \
}

3.      In the private section I added a new function.
Code: [Select]

void lcdDataShiftOut(uint8_t data);


In the ks0108.cpp file I did these changes:
1.      All the lines that uses the ReadData() function I changed to a fake readout with 0. This is because it's no longer possible to read from the GLCD.
e.g. "data = this->ReadData();" became
data = 0x00; //this->ReadData();
2.      In the "Init(Boolean invert)" function I added the outputs needed for the 74HC595.
Code: [Select]

pinMode(LatchPin,OUTPUT);
pinMode(DataPin,OUTPUT);
pinMode(ClockPin,OUTPUT);

3.      A shiftout function was added to write to the GLDC using the macros in the .h file.
Code: [Select]

void ks0108::lcdDataShiftOut(uint8_t data)
{
     fastWriteLow(LatchPin);
     shiftOutByte(DataPin, ClockPin, MSBFIRST, data);
     fastWriteHigh(LatchPin);
}

4.      And finally in the "WriteData(uint8_t data)" and "WriteCommand(uint8_t cmd, uint8_t chip)" functions I commented out the use of "lcdDataOut()" macro and replaced it with the "lcdDataShiftOut(uint8_t data)".
e.g. "lcdDataOut(cmd);" was commented out and "lcdDataShiftOut(cmd);" was added.

I hope that someone find this usefull. It works fine with my GLCD (ATM12864D). If I test it with the testcode made by mem I got 12 FPS but it do not look that good in the display because there is not possible to read anything from the GLCD. Do not use the 74HC595 if you tend to use a lot of graphics in the GLCD.
\Frisken
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 02, 2008, 08:51 pm
Firsken, good to hear you have that going with the shift register.  As you say, that solution works well with text.  The next version of the library will contain a 5x7 fixed pitch 'system' font which gives up to  8x20 character text display on a 128x64 panel. The release is taking a little longer than I had expected so FWIW, here is the fixed pitch system font definition for those that want do something similar to you:
Code: [Select]
/*
* System5x7
*
* File Name           : System5x7.h
* Date                : 28 Oct 2008
* Font size in bytes  : 470
* Font width          : 5
* Font height         : 7
* Font first char     : 32
* Font last char      : 127
* Font used chars     : 94
*
* The font data are defined as
*
* struct _FONT_ {
*     uint16_t   font_Size_in_Bytes_over_all_included_Size_it_self;
*     uint8_t    font_Width_in_Pixel_for_fixed_drawing;
*     uint8_t    font_Height_in_Pixel_for_all_characters;
*     unit8_t    font_First_Char;
*     uint8_t    font_Char_Count;
*
*     uint8_t    font_Char_Widths[font_Last_Char - font_First_Char +1];
*                  // for each character the separate width in pixels,
*                  // characters < 128 have an implicit virtual right empty row
*
*     uint8_t    font_data[];
*                  // bit field of all characters
*/

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef SYSTEM5x7_H
#define SYSTEM5x7_H

#define SYSTEM5x7_WIDTH 5
#define SYSTEM5x7_HEIGHT 7

static uint8_t System5x7[] PROGMEM = {
   0x0, 0x0, // size of zero indicates fixed width font, actual length is width * height
   0x05, // width
   0x07, // height
   0x20, // first char
   0x7f, // char count
   
   // Fixed width; char width table not used !!!!
   
   // font data
   0x00, 0x00, 0x00, 0x00, 0x00,// (space)
     0x00, 0x00, 0x5F, 0x00, 0x00,// !
     0x00, 0x07, 0x00, 0x07, 0x00,// "
     0x14, 0x7F, 0x14, 0x7F, 0x14,// #
     0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
     0x23, 0x13, 0x08, 0x64, 0x62,// %
     0x36, 0x49, 0x55, 0x22, 0x50,// &
     0x00, 0x05, 0x03, 0x00, 0x00,// '
     0x00, 0x1C, 0x22, 0x41, 0x00,// (
     0x00, 0x41, 0x22, 0x1C, 0x00,// )
     0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
     0x08, 0x08, 0x3E, 0x08, 0x08,// +
     0x00, 0x50, 0x30, 0x00, 0x00,// ,
     0x08, 0x08, 0x08, 0x08, 0x08,// -
     0x00, 0x60, 0x60, 0x00, 0x00,// .
     0x20, 0x10, 0x08, 0x04, 0x02,// /
     0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
     0x00, 0x42, 0x7F, 0x40, 0x00,// 1
     0x42, 0x61, 0x51, 0x49, 0x46,// 2
     0x21, 0x41, 0x45, 0x4B, 0x31,// 3
     0x18, 0x14, 0x12, 0x7F, 0x10,// 4
     0x27, 0x45, 0x45, 0x45, 0x39,// 5
     0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
     0x01, 0x71, 0x09, 0x05, 0x03,// 7
     0x36, 0x49, 0x49, 0x49, 0x36,// 8
     0x06, 0x49, 0x49, 0x29, 0x1E,// 9
     0x00, 0x36, 0x36, 0x00, 0x00,// :
     0x00, 0x56, 0x36, 0x00, 0x00,// ;
     0x00, 0x08, 0x14, 0x22, 0x41,// <
     0x14, 0x14, 0x14, 0x14, 0x14,// =
     0x41, 0x22, 0x14, 0x08, 0x00,// >
     0x02, 0x01, 0x51, 0x09, 0x06,// ?
     0x32, 0x49, 0x79, 0x41, 0x3E,// @
     0x7E, 0x11, 0x11, 0x11, 0x7E,// A
     0x7F, 0x49, 0x49, 0x49, 0x36,// B
     0x3E, 0x41, 0x41, 0x41, 0x22,// C
     0x7F, 0x41, 0x41, 0x22, 0x1C,// D
     0x7F, 0x49, 0x49, 0x49, 0x41,// E
     0x7F, 0x09, 0x09, 0x01, 0x01,// F
     0x3E, 0x41, 0x41, 0x51, 0x32,// G
     0x7F, 0x08, 0x08, 0x08, 0x7F,// H
     0x00, 0x41, 0x7F, 0x41, 0x00,// I
     0x20, 0x40, 0x41, 0x3F, 0x01,// J
     0x7F, 0x08, 0x14, 0x22, 0x41,// K
     0x7F, 0x40, 0x40, 0x40, 0x40,// L
     0x7F, 0x02, 0x04, 0x02, 0x7F,// M
     0x7F, 0x04, 0x08, 0x10, 0x7F,// N
     0x3E, 0x41, 0x41, 0x41, 0x3E,// O
     0x7F, 0x09, 0x09, 0x09, 0x06,// P
     0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
     0x7F, 0x09, 0x19, 0x29, 0x46,// R
     0x46, 0x49, 0x49, 0x49, 0x31,// S
     0x01, 0x01, 0x7F, 0x01, 0x01,// T
     0x3F, 0x40, 0x40, 0x40, 0x3F,// U
     0x1F, 0x20, 0x40, 0x20, 0x1F,// V
     0x7F, 0x20, 0x18, 0x20, 0x7F,// W
     0x63, 0x14, 0x08, 0x14, 0x63,// X
     0x03, 0x04, 0x78, 0x04, 0x03,// Y
     0x61, 0x51, 0x49, 0x45, 0x43,// Z
     0x00, 0x00, 0x7F, 0x41, 0x41,// [
     0x02, 0x04, 0x08, 0x10, 0x20,// "\"
     0x41, 0x41, 0x7F, 0x00, 0x00,// ]
     0x04, 0x02, 0x01, 0x02, 0x04,// ^
     0x40, 0x40, 0x40, 0x40, 0x40,// _
     0x00, 0x01, 0x02, 0x04, 0x00,// `
     0x20, 0x54, 0x54, 0x54, 0x78,// a
     0x7F, 0x48, 0x44, 0x44, 0x38,// b
     0x38, 0x44, 0x44, 0x44, 0x20,// c
     0x38, 0x44, 0x44, 0x48, 0x7F,// d
     0x38, 0x54, 0x54, 0x54, 0x18,// e
     0x08, 0x7E, 0x09, 0x01, 0x02,// f
     0x08, 0x14, 0x54, 0x54, 0x3C,// g
     0x7F, 0x08, 0x04, 0x04, 0x78,// h
     0x00, 0x44, 0x7D, 0x40, 0x00,// i
     0x20, 0x40, 0x44, 0x3D, 0x00,// j
     0x00, 0x7F, 0x10, 0x28, 0x44,// k
     0x00, 0x41, 0x7F, 0x40, 0x00,// l
     0x7C, 0x04, 0x18, 0x04, 0x78,// m
     0x7C, 0x08, 0x04, 0x04, 0x78,// n
     0x38, 0x44, 0x44, 0x44, 0x38,// o
     0x7C, 0x14, 0x14, 0x14, 0x08,// p
     0x08, 0x14, 0x14, 0x18, 0x7C,// q
     0x7C, 0x08, 0x04, 0x04, 0x08,// r
     0x48, 0x54, 0x54, 0x54, 0x20,// s
     0x04, 0x3F, 0x44, 0x40, 0x20,// t
     0x3C, 0x40, 0x40, 0x20, 0x7C,// u
     0x1C, 0x20, 0x40, 0x20, 0x1C,// v
     0x3C, 0x40, 0x30, 0x40, 0x3C,// w
     0x44, 0x28, 0x10, 0x28, 0x44,// x
     0x0C, 0x50, 0x50, 0x50, 0x3C,// y
     0x44, 0x64, 0x54, 0x4C, 0x44,// z
     0x00, 0x08, 0x36, 0x41, 0x00,// {
     0x00, 0x00, 0x7F, 0x00, 0x00,// |
     0x00, 0x41, 0x36, 0x08, 0x00,// }
     0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
     0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
   
};

#endif

save the above as SystemFont5x7.h.

usage in sketch:
#include <SystemFont5x7.h>
void setup(){
 GLCD.Init(NON_INVERTED);
 GLCD.SelectFont(System5x7);
 GLCD.ClearScreen();
 for(int line=0; line < 64; line+=8){
    GLCD.GotoXY(0, line);  // note that y position should be evenly divisable by 8
 GLCD.Puts("line ");
 GLCD.PutChar(line + '0');
 }
}




Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Nov 03, 2008, 08:00 pm
Thanks for the font mem.

In the library there is a private function called WriteData. Is it private for a reason or can you make it public in the next release?

\Frisken
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 03, 2008, 08:23 pm
Hi Frisken, I was thinking about  adding a method that enables writing of bitmap data to the panel which would be a wrapper around writeData. But if you think having writeData public would be more useful, then I can do that if someone could test it thoroughly.

As you can probably see from looking at the source code, driving this chip is complicated, particularly when data is not written to an even vertical page boundary or if individual pixels need to be set. Alsothe chip requires lots of data contortions because it needs to be read twice to get a single byte of data out, and each double read increments the chips internal address counter which needs to be set back when data is written.  All those GotoXYs in the code should take care of it but it really would need some testing if you were accessing writeData externally.

I am almost ready with a beta copy of the new version, I would be happy if you wanted to test using writeData from a sketch.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Nov 03, 2008, 08:48 pm
I would be happy to try it out for you. Is there any specific combination that you think could be troublesome or are you just interested in random testing?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 03, 2008, 10:03 pm
Anything with complex graphics,  particularly where individual pixels are written that cross over between controller chips (x = 64) would be a good test. Also where pixels and/or lines are drawn across page boundaries (there are eight pages in the controller, each 8 bits high starting from line 0)

A simple but effective test is to copy small monochrome bitmaps to the various locations in the panel using WriteData.

I probably won't have the version ready tonight, I will pm you and Hulk when it is available.
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Nov 04, 2008, 07:52 pm
Anybody know what the maximum cable lenght between the panel and Arduino is?
Are we talking about 30-50cm or just 10cm, at some point the cable lenght has to disturb the signals.

I am sure i can test this myself but hopefully somebody of you have that experience allready  :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: skeo on Nov 07, 2008, 01:46 am
Hey guys. New member and new Arduino user here. I've been seeing the same issues as Argo. I also have an LCD-00710 screen from Sparkfun. It was garbled just as Argo said. I've tried editing the .cpp file with the "nop\n\t" fix that Argo did as well as add the code that mem posted.

Both of these do in fact clear up the screen a bit, but it's still nothing close to what the pic in the tutorial shows.

Let me know what you guys think I should do. Thanks!
Title: Re: Graphic LCD (KS0108) library now available
Post by: skeo on Nov 07, 2008, 01:47 am
The forum wouldn't let me add a link in my first post, so this is what it currently looks like: (http://i38.tinypic.com/1428w12.jpg)

I know it's hard to see. But the circle with the lines from the corner is pretty garbled. In fact it looks like two columns need to be swapped.

Edit: Also note that I'm using twisted pair wire for the data pins. Is this bad?
Title: Re: Graphic LCD (KS0108) library now available
Post by: skeo on Nov 07, 2008, 03:34 am
.. never mind. Turns out that one of my twisted pairs was twisted a little too much (read: hooked up backwards).

All is fixed and I look forward to mem's update!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 07, 2008, 09:21 am
Hi skeo, good to hear you have it going. Yes, I am also looking forward to the update  ;)  Sorry its taken so long but I am testing with lots of different displays and I am still working on code to get the best performance out of some of the slower ones. Progress is slow but steady, hope to have something up real soon now.
Title: Re: Graphic LCD (KS0108) library now available
Post by: tvdbon on Nov 17, 2008, 12:34 pm
Cool, can't wait - I've got a graphical lcd and I want to try and get it working.  :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: Karoly on Nov 18, 2008, 07:31 am
Hello there,

I bought Futurlec BLUE128X64LCD LCD (type B pinout), but I cannot make it work with my Arduino. The backlight is lit up, but there is nothing on the screen. I also cannot adjust the contrast. I've noticed on the Wiki page that the the third leg of the contrast potmeter is connected to the ground. According to the datasheet of Lumex LCM-S12864GSF (another LCD with type B pinout), it should be connected to 5V. Well, I tried in both way (which I probably shouldn't have) but it didn't work anyway. How much voltage should actually be present at pin 18 (Vee)?

Thanks!
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Nov 18, 2008, 09:43 pm
Hi Karoly!
I can only speak for what I did and I connected it to the ground and to pin #3 and #18 on the GLCD as in the picture in the ks0108 playground. I also use the B pinout but the contrast is the same in both pinouts. I had to turn the variable 10K resistor to almost 0 before I got anything on the GLCD. Set it to 0 and very slowly increase the resistance. I discovered that the contrast has to be correct otherwise the GLCD shows nothing.
I do not now how much voltage there should be on pin #18. The measurement I got was 9V. That was a surprise for me because I only have 5V in.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Nov 18, 2008, 10:07 pm
Hello!!
I created a new public function in the ks0108 library that calls the private function WriteData like this.
Code: [Select]

void ks0108::WD(uint8_t data)
{
     WriteData(data);
}

I just wanted to try and add a B/W image of my youngest daughter using this function. Guess what, it works. There is no problems with the border between the two controller chips. I tested it with lines, circles, squares and text both inverted and not, no problem.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Karoly on Nov 19, 2008, 07:03 pm
Thanks for your reply, Frisken! I can only measure 0.5V on pin 18. I guess that is why I can't see anything on the screen. It seems I got a faulty unit or I killed it somehow.  :(
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Nov 21, 2008, 11:01 am
Karoly,
Quote
I can only measure 0.5V on pin 18. I guess that is why I can't see anything on the screen. It seems I got a faulty unit or I killed it somehow.  

I can recommend you to check and recheck the connections according to the B pin out because in my own experience I checked the pin out many times and still some small faults had slipped in.
Title: Re: Graphic LCD (KS0108) library now available
Post by: showup on Jan 03, 2009, 02:15 am
I got a LCD from Ebay with type B pin out. It works with Atmega8 except 2 issues.

1) When the 10th PIN of LCD is connected with the 11th pin of arduino (PB3 of Atmega8) I cont upload the files to Atmega8. If i do i get an error as follows:
----------------------------------------------
avrdude: verification error, first mismatch at byte 0x0000
        0x4c != 0x00
avrdude: verification error; content mismatch

-----------------------------------------------
But when i disconnect the above specified connection the uploading is not a problem at all.

2) I get some extra characters above and below the the actual location of the text. For example if i write "Test" at 20,30 i get T at 20,50 e at 27, 10 something like that.  ::)

Is my LCD is not good or is it Atmega8 specific issue(s).
Thanks.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 03, 2009, 09:23 am
only pins 0 and 1 should affect uploading using the serial port. Connection to pin 11 should not be a problem - check that there is not short circuit on you board that has pin 11 connected to pins 0 or 1.

The extra characters are probably caused by your LCD not reacting fast enough to the signals so its occasionally writing pixels in the wrong place. This seems to be more likely in type B panels. There have been a few suggestions for slowing down the library for these panels that was discussed in earlier posts.
Title: Re: Graphic LCD (KS0108) library now available
Post by: showup on Jan 03, 2009, 01:18 pm
I am not using Arduino board. I am using an Atmega8 in Arduino environment without a bootloader. So, I am using Usbtiny to program via the ICSP Header which uses pin # 17 of Atmega8 (pin 11 of Arduino)...

I will reduce the speed as described previously and try to solve the extra character problem...

Thanks.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 03, 2009, 01:41 pm
Quote
I am using Usbtiny to program via the ICSP Header which uses pin # 17 of Atmega8 (pin 11 of Arduino)...


The easiest thing to fix the upload is to connect the wire to pin 11 so it can be easily disconnected when using ICSP.  But you could also try to re-assign the data pins to avoid pin 11.
If you are not using the uart, you can use the dataPins0to3 #define  in the header so that data is on pins 0-7.  You comment out dataPins8to11 and uncomment dataPins0to3 in ks0108.h. delete the ks0108.o file and rebuild the sketch.
Title: Re: Graphic LCD (KS0108) library now available
Post by: showup on Jan 03, 2009, 04:19 pm
I will try it. Thanks.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 03, 2009, 04:21 pm
Good luck, bear in mind that hardware serial won't work if you use pins 0-3 for data.
Title: Re: Graphic LCD (KS0108) library now available
Post by: santy on Jan 17, 2009, 07:30 pm
Hey Guys..

My first post.. :-)

Thanks for the nice library and instructions. They are awesome.

I got a AZ displays AGM1264F LCD from Tanner Electronics. It works beautifully with the KS0108 lib.

In the LCD spec sheet the power circuit was a bit confusing. I checked out a similar project (a PIC oscilloscope using the same LCD) and copied it. It powered up nicely. :-)  This is the url if anyone needs it :
http://www.semifluid.com/?p=15

I wired the data and control wires according the playground wiki page and it sprang to life...I had to adjust the delay to get it to display properly. I updated the playground wiki page with the model of the LCD.

Awesome job everyone. And special thanks to mem for the lib and the wiki page.

Some pics here:
http://picasaweb.google.com/santy.raghavan/ArduinoGLCD#

Santy
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 17, 2009, 07:57 pm
santy, good to hear you have it going. Thanks for updating the playground with info on that panel.

Have fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: Noob4Life on Apr 04, 2009, 12:03 am
"hardware serial won't work if you use pins 0-3 for data." !!! Does this mean that any open digital pins cannot be used for I/O because they're part of the port setup?  (0-3, 12,13)   :o
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Apr 04, 2009, 12:07 am
"hardware serial won't work if you use pins 0-3 for data.

it means that you should not connect the LCD to pins that are used for the serial port. pins 0-3 can only be used on a board that does not have the serial hardware connected to pins 0 and 1.

I don't understand the rest of your question, what do you want to do?

Title: Re: Graphic LCD (KS0108) library now available
Post by: Noob4Life on Apr 04, 2009, 12:12 am
I was hoping to use the remaining digital pins as inputs for a mock alarm system using switches with pull-up resistors on pins 0-3, maybe 12 &13 too.  I was going to use the display to draw the house perimeter and use text as status updates (secure/alarm).
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Apr 04, 2009, 12:17 am
Any unused digital pin is available for your use, but the GLCD library uses them in blocks of four which is why 0-3 is not available. You are free to use 2-3 or 12-13 for other things.


have fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: krekr on Apr 04, 2009, 12:33 am
Sorry for the bump, first post here etc.
First off: thanks for making my almost-forgotten LCD useful again. Very handy for prototyping products, basic user interfaces etc.

My model is a Crystalfonts CFAG12864B-TMI-V and I was also having trouble with garbled output. The timing was the problem and the "nops"-trick was the solution. I'm now using 37 nop's, giving 6 FPS which is more than enough for my application.

Thanks again for the great library!
Title: Re: Graphic LCD (KS0108) library now available
Post by: Nick_Fury on Apr 12, 2009, 02:59 am
I bought one of the KS0108 LCDs from sparkfun.  To get it working I had to add about 40 "nop\n\t" to delay450ns in the ks0108.cpp file.  My frame rate is somewhere around 6FPS now.

I hope that helps some people.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Noob4Life on May 01, 2009, 08:53 pm
My display from Crystalfontz, CFAG12864ISTITN, works at 6FPS now; though I assumed it was working well --until I now notice that the example output is on opposite sides! So I drew a line from 0,0 to 128,64 which shows that the x axis origin starts in the middle of the screen and then wraps around back to the middle! Does anyone have advice on what to do next or what I've done wrong?
Title: Re: Graphic LCD (KS0108) library now available
Post by: nkcelectronics on May 01, 2009, 10:45 pm
You can invert the CS1 / CS2 pins (chip select 1 and 2).
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 04, 2009, 05:28 pm
The advice given by nkcelectronics is the easiest way to reverse the left an right side of the display.

The troubleshooting page in the playground says:

If Left and Right side of image reversed  > swap CSEL1 and CSEL2 wires (or swap pin assignments in header file)
If you do want to leave the wiring alone and swap the assignments in the ks0108.h header file instead, swap the two pin numbers in the following line, delete the ks0108.o file and rebuild the sketch.
Code: [Select]

#define CSEL1  14      // CS1 Bit   // swap pin assignments with CSEL2 if left/right image is reversed
#define CSEL2  15      // CS2 Bit
Title: Re: Graphic LCD (KS0108) library now available
Post by: anunakin on May 11, 2009, 04:46 am
I bought a TECH12864g Display, and this works very well at 5 FPS, using BIG_DELAY 2, I tried many "nops" and with 45 nops this worked... on same 5 FPS... ok I back to "for(volatile uint8_t i=0; i< BIG_DELAY  ; i++)"  ::) well 5 FPS is better then nothing... thanks all...!  :D ;)

Ah... my LCD has a pinout type "C" not A or B .... order ... and I using a Arduino Nano!
Title: Re: Graphic LCD (KS0108) library now available
Post by: magalu on May 12, 2009, 05:13 am
I have a LED/BLUE128X64LCD from futurlec

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 only a blink and flickering of all the screen from blu to white with a medium contrast, but that's it.

And more : is the Reset is connect no possible to upload schetch,
if is not connect or placed on 5v upload work fine.

I've checked the wiring many times...
But I use an Arduino Mega, anyone have the right pins assignement
for this model ?

;) thnks
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 12, 2009, 12:05 pm
This library uses direct port io to get the best performance and the Mega pin assignments are completely different from the 168/368.

I have not tested the following but you can try these connections:

Data pins - this requires the following changes in ks0108.h:
change
 #define LCD_DATA_HIGH_NBL  D  
To
 #define LCD_DATA_HIGH_NBL  B  

You need to delete the ks0108.o file and rebuild the sketch for this change to take affect

Make the following changes to the data pin wiring:
Connect wire shown connected to pin 8 to Mega pin 53
Connect wire shown connected to pin 9 to Mega pin 52
Connect wire shown connected to pin 10 to Mega pin 51
Connect wire shown connected to pin 11 to Mega pin 50
Connect wire shown connected to pin 4 to Mega pin 10
Connect wire shown connected to pin 5 to Mega pin 11
Connect wire shown connected to pin 6 to Mega pin 12
Connect wire shown connected to pin 7 to Mega pin 13


Control pin wiring: (this part of the header file stays the same, just change the wiring)
CSEL1      (was 14) 37      
CSEL2      (was 15) 36
R_W   (was 16) 35       // R/W Bit
D_I   (was 17) 34       // D/I Bit
EN    (was 18) 33       // EN Bit

I will have no chance to run this myself to test it until the end of the month, if you run into problems and you are sure you have wired it correctly then it may have to wait until I return from my travels

Good luck!
 
Title: Re: Graphic LCD (KS0108) library now available
Post by: magalu on May 13, 2009, 03:03 am
MEM... First Thnks for your time  :)
I have done the modification of the header file and the re wiring.
But cant get any result in LCD.

I use a PinB layout and I don't know if I have understood  the pins mapping changes for the Mega You have suggested.

I have done this following your directions :

function           MyLCDPin      MEGA

+5v                     2              +5
GND                     1                GND
Contrast               3               3
 D0                       7               53
 D1                     8               52
 D2                     9               51
 D3                    10               50
 D4                    11               10
 D5                    12               11
 D6                    13               12
 D7                    14               13
CSEL1              15               37                                            
CSEL2              16               36                                            
Reset              17             Reset
R_W                      5               35                                            
D_I                      4               34                                            
 EN                      6               33                                            
Contr. out                18        Contr.Out                                            
Backlight -5        19         Backlight +5                                 
Backlight -5        20         Backlight -5

Is this the right wiring ?

thnks
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 13, 2009, 03:49 am
that looks ok except for contrast - this does not connect to the mega, it goes to pot.

Type B panels have been much more troublesome than type A, can you test your panel on a standard Arduino to see if it has anything to do with the mega?
Title: Re: Graphic LCD (KS0108) library now available
Post by: magalu on May 14, 2009, 02:04 am
The contrast is connected to the pot, In fact is the only thing that works  hihihihih  ;)

No no way to test Lcd with a normal arduino.

But look at this pic (above the link) I'm asking  why we use pins 33-37
this are marked as Port C 4 to 0 (Analog 12 to 8), without change pins assignement on header file how is possible for arduino to recognize the differences (in the header are 14 to 18) ?

on datasheet  : Port C also serves the functions of special features of the ATmega640/1280/1281/2560/2561 as listed on page 82.

Sorry if my question is stupid but i'm totaly new to all this...


and ever the reset it's stoping the upload to work if connected.

Another question, now we use port B for the data, where all data bits are on same port it's not the case to add something like this  ? :

#ifndef dataPins8to11                     // 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

Anyway, thanks for all your infos, which are very valuable to make me understand better how it works Arduino and LCD


for info from datasheet :

3.3.5 Port C (PC7..PC0)
Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port C output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port C pins are tri-stated when a reset condition becomes active,
even if the clock is not running.

Port C also serves the functions of special features of the ATmega640/1280/1281/2560/2561 as
listed on page 82.



Port F (PF7..PF0)
Port F serves as analog inputs to the A/D Converter.
Port F also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins
can provide internal pull-up resistors (selected for each bit). The Port F output buffers have symmetrical
drive characteristics with both high sink and source capability. As inputs, Port F pins
that are externally pulled low will source current if the pull-up resistors are activated. The Port F
pins are tri-stated when a reset condition becomes active, even if the clock is not running. If the
JTAG interface is enabled, the pull-up resistors on pins PF7(TDI), PF5(TMS), and PF4(TCK) will
be activated even if a reset occurs.
Port F also serves the functions of the JTAG interface.



3.3.12 Port K (PK7..PK0)
Port K serves as analog inputs to the A/D Converter.
Port K is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port K output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port K pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port K pins are tri-stated when a reset condition becomes active,
even if the clock is not running.
Port K also serves the functions of various special features of the ATmega640/1280/2560 as
listed on page 96.


(http://yqezpq.blu.livefilestore.com/y1pa2RXO6b_UQcCxkc7KHWsQZRQlmIMOJ7aYHw-yt-z9x9jT96E4znU5rVXJJQZhLamSy-NFxAQiqhYxRYBCTY8DwYoo6J4l8-B/PIN%20MAPPING%20ARDUINO%20MEGA.jpg)
Title: Re: Graphic LCD (KS0108) library now available
Post by: macvlk on May 15, 2009, 02:40 am
Hello ,

  This is my lcd :

Displaytech      64128C-CC-BC-3LP

   I conected all as you say.I triple checked it and its ok conected.But i can not see nothing in my lcd.I tried to find in the header the ifdef publish in order to ad #PUBLISH but in the header the is no such expresion.Please help me with this.Thanks...
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 15, 2009, 04:16 am
Magalu, I will be 3000 miles from my mega for the next week or so and can't test any of this, but I hope the following clarifies what needs to be done to get it going.

This library bypasses the Arduino digitalWrite abstractions because many thousands of writes are needed each second and using digitalWrite would be too slow.
On the standard Arduino, the library uses ports pins from ports B, C and D. But on the mega, the pins from port D are not available, so the suggestion above uses port B instead of D.

On the Mega, pins for ports B and C have different Arduino numbers. Here is a spreadsheet I used for the mappings in my post : http://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 15, 2009, 04:23 am
macvlk, this is a big thread so there is some obsolete information early in the thread. Reply #15 does say that the #ifdef PUBLISH line is no longer needed and was removed last year.
Is your LCD a type A or type B?  - can you post a link to the datasheet?
Title: Re: Graphic LCD (KS0108) library now available
Post by: magalu on May 15, 2009, 05:08 am
thnks a lot Mem for the spreadsheet ;)

I have understood the port B problem but in the header
in the 0to3 case that is the case all data are on the same port
there is a nibble procedure LCD_DATA_NIBBLES for take care of this.
With your suggestion we use port B for both low and high nibble so
is the same situation of 0to3 case i think.
But i have tried and never change...

In the end may be lcd its not ok in the hardware.
Because the strange thing is : in every test ever same result : only flash.
If there are few pins not in the right place may be the tests
give me differents results not every time the same.
But in the next days i will try again tests in the wait of your return to home and to your mega arduino eheheh.

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 15, 2009, 12:02 pm
The mega does allow all the data lines on a single port and that is a slightly faster way to run the code. But it is not necessary to do that and if it doesn't work using seperate nibbles it won't work with a single byte. But please do double check that the pin mappings I suggested actually do match the spreadsheet.
Title: Re: Graphic LCD (KS0108) library now available
Post by: macvlk on May 15, 2009, 10:17 pm
Hy there ,

   The real problem is solved.It was my fault.I bought a 9v suply today and a 10 k pot.all is solved and work ok.I also had to add about 45 "nop\n\t".So we have another lcd model that works fine with your library.Thanks a lot.Plase add this model to the compatible lcd models :

Displaytech   64128C-CC-BC-3LP  (this is a Blue/White one).
  Thank you very much once again and when i will finish my project i surely post it.(somewhere :))).
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 16, 2009, 12:38 am
macvlk, thanks for the feedback. I would guess you LCD is a type B (from all those delays you needed) but could you confirm which wiring configuration you used.

I look forward to reading more about your project in the exhibition forum when you are ready.
Title: Re: Graphic LCD (KS0108) library now available
Post by: sircastor on May 24, 2009, 08:08 am
Hey, just wanted to say thanks for the library and this thread. VERY helpful in trying to figure out what all was supposed to be going on here.

I'm using the GDM12864H from SparkFun and was thouroughly confused and frustrated with this thing. I'm fairly new to electronics, and the amount of information here was extremely helpful. Thanks!

To reiterate for people who haven't read through or caught all the information here, for this particular module:

1) This is a "Type A" board, and CSEL1 and CSEL2 need to be reversed. This can be done in the header file or (more easily) by swapping the pins. This will make it so the order of horizontal blocks are correct.

2) You need to have ~45 nops in your "delay450ns()" method in the ks0108.cpp file. By nops, we mean the line ' "nop\n\t" ' (including the double quotes). These create a delay in the library that allow your data from the Arduino to sync up with the reader on your screen, so instead of garbled dots, you get readable text and pretty pictures. Mem (the author) is planning on providing a way to adjust this in the future.

Title: Re: Graphic LCD (KS0108) library now available
Post by: magalu on May 25, 2009, 10:57 pm
Hi  MEM,
I have tested my LCD (in troubles with the Arduino Mega) with an arduino DuemilaNove and It was only having trouble with The timing and with the "nops"-trick  (33) all now are ok.

But i need many analog and digital pins for my project
So the Arduino Mega issue is still without solution...
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 25, 2009, 11:05 pm
I am back from my travels and hope to be able to try the GLCD code with the Mega real soon now.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 26, 2009, 03:53 pm
A beta version of the Graphical LCD library that supports the Mega (as well as the ATmega168/328 boards) is available here: http://www.arduino.cc/playground/uploads/Code/GLCD_Library_Beta1_2.zip

This version is more tolerant to slower panels, although they will still need to have some delays. Delays can be added by modifying the panel configuration file. The following is the readme file which contains more info :

To install this library, just place all the files into a subfolder in your
Arduino hardware/libraries directory.

When installed, this library should look like:

Arduino/hardware/libraries/ks0108                                (this library's folder)
Arduino/hardware/libraries/ks0108/ks0108.cpp             (the library implementation file)
Arduino/hardware/libraries/ks0108/ks0108.h                 (the library header file)
Arduino/hardware/libraries/ks0108/ks0108_Panel.h       (the Panel configuration header)
Arduino/hardware/libraries/ks0108/ks0108_Arduino.h   (header used to define pins for Atmega168/328)
Arduino/hardware/libraries/ks0108/ks0108_Mega.h      (header used to define pins for Mega)
Arduino/hardware/libraries/ks0108/ks0108_Sanguino.h (header used to define pins for Sanguino) - untested
Arduino/hardware/libraries/ks0108/SystemFont5x7.h     (definition for 5x7 system fonmt)
Arduino/hardware/libraries/ks0108/Arial14.h                 (the definition for 14 point Arial Font)
Arduino/hardware/libraries/ks0108/keywords.txt           (the syntax coloring file)
Arduino/hardware/libraries/ks0108/examples                 (diectory containing the example test sketch)
Arduino/hardware/libraries/ks0108/readme.txt               (this file)

Building
--------------------------------------------------------------------------------

After the files are copied into your library directory, check the wiring matches the pin configuration
for your board. The default wiring is different for the different chip types:
(see http://www.arduino.cc/playground/Code/GLCDks0108 for more info)

Code: [Select]

ATmega168/328  uses configuration file: ks0108_Arduino.h
LCD           ARDUINO pins
CSEL1            14            // CS1 Bit   // swap with CSEL2 if left/right is reversed
CSEL2            15            // CS2 Bit
R_W            16            // R/W Bit
D_I            17            // D/I Bit
EN            18            // EN Bit

LCD data 0-3       8-11
LCD data 4-7       4-7

Mega (ATmega1280)  uses configuration file: ks0108_Mega.h

CSEL1            33            // CS1 Bit   // swap with CSEL2 if left/right is reversed
CSEL2            34            // CS2 Bit
R_W            35            // R/W Bit
D_I            36            // D/I Bit
EN            37            // EN Bit

LCD data 0-7       22-29


Slow panels may need delays added to the panel panel configuraion file: ks0108_Panel.h
change the number 6 to a higher number to make th delay longer :
#define EN_DELAY_VALUE 6 // this is the delay value that may need to be hand tuned for slow panels

After a successful build of this library, a new file named 'ks0108.o' will appear
in ks0108 library directory. If you make any changes to any of the files in the
ks0108 directory you must delete ks0108.o before recompiling your sketch for the changes to be
recognized by your sketch. The new "Test.o" with your code will appear after the next
verify or compile (If there are no syntax errors in the changed code).

To use the library in a sketch, go to the Sketch | Import Library menu and
select ks0108.  This will add a corresponding line to the top of your sketch:
#include <ks0108.h>. It will also add lines for all the font definitions you have
in the ks0108 library directory. You should remove the includes for any fonts you
don't use in a sketch, they use a lot of program memory.
Title: Re: Graphic LCD (KS0108) library now available
Post by: magalu on May 26, 2009, 11:19 pm
MEM,
your new library for Mega work perfect !!! 8-)
Pins are all ok.  No need any trim... too delay is ok. FPS = 7.

great job, my congratulations.

thnks  :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mvcl on May 28, 2009, 08:03 am
Overall, this beta is really great! My worst problem was finding I had to adjust the lcd contrast.

There is one issue: Using the SparkFun LCD-00710 (GDM12864H layout A) on Arduino Mega, the GLCD.Init draws a funny bunch of pixels in the upper ten rows in the init screen. This garbage is drawn before introScreen() is called. Inserting a call to GLCD.ClearScreen right after GLCD.Init and before introScreen() clears away the bad stuff and shows all the drawing which comes after is perfect. Is there some timing issue to resolve in GLCD.Init?

Thanks for pulling this all together so well.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 28, 2009, 08:33 am
mvcl, thanks for the feedback.
GLCD.init does clear the screen after a 10 millisecond delay but perhaps your panel needs longer.

Could you experiment with some longer delays in the library and report back what works for your panel so I can modify the value in the release version.

In the ks0108.cpp file change the following value at the end of  the  ks0108::Init method:

     delay(10);  <- change this value
     this->ClearScreen();                                          // display clear
     this->GotoXY(0,0);  
}


Don't forget to delete the ks0108.o file .
Title: Re: Graphic LCD (KS0108) library now available
Post by: regomodo on May 28, 2009, 03:37 pm
I'm trying to use the new beta library on my Gentoo box. I've put the necessary files in the correct place but when I start up the IDE i'm getting this error about ks0108


Quote
In file included from ks0108.h:46,
                from ks0108.cpp:36:
ks0108_Panel.h:25:25: error: invalid suffix "B01" on integer constant
ks0108_Panel.h:25:31: error: invalid suffix "B10" on integer constant
ks0108.cpp:781:2: warning: no newline at end of file
o: In function `main':
undefined reference to `GLCD
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 28, 2009, 04:11 pm
regomodo, your system is not finding the arduino core file: binary.h

Binary.h is included by wiring.h (which is included by ks0108.h)


You can do any one of the following  three things to fix this:

1. search to see if you can find any information on fixing Arduino build dependencies in Linux

2. explicitly add #include <binary.h> in ks0108_panel.h

3. in ks0108_panel.h, replace the binary constants with their decimal equivalent:

#if (DISPLAY_WIDTH / CHIP_WIDTH  == 2)
  byte chipSelect[] = {1, 2};        // this is for 128 pixel displays
#elif (DISPLAY_WIDTH / CHIP_WIDTH  == 3)
  //byte chipSelect[] = {0,1, 2};  // this is for 192 pixel displays
  byte chipSelect[] = {0, 2, 1};  // this is for 192 pixel displays on sanguino only


I will probably do the latter in the distribution if that fixes the problem for you.
Title: Re: Graphic LCD (KS0108) library now available
Post by: regomodo on May 28, 2009, 04:32 pm
I've just ran this

Quote
jon@genbox ~/arduino-0015 $ grep -r binary.h ./
./hardware/cores/arduino/wiring.h:#include "binary.h"
./hardware/libraries/Sprite/Sprite.h:#include "binary.h"


Where should it be? In avr-libc?

Added "#include <binary.h>" to the top of ks0108_Panel.h. Still get the same error.

Going from binary to decimal seems to have worked.

[EDIT] Yep , it works but now it runs at 6fps. It'll do.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 28, 2009, 05:08 pm
Binary.h is an Arduino file in the directory where you installed the core software:  hardware/cores/Arduino

Changing the binary constants to decimal will not affect the speed. If it is running differently on your Linux box its probably because you are using a different version of the Arduino compiler.

Anyway, good to hear that it is now working. I will be making the same change in the version I distribute.

Have fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mvcl on May 30, 2009, 01:54 am
As you guessed, indeed, a greater delay makes the display happy.
I changed it from 10 to 11 and it's now perfect.

Cheers,

Quote

GLCD.init does clear the screen after a 10 millisecond delay but perhaps your panel needs longer.

Could you experiment with some longer delays in the library and report back what works for your panel so I can modify the value in the release version.

In the ks0108.cpp file change the following value at the end of  the  ks0108::Init method:

    delay(10);  <- change this value
    this->ClearScreen();                                          // display clear
    this->GotoXY(0,0);  
}
Title: Re: Graphic LCD (KS0108) library now available
Post by: todotani on May 31, 2009, 04:11 pm
Hi mem,

Thank you for new version of ks0108 library!
It works with better performance even with type B panel. With Mega, my type B panel worked fine, and marked 8 PPS with delay = 4.

For more performance tuning, I added frame buffer (FB)  function. As FB consume 1KB of SRAM, it is applicable only for Mega. With modified code, I got 14 FPS with delay = 1 . It marked 12 FPS with delay = 4, so performance increase of FB was 4 FPS.

The followings are codes that I modified.
Code: [Select]

<ks0108.h>
class ks0108  // shell class for ks0108 glcd code
{
 private:
   lcdCoord                  Coord;
   boolean                        Inverted;
   FontCallback          FontRead;
   uint8_t                        FontColor;
   const uint8_t*            Font;
     uint8_t ReadData(void);
     uint8_t DoReadData(uint8_t first);
     void WriteCommand(uint8_t cmd, uint8_t chip);
     void WriteData(uint8_t data); // experts can make this public but the functionality is not documented
     inline void Enable(void);
     inline void SelectChip(uint8_t chip);
     void WaitReady( uint8_t chip);
     //-- Added for Frame Buffer --
     uint8_t vram[DISPLAY_PAGE][DISPLAY_WIDTH];
     //
 public:

<ks0108.cpp>
void ks0108::Init(boolean invert) {  
     pinMode(D_I,OUTPUT);       
   pinMode(R_W,OUTPUT);       
   pinMode(EN,OUTPUT);       
   pinMode(CSEL1,OUTPUT);
   pinMode(CSEL2,OUTPUT);

     delay(10);

     fastWriteLow(D_I);            // I
     fastWriteLow(R_W);            // W
     fastWriteLow(EN);
       lcdDataDir(0xFF);          // Add

     this->Coord.x = 0;
     this->Coord.y = 0;
     this->Coord.page = 0;
     
     this->Inverted = invert;
     
     for(uint8_t chip=0; chip < DISPLAY_WIDTH/CHIP_WIDTH; chip++){
      delay(10);  
        this->WriteCommand(LCD_ON, chip);                        // power on
        this->WriteCommand(LCD_DISP_START, chip);      // display start line = 0
     }

     // -- Addition for Frame Buffer --
     uint8_t i, j;
     for (j = 0; j < DISPLAY_PAGE; j++)
           for (i = 0; i < DISPLAY_WIDTH; i++)
                 vram[j][i] = 0;
     // -- End Addition --

     delay(12);                                                      // Original 10ms -> 12ms
     this->ClearScreen();                                          // display clear
     this->GotoXY(0,0);
}

void ks0108::WaitReady( uint8_t chip){
     // wait until LCD busy bit goes to zero

   SelectChip(chip);
     lcdDataDir(0x00);
     fastWriteLow(D_I);            // I
     fastWriteHigh(R_W);            // Read
     fastWriteHigh(EN);       
   //asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t" ::);
     EN_DELAY();
     while(LCD_DATA_IN_HIGH & LCD_BUSY_FLAG)
           ;
     fastWriteLow(EN);       
     fastWriteLow(R_W);         // Back to W
      lcdDataDir(0xFF);               // Back to port direction Output
}

inline uint8_t ks0108::ReadData(void) {  
     if (!Inverted)
           return vram[Coord.page][Coord.x];
     else
           return ~vram[Coord.page][Coord.x];
}

void ks0108::WriteCommand(uint8_t cmd, uint8_t chip) {
      if(this->Coord.x % CHIP_WIDTH == 0 && chip > 0){             // todo , ignore address 0???
          EN_DELAY();
   }
     this->WaitReady(chip);
     fastWriteLow(D_I);                              // I
//      fastWriteLow(R_W);                              // W
//    lcdDataDir(0xFF);

     EN_DELAY();
   lcdDataOut(cmd);
  this->Enable();                                    // enable
  EN_DELAY();
  EN_DELAY();
//      lcdDataOut(0x00);
}

void ks0108::WriteData(uint8_t data) {
     uint8_t displayData, yOffset, chip;
     //showHex("wrData",data);
//showXY("wr", this->Coord.x,this->Coord.y);

     GotoXY(this->Coord.x, this->Coord.y);
     if(this->Coord.x >= DISPLAY_WIDTH)
           return;
   chip = this->Coord.x/CHIP_WIDTH;
   this->WaitReady(chip);

// if(this->Coord.x % CHIP_WIDTH == 0 && chip > 0){             // todo , ignore address 0???
//       this->GotoXY(this->Coord.x, this->Coord.y);
// }

     fastWriteHigh(D_I);                              // D/I = 1 (Data)
//      fastWriteLow(R_W);                          // R/W = 0 (W)
//      lcdDataDir(0xFF);                              // data port is output
     
     yOffset = this->Coord.y%8;

     if(yOffset != 0) {
           // first page
           displayData = this->ReadData();
           displayData |= data << yOffset;
           if(this->Inverted)
                 displayData = ~displayData;
           lcdDataOut( displayData);                              // write data
           this->Enable();                                                // enable
           // -- Addition for Frame Buffer --
           vram[Coord.page][Coord.x] = displayData;  // Write back vram
           
           // second page
           this->GotoXY(this->Coord.x, this->Coord.y+8);
           displayData = this->ReadData();
           displayData |= data >> (8-yOffset);
           if(this->Inverted)
                 displayData = ~displayData;
           lcdDataOut(displayData);            // write data
           this->Enable();                              // enable
           // -- Addition for Frame Buffer --
           vram[Coord.page][Coord.x] = displayData;
           
//            this->GotoXY(this->Coord.x+1, this->Coord.y-8);
           Coord.x++;
           Coord.y -= 8;
     } else {
           // just this code gets executed if the write is on a single page
           if(this->Inverted)
                 data = ~data;        
       EN_DELAY();
           lcdDataOut(data);                        // write data
           this->Enable();                              // enable
           // -- Addition for Frame Buffer --
           vram[Coord.page][Coord.x] = data;
           this->Coord.x++;
         //showXY("WrData",this->Coord.x, this->Coord.y);
     }
//      lcdDataOut(0x00);
}

//  uint8_t ks0108::DoReadData() was removed

To simplify the code (so as to I can trace), I removed #ifdef block from WriteData() function. So, it works only in Mega which dose not requre nibble mode.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on May 31, 2009, 05:18 pm
hi todotani, good to hear you have it working so well and thanks for posting the code.

Note that the #ifdef block for the mega does not use nibble mode, it reads and writes the full byte. So there would be no performance improvement in making that change.

Using a frame to build the image does result in much faster writes. There is an undocumented function called DrawBitmap in the library which blits a frame from program memory that you may want to look at to see if you can speed up your vram code even more.  
Title: Re: Graphic LCD (KS0108) library now available
Post by: todotani on Jun 01, 2009, 03:43 pm
Hi mem,
Thanks for your reply.

Currently, I'm using vram (frame buffer) as read buffer from GLCD and it can reduce overhead of DoRead() function.
(Due to device limitation, it is required read twice from GLCD with delay of Enable signal)

You mentioned that it is possible to increase performance by using vram as write buffer.  
In write buffer operation, WriteData() function just write to vram. With certain interval, (and may be different function) transfer block of vram to GLCD.
I think it can speed up write operation because of auto-address increment of GLCD.
I'll try this.

Quote

Using a frame to build the image does result in much faster writes. There is an undocumented function called DrawBitmap in the library which blits a frame from program memory that you may want to look at to see if you can speed up your vram code even more.  


Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jun 01, 2009, 04:21 pm
I look forward to seeing your  results. Also, I would be interested to read about your project - perhaps you can post some information in the exhibition area of this forum.
Title: Re: Graphic LCD (KS0108) library now available
Post by: edu986 on Jun 13, 2009, 07:23 am
Hi,
Hi,
I'm from Chile and i have an Arduino Diecimila,
i want to connect a GLCD, i followed the datasheet of my lcd and
i connected it, but i don't have any image o letter in my lcd,
i need help, please.
Title: Re: Graphic LCD (KS0108) library now available
Post by: edu986 on Jun 13, 2009, 07:26 am
Hi,
I'm from Chile and i have an Arduino Diecimila,
i want to connect a GLCD, i followed the datasheet of my lcd and i connected it, but i don't have any image o letter in my lcd,
i need help, please.
this is my lcd:
(http://img268.imageshack.us/img268/7650/s8302385resoluciondeesc.th.jpg) (http://img268.imageshack.us/i/s8302385resoluciondeesc.jpg/)(http://img195.imageshack.us/img195/4258/s8302386resoluciondeesc.th.jpg) (http://img195.imageshack.us/i/s8302386resoluciondeesc.jpg/)
here is the datasheet:
http://www.longtech-display.com/PRODUTS/LCD%20MODULES/longtech%20pdf/LGM12864B.pdf
i only can adjust the contrast, but no image.
i have installed the ks0108 libreries
thanks.

Title: Re: Graphic LCD (KS0108) library now available
Post by: Ran Talbott on Jun 13, 2009, 08:49 am
Well, this thread (http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=46614) on the avrfreaks forum says the S6B0108 controller on your LCD has the same instruction set as the KS0108.  But it also says that the LCD pixels on the display they were trying to get working were connected differently.

So,  if you have everything connected correctly,  you should probably see something on the display,  even if it's garbled.

Have you carefully checked all the connections?

Ran
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jun 13, 2009, 01:16 pm
It looks like that panel uses a completely different pin arrangement than the panels that have been used so far. As Ran says, make sure that you have everything wired up to match the datasheet. Test it with the latest beta code using bigger delay values, see the recent posts in this thread for more about this.  
Title: Re: Graphic LCD (KS0108) library now available
Post by: edu986 on Jun 14, 2009, 07:05 am
hi, thanks for help me.
i'm using the beta version of the librerie, but i'm still having no image in the lcd. i've cheked many times the wiring, its OK, also i've changed the DELAY VALUE in ks0108_panel.h file.
if you have any idea that can help please tell it to me.
bye
Title: Re: Graphic LCD (KS0108) library now available
Post by: mvcl on Jun 14, 2009, 08:09 am
I had some trouble at first with the particular lcd I got (fron Sparkfun). The only issue was the contrast.

Does adjusting your contrast have the expected effect? At one end of its range you get all pixels lit up solid, just back off that a little and the real image will display if it is there.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jun 19, 2009, 03:43 am
I have a question:

I have an LCD that I grabbed out of the trash at work, it has no part numbers, but It has I think 3 Samsung S6B0108A01, is this a cross referenced generic chip that is the same as the one you guys are using? i think it has three, only 2 part numbers are visible, the other has a sticker on it.

The LCD unit has 20 pins, it says EDT on it (Emerging Display Technologies) and the sticker says

EDT
EW13B30GLY
03052*11

I can't find anything on this, maybe someone has a resource they can point me to?
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jun 19, 2009, 03:53 am
Ok, I read up a little and i see the op has a problem as well

does anyone have a pinout? i have no idea where the pins go
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jun 19, 2009, 04:34 am
I am the op and don't have a problem  ;)  did you read the first post in this thread?
If you do you will find a link to a playground article that has the two most common pinouts for panels made using this chip. Perhaps you can trace the connections on your panel to see which one you have.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jun 19, 2009, 11:15 pm
ok, i have a general idea,

my question is that my board has Vcc, Vdd, and V0

I would guess that V0 is GND or -

Vcc is +5v? what's the other one? lol

Im new to all this...Thanks!

which one is the contrast>?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jun 19, 2009, 11:35 pm
Vcc and Vdd are both terms for the positive supply. If you have a multimeter you should check if they are connected together.

Vss or Gnd are the usual terms for ground.

If Vcc is connected to pin 1 and Vo is connected to pin 2 then you have a type A board, if Vcc is connected to pin 2  you have a type B board.

See the playground article linked earlier for the correct wiring for these types.
Title: Re: Graphic LCD (KS0108) library now available
Post by: sircastor on Jun 20, 2009, 06:20 am
I don't mean to be rude Metalfan1185, but did you even try to find any information about this? I Googled your part number and found the full datasheet, including the pinout! First link on the list.

Datasheet direct link for EW13B30GLY:
http://www.datasheetarchive.com/pdf-datasheets/Datasheets-9/DSA-171222.pdf
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jun 21, 2009, 03:22 pm
Actually, I did look for information quite intensively for this LCD because even out of the trash, it was brand new.  I looked for about 3 weeks and couldn't find anything (that wasn't in chinese) so I threw it in a box, and packed it up and moved it to my new apartment, where i found it and decided to give it a second try after finding this thread.

thank you so much, i believe i checked that site, maybe i entered the part number incorrectly.

So another question, I read the thread from the beginning and I dont understand how to tell wether my GLCD is a A pinout or a B one. I suppose it doesn't matter, as long as the corresponding arduino pins go to the correct places.

This has regained my interest.  GLCD's are pretty neat! :)

i hope i can get mine to work!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jun 21, 2009, 03:54 pm
It does matter! You can destroy your LCD panel if you wire it using the diagram in the playground (the picture is for type A only). As the playground article says, you must check if you have a type A or type B panel and wire then appropriately You do this by checking the datasheet interface (it's the diagram on page 8 of your datasheet, did you actually read through the datasheet?). Your Panel is type B so you need to wire it using the playground information for pinout B.

Have fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jun 26, 2009, 05:24 am
OK, I understand now.  so in my case, pin 1 is GND and 2 is +5v.

im going to tinker with this this weekend, im going to try and make use out of this thing ;)
Title: Re: Graphic LCD (KS0108) library now available
Post by: randoma on Jun 28, 2009, 09:34 pm
todotani said:
Quote
For more performance tuning, I added frame buffer (FB)  function. As FB consume 1KB of SRAM, it is applicable only for Mega. With modified code, I got 14 FPS with delay = 1 . It marked 12 FPS with delay = 4, so performance increase of FB was 4 FPS.

The followings are codes that I modified.


Is there any chance you could post the entire .cpp and .h files with your modifications? The code modifications that you posted appear to be incomplete. Of course, it could just be me...
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 01, 2009, 05:33 pm
Ok, I hooked my glcd up, I followed the b pinout and I can make out the sample sketch barely, but its garbled. The circle is all messed up and hardly make out the fps.

I checked the wires like. 5 times and all that, I think I need to slow it down like you guys are saying, but I'm not sure exactly how.

I'm soooo close! Someone help me out?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 01, 2009, 06:24 pm
download the beta version of the library from the playground (the link to the file is after the GLCD pinout table).

If you need to slow it down, in the file ks0108_Panel.h  change:
 #define EN_DELAY_VALUE 6
from 6 to some higher value.

You must delete ks0108.o and recompile the sketch for changes to take affect.


Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 01, 2009, 10:56 pm
I get an error reffering to

GLCD.CursorTo(1,0);

Here is a screen shot of what im lookin at. (btw, i changed the 6 to a 10 and deleted the "o" file)

(http://i108.photobucket.com/albums/n10/Metalfan036/blah.jpg)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 01, 2009, 11:14 pm
are you running the Beta version from the link at the end of the 'Wiring and Configuration' table in the playground?

if you look in the ks0108.cpp file  you should see a comment indicating the version as 1.2 May 26th. If not, download the beta version and that. If you have that verison, make sure you delete the ks0108.o before compiling the sketch.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 02, 2009, 12:18 am
Thanks for working with me on this btw...

Yup, the one i downloaded is the one you say i should have.

I tried it again and i get the same message.

here's what im doing step by step:


**Downloaded Mega code from link DIRECTLY following the pinout table.

navigate to ".h" file located in the ks1080 folder and change the 6 to a 10 on the line you stated earlier.

Open Arduino IDE
Open sketch-> navigate to ks1080 folder -> examples -> GLCDexample.pde (or whatever that example file is called)

While that open dialog box is open, i click on the ks1080.o file just before the examples folder and delete it.

go to arduino IDE, click on "Verify/Compile" and thats where i get the error.

Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 02, 2009, 12:40 am
Ok, I got it now.


All I did was delete everything i had that had to do with the GLCD stuff and started from scratch.

I downloaded the Beta code again, extracted to libraries, deleted the ".o" file, and compiled it and it ran.  That delay value is still at 6, so, i guess that fixed it.

It must have gotten garbled up somewhere...


Anyways, Im using a Arduino Duemilanove with 328 and my display is a

Emerging Display Technologies (EDT)
EW13B30GLY (type B pinout)

Works Great!

thank you for all your hard work. and everyone else too...

now its tinkerin time lol ;D

(http://i108.photobucket.com/albums/n10/Metalfan036/2009-07-01184413.jpg)
Title: Re: Graphic LCD (KS0108) library now available
Post by: todotani on Jul 02, 2009, 05:35 pm
Hi randoma,

Quote
Is there any chance you could post the entire .cpp and .h files with your modifications? The code modifications that you posted appear to be incomplete. Of course, it could just be me...


Here is a link to download entre code.
http://todotani.cocolog-nifty.com/blog/files/ks0108.zip
For your information, this code is optimized for Arduino Maga, and dose not work with other Arduino board like Duemilanove.

Here is other optimization.
http://todotani.cocolog-nifty.com/blog/files/ks0108_wb.zip
In this version, instead to write data to GLCD in each column address, block transfer entire 8 lines when call GLCD.Update() function.
When I call Update() function 5ms interval (equivalent to 24Hz refresh rate), this version can mark 20 FPS.

Here is link to my blog to explain above modifications. Sorry it written in  Japanese only, but you may find what I'm writing with machine translation.
http://todotani.cocolog-nifty.com/blog/2009/06/post-7442.html
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 02, 2009, 06:06 pm
I have just updated  the playground with Releae 2 of the library : http://www.arduino.cc/playground/Code/GLCDks0108.

This is a release version of the Beta code that has been on the site for the last month or so.

This version makes it easier to integrate slower panels, supports the Mega and Sanguino boards, and has the following new features:
- Supports fixed width fonts that provides up to 8 x 21 character display with the supplied system font.
- CursorTo method to position the cursor to a given font location (fixed width fonts only)
- DrawBitmap function to display bitmap images stored in Flash memory. A Processing utility is provided in the download to convert a monochrome bitmap file to a header file automatically stores the image in flash for use by the DrwBitmap method.

Even if are already running the recent beta code you may still want to get the download for the updated example sketch and the Processing app that creates bitmap files.

[media]http://www.youtube.com/watch?v=019HDRBf4sA[/media]

have fun!

Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 09, 2009, 03:53 am
Ok, I made an icon similar to the one you used, but when i try to run the code with the processing pde file, i get an error with 'writefile' .  I changed the string file name to the one im using and cant get a header file out of it.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 09, 2009, 06:17 am
What exactly does the error message say?

Did you copy the BMP file to the data directory (the same directory that contains the ArduinoIcon.bmp file)

Do you get an error message if you try to re-make the header file using the unmodified Processing sketch and the supplied bmp file?
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 09, 2009, 04:21 pm
I got the error msg Even when recompiling the processing sketch that makes the header file. I used paint to make a 64x64 pixel logo for my side work and tried to make that but I get some error like something 'writefile' global something. I'm at work now, so I will upload a screenshot when I get out.

I did everything as it said to do, I even deleted the library and re downloaded it and ran the processing sketch with the given filenames and I get the same error.  Ill get a pic up soon.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 09, 2009, 04:45 pm
Yes, knowing the actual  error will help. If you still get the error with the supplied ArduinoIcon.bmp and the unmodified Processing sketch, can you say exactly what files are in your directories. It should look like this:

A directory (under your Processing sketches) named: glcdBitmap with the following entries:
A file called  glcdBitmap.pde dated July 2 2009
A file called readme.txt that I trust you have read!
(If there is a header file called ArduinoIcon.h, delete that file for now)
A directory called data with a file called ArduinoIcon.bmp dated 9 November 2008

If  your Processing directory does not look like that then reinstall the ks0108 Processing files.


Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 09, 2009, 10:27 pm
Ok, im going to try again.

1)clear out all traces of any GLCD libraries lol
2)download from link supplied on GLCD library playground page.
3)extract folder "ks1080" to arduino0015\hardware\libraries\
4)navigate to arduino0015\hardware\libraries\ks0108\
5)delete "arduinoicon.h"
6)open arduino IDE
7)sketchbook>open>navigate to ks0108\processing\glcdbitmap\
8)open "glcdbitmap.pde"
9)verify/compile ->

this should give me a header file for the arduino icon bmp supplied in package.


Here's what I get. ->

(http://i108.photobucket.com/albums/n10/Metalfan036/error.png)

Im still new to C so im not even sure what's going on.  But there you have it.

any ideas?  :)

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 09, 2009, 11:04 pm
Glcdbitmap.pde is a Processing sketch. It needs to be run by Processing, not Arduino. See  http://processing.org/
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Jul 09, 2009, 11:25 pm
my bad


it had a pde extension so i thought it was arduino sketch lol

ok, well that should fix it then  ::)
Title: Re: Graphic LCD (KS0108) library now available
Post by: slanderer on Jul 23, 2009, 07:36 pm
I can't seem to get this code working on the LCD screen i just got from adafruit
http://www.adafruit.com/index.php?main_page=product_info&cPath=37&products_id=188

I'm using the Arduino (atmega328), and I followed the "B" wiring described on the library's page. The backlight comes on, and the contrast is adjustable (although I had to use a 47ohm current limiting resistor for it to work right).

All I see on the screen with the demo code is black pixels, and a sorta slight wavy/noisy effect when using a medium contrast, which will stop if I reset the board, but come on after a few seconds (although the dark pixels remain dark).

Any ideas?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 23, 2009, 08:24 pm
The most common cause of problems is incorrect wiring. Can you get someone to double check the connections for you. If  not, perhaps post a clear picture of  how your setup is wired
Title: Re: Graphic LCD (KS0108) library now available
Post by: slanderer on Jul 23, 2009, 08:56 pm
I've redone the wiring 3 times, changed the EN_DELAY_VALUE (and deleted ks0108.o) a dozen times, to anything from 6 to as high as 50.

I'll try to throw together a diagram of my wiring, but it exactly follows the scheme of Pinout B.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 23, 2009, 09:27 pm
I was thinking of a photo. Its surprising how easy it is to miss some wiring problem over and over. You would not be the first to be absolutely positive that the wiring is ok and later find something is not connected as it should.

Are you using the latest version of the code, the source files should have a comment indicating  Version 2 - May 26 2009
Title: Re: Graphic LCD (KS0108) library now available
Post by: slanderer on Jul 24, 2009, 02:59 pm
ah, i've found the problem. turns out one of my jumper wires (the one connected to the Enable pin, unfortunately) was  cut inside it's insulation, due to repeated bending i imagine.

Works like a charm, now.

Just to be certain, I should be getting 9 FPS w/ the demo code if EN_DELAY_VALUE is set to its default value of 5, right?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 24, 2009, 03:27 pm
The latest version of the library is much more tolerant of different panel speeds then the first release and this results in it running slightly slower than the old version. You can try smaller delay values to see if your panel can cope but expect an FPS of 8 or less.
Title: Re: Graphic LCD (KS0108) library now available
Post by: slanderer on Jul 24, 2009, 04:29 pm
thanks for the help.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Jul 30, 2009, 11:44 am
Hello,

first: I'm from Germany and my english isn't really good!

I have a problem. like on page one in the last two posts. My Display is flickering a lot. both sides are involved. I hope you understand what I mean.
I took the libary given on this page  and installed it on my arduino. I use an Atmega328 microcontroller on my arduino.
this is my display
I hope you will find a solution because I have to use it in my project. I want to show temperatures, fanspeeds and other things with it.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Jul 30, 2009, 11:45 am
I'm sorry but I couldn't post links in my first post so I have to do it now.

I have a problem. like on page one in the last two posts. My Display is flickering a lot. both sides are involved. I hope you understand what I mean.
I took the libary given on this page http://www.arduino.cc/playground/Code/GLCDks0108 and installed it on my arduino. I use an Atmega328 microcontroller on my arduino.
this is my display http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&ssPageName=STRK:MEWNX:IT&item=140331745957
I hope you will find a solution because I have to use it in my project. I want to show temperatures, fanspeeds and other things with it.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 30, 2009, 12:28 pm
Quote
I have a problem. like on page one in the last two posts.

could you say what the actual post numbers are, I am not sure which ones you mean.

The specifications of your display look ok so we should be able to get it to work if you can explain the problem clearly.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Jul 30, 2009, 12:43 pm
Thanks for the answer! It is reply #12

may I make a video.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Jul 30, 2009, 12:52 pm
I've made a short video clip.

[media]http://www.youtube.com/watch?v=zmw9fgX9f9A[/media]
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 30, 2009, 01:30 pm
lorz, Reply#12 was a problem where there was no actual graphics, also the code that was related to that problem is no longer in the latest release.

Your LCD is producing graphics - I can make out the boxes and the FPS text but although its breaking up, I think you are close to getting it working.   In the file ks0108_panel.h, try increasing the delay value:
#define EN_DELAY_VALUE 2 // this is the delay value that may need to be hand tuned for slow panels

Change the number 2 to something like 16. Delete the ks0108.o file and rebuild your sketch. If that fixes the problem you can try smaller values to find the fastest speed your panel can cope don't forget to delete the .o file after each change in one of the library files.

If you still have the problem try a very large value, say 30. if that makes no difference then its some other issue and we can look at that if necessary

BTW, I think you need to swap the chip select pins, the FPS should display on the right hand side. See the playground for more about this.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Jul 30, 2009, 02:51 pm
Thanks a lot now it is working.

in my download I hadn't any file named ks0108_panel.h.

But after I reload it from playground there was one. I hadn't anything to change.

Now I will programm my own code with temperaturesensors and other things.

I will show you the result in some days.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 30, 2009, 03:26 pm
Good to hear you have it going. I hope you can post some pictures when you are done.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 01, 2009, 08:41 pm
Again me


I have  the next problem: I can't change the command pins. I want to put it to port b. but if I put it to port b the display shows only the second half. I don't know why. Is there anything else what I have to change?

All Datapins are on port d and my serial communication during the code runs on arduino is deactivated ==> pin 8 to 13 are free so they are free and ready to be used by the command pins. I hope you understand what I mean.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 01, 2009, 09:59 pm
If you can see the display on one half only then you have a problem with one of the chip select pins (CSEL1 or CSEL2). Make sure that the defines in the ks0108_Arduino.h header file match the actual pins you are using.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 01, 2009, 10:20 pm
All pins are right!

Thanks for the answer
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 01, 2009, 10:33 pm
Does that mean its now working correctly,  or that you checked the pins and they are set correctly but its still not working
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 01, 2009, 11:04 pm
It means that its still not working. Sorry that I confused you.

thanks for the answer.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 01, 2009, 11:36 pm
Try swapping the wires so that CSEL1 and CSEL2 are connected to opposite pins. See if the image changes sides.  If so the you need to make sure that the pin definitions in the header file match the wiring.

It may help if you say what pins you are using and cut and paste the definitions from the header into a post so I can see what you have.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 02, 2009, 12:33 am
I found the mistake. I forgot to commend the following line:

/* 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 for pins 14-19


I'm sorry I think tomorrow I will post some pictures.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 02, 2009, 10:27 pm
I've a further question. I want to youse the GLCD with shiftoutregisters how can I realize that?

I think that it is a bit complicate so I ask you mem.

If it is too complicate it is also possible to use a seperate arduino but I prefere to do it with the shift register. My shift registers are 74hc595. I think taht I have shift in registers for the command pins. So I thinkk I will use 74hc165.

I hope you understand what I mean. Is it possible to paste the libaries into the normal code cause if it is I could use the shiftregisters easily. If not I don't know how I have to use it.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 05, 2009, 11:04 pm
Is there any possibility to use the GLCD with shift registers? For me it is too complicated to change the libary because I can't understand it.

I have to use the pins for some buttons to make a display menu. And I want to read some fan speeds and temperatures

at the moment

pin 0 - 7 Display Data pins
pin 8 - 12 Display Command pins
analog pin 5,4 tempertatures
analog pin 3 - 1 fan speed

==> 2 pins left. But I have to set again 2 potentiometers and min 2 Buttons. Thats why I have to get new pins.
The fan speed pins can also be set to digital pins.

I hope you understand my problem.

If not ask me.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 05, 2009, 11:13 pm
It has been done although I have not tried it myself. See posts starting from here for more: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210427907/63#63

Another approach is to use a board with lots more pins, such as the sanguino or mega.
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 06, 2009, 04:20 pm
Thanks a lot I overread this post.

But it wont work. I don't know why.
I get lots of errors.

Is it possible that you try it.

Propably it cant work with the new libary.

I will give some pictures if I'm ready.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 06, 2009, 05:24 pm
Unfortunalty I don't have any spare time at the moment to do any work on integrating shift registers with this library. Did you try and contact the person that posted that code to see if he can help?
Title: Re: Graphic LCD (KS0108) library now available
Post by: fury_lorz on Aug 06, 2009, 05:32 pm
Thanks

I will try to cantact the person who postet the hack.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Aug 14, 2009, 02:53 pm
I tested my old hack with the new KS0108 lib and it works just fine.
I also tried to move the CSEL1 and CSEL2 to the digital pins and it was easy.
Then I tried to move the D_W, D_I an EN to the digital side but was not able to get it to work.

mem do you have an idea of why it is not possible to just change the D_W, D_I and EN pins from the analog side to the digital side by just changing the pin settings in the h-file???
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 14, 2009, 03:30 pm
All the command pins share the same code so if CSEL works then the others should also.

I have a version running here on a standard Arduino board with EN on digital pin 2 and it works without problems.  The command pins have been tested on digital pins 30-37 on the Mega board. What board and controller are you using?
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Aug 14, 2009, 05:56 pm
I'm using Diecimila board with a 168 controller.

If I use CSEL1 and 2, E_W, D_I and EN on Port C it works.
If I use Port B or D it don't work, no text or symbols appear on the GLCD.
But if only the CSEL1 and 2 is moved to Port B or D it woks.

They are all set with "fastWriteHigh" or "fastWriteLow" and therefore I cant understand why it won't work.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 14, 2009, 08:24 pm
In ks0108_Arduino.h  lets see what happen if we try this test:

Comment out the two lines defining fastwriteHigh and fastwriteLow and replace with:

#define fastWriteHigh(_pin_) digitalWrite(_pin_, HIGH)
#define fastWriteLow(_pin_) digitalWrite(_pin_, LOW)

Try that with your pin assignment and let me know if that works (it may be slow but I just want to know if you can see anything)

Are you testing this with the GLCD directly connected or with a shift register?
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Aug 14, 2009, 11:45 pm
No the result is the same, nothing on the screen.
I tried with a lot of different pin assignments but the result is still as described in reply #187.

I'm using a shift register. Do you think that the shift register can cause this kind of problems.
If the shift register creates this problem, it may be a synchronization problem. Something that goes too fast or too slowly.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 15, 2009, 12:52 am
I wonder if it is the shifting code, can you post your sketch.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Aug 15, 2009, 03:02 pm
I am using your example sketch for testing. But the shifting code is in the lib.
I altered your new KS0108 lib according to reply #63 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210427907/63#63, all the shift register code is in the ks0108.h file. That code is from MartinFick in the "higher performance IO" thread.

The only thing I did to change the pin assortment was to change the top of "ks0108_Arduino.h" to the digital pins instead of the analog ones.
The Shift register pins is defined in the ks0108.h file (pin 2,3 and 4).

If you want I can send you a private mail with all the code, maybe its easier to look at it when it is implemented.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 15, 2009, 03:36 pm
I just realized that you may not be reading the LCD status. Have you modified the WaitReady function so it reads the busy flag (this requires either an additional pin on the arduino or some clever wiring)

Yes, pm me the files you changed and I will have a look.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 15, 2009, 07:03 pm
Frisken, It looks like you have not modified the read routines and this may be why its not working.  I think there is a problem with this shift register solution because of the architecture of the ks0108 chipset.

The library read a byte of data from the chip before each write. If you study the datasheet you will see why the library has to do this to prevent overwriting adjacent pixels.  I don't think your code actually accesses the data  so the output routines will not be correct.  

One way to overcome this is to create a copy of the pixel data in Arduino RAM, but this requires 1K of memory dedicated for this, so won't work on a ATmega168.

Anther way is to use a bi-directional shift register to get the data back into the arduino but that will be complicated and slow.

Perhaps I missed the place in your code that addresses this problem, can you actually duplicate the image shown in the playground (using any pins of the pins to drive the shift register)? if so, perhaps put some delays in the sketch to slow things down and take a picture so I can have a look.  
Title: Re: Graphic LCD (KS0108) library now available
Post by: Frisken on Aug 15, 2009, 08:07 pm
I changed all the reads to be static 0x00 instead of "this->ReadData()" and thereby it is not possible to do readings from the GLCD. If I only ever write to any of the 8 adjacent pixels once, then I don't need to read the LCD data. I use a fixed width font that I got from you in reply #64. I works great if the amount of characters on a row is known. Look at reply #47 to #50.

My app only uses text and some small graphics and I have no problem using the analog pins for the GLCD. Therefore I have not seen this problem until Lorz contacted me. Lorz have to use the analog pins for other stuff and therefore I tried to use only the digital pins, but it do not work for some strange reason.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 15, 2009, 08:40 pm
Does Lorz know that  the pixel, line, and proportional font functionality will not work correctly when using write only shift registers? It would be unfortunate if he went to a lot of effort to get it going only to find it does not do what he wants.

Anyway, lets try replacing the sbi/cbipin macros with fastwrite macros:
Change:
Code: [Select]
#define bitWrite(pin, val) { \
 if ((val) == LOW) cbipin(pin); \
 else              sbipin(pin); \
}

To
Code: [Select]
#define bitWrite(pin, val) { \
 if ((val) == LOW) fastWriteLow(pin); \
 else              fastWriteHigh(pin); \
}
Title: Re: Graphic LCD (KS0108) library now available
Post by: adr1an on Aug 18, 2009, 10:50 am
Quote
One way to overcome this is to create a copy of the pixel data in Arduino RAM, but this requires 1K of memory dedicated for this, so won't work on a ATmega168.


Mem: I assume this is using the 'undocumented' DrawBitmap feature you made reference to earlier in the thread? When you have a moment, could you share an example of how to do this? I am using this lib great on a Mega, but want to downscale to a Pro-Mini (328/16Mhz) and would like to give a shiftreg a go. Bearing in mind bi-directional is too slow/complicated, whats involved using the method you suggest?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 18, 2009, 11:21 am
Hi Adr1an, DrawBitmap is exposed in the version uploaded to the playground in July and there is an example of its use in the sketch in the download.

But that function gets its data from progmem, you would need to modify DrawBitmap to get its data from a RAM buffer. That's the easy part. The more difficult task would be to modify the WriteData and ReadData routines so they operated on the RAM buffer and then flushed this to the LCD.

certainly possible but not easy.

Have fun!

Title: Re: Graphic LCD (KS0108) library now available
Post by: todotani on Sep 05, 2009, 10:29 am
Hi,
I experienced the following issue of Puts() member function.
When I print string on the last line of GLCD with the following sketch, font image was shown disordered.

Code: [Select]

#include <ks0108.h>  
#include <Arial14.h>

void setup(){
 Serial.begin(115200);
 GLCD.Init(NON_INVERTED);  
 GLCD.SelectFont(Arial_14);

 GLCD.ClearScreen();
 GLCD.GotoXY(0, 50);
 GLCD.Puts("Arduino");
}

void  loop(){  
}


To solve this issue, I add the following code in ks0108::WriteData() function.
Code: [Select]

     displayData |= data << yOffset;
     if(this->Inverted)
           displayData = ~displayData;
     lcdDataOut( displayData);                              // write data
     this->Enable();                                                // enable
     
     // second page
     // --- Additonal (Do not draw second page in case y address exceed DISPLAY_HEIGHT) -----
     if ( (this->Coord.y + 8 - yOffset) >= DISPLAY_HEIGHT )
     {
           this->Coord.x++;
           return;
     }
     // --- End Additonal -----
     this->GotoXY(this->Coord.x, this->Coord.y+8);
     displayData = this->ReadData();
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 05, 2009, 11:50 am
Hi todotani,

Thanks for spotting that. GotoXY does do a range check but as you recognized the problem occurs because the WriteData function does multiple low level writes to the chip.


I think an even  better solution would be have GotoXY return a Boolean value of true if the range was valid and false otherwise.

The only change in the GotoXY code would be to add the return values:
Code: [Select]
boolean ks0108::GotoXY(uint8_t x, uint8_t y) {
 uint8_t chip, cmd;
     
 if( (x > DISPLAY_WIDTH-1) || (y > DISPLAY_HEIGHT-1) )      // exit if coordinates are not legal
   return false; // in the published version this returns without a value
 - - -
 (remaining code unchanged)

  return true;  // add this      
}

The change to WriteData could be:
Code: [Select]

 displayData |= data << yOffset;
 if(this->Inverted)
   displayData = ~displayData;
 lcdDataOut( displayData);   // write data
 this->Enable();               // enable

 // second page
 // New code
 if( ! this->GotoXY(this->Coord.x, this->Coord.y+8) )
 {
   this->Coord.x++;
   return;
 }
 // -- end new code
 displayData = this->ReadData();

Perhaps you could try that and let me know if it works for you
Title: Re: Graphic LCD (KS0108) library now available
Post by: todotani on Sep 05, 2009, 12:14 pm
Hi mem,

Thank you for your confirmation.
I tested your modification and worked fine!
I'll apply your modification.
Title: Re: Graphic LCD (KS0108) library now available
Post by: trunck on Sep 14, 2009, 05:43 pm
Hello mem,
Great work on the library. I am using it and it's working very well.
I do have a problem with the program that creates a H file from a bitmap: glcdBitmap.

I managed to create the H file from bitmaps that were squares, i.e 32x32 or 64x64 pixels. However once I try a bitmap that is 64x32 for example, I am getting an array out of bounds exception in the getvalues function, here's the info:

Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 2822
     at glcdBitmap.getValue(glcdBitmap.java:109)
     at glcdBitmap.writeFile(glcdBitmap.java:88)
     at glcdBitmap.setup(glcdBitmap.java:48)
     at processing.core.PApplet.handleDraw(PApplet.java:1402)
     at processing.core.PApplet.run(PApplet.java:1327)
     at java.lang.Thread.run(Thread.java:619)

it's easy to recreate. Just thought you would like to know about this. I didnt see anywhere in the instructions that the bitmaps had to be squares so i figured it's a bug.

Thanks for the help,
trunck
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 14, 2009, 06:54 pm
Hi trunck,

I have converted many non-square bitmaps including sizes 64x32 and 32X64 without problem.

Did you try converting the image to a monochrome bmp file before running glcdBitmap?
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Sep 14, 2009, 09:33 pm
I am building a remote controll with a touch screen and a kso1o8 lcd.
To save battery i am looking for a way to switch off the lcd and back on when needed, is that possible with command?
If yes, will the lcd when turned on display the old graphics or do i need to initiate it again with the graphics that where on before it was switched off?
Actually i am sure that the lcd will not draw a high amount from the battery current (10mA) but the lcd light will do so but that is easy to controll (350mA).
Title: Re: Graphic LCD (KS0108) library now available
Post by: Nachtwind on Sep 14, 2009, 10:05 pm
afaik its not possible to turn it off via command.. but i believe to remember that you could disconnect the 1st Pin (or second - depending on the type) +5V and plug it in again without having to reinitialise the lcd. Maybe you can save some ma that way..
Title: Re: Graphic LCD (KS0108) library now available
Post by: Nachtwind on Sep 14, 2009, 10:08 pm
afaik its not possible to turn it off via command.. but i believe to remember that you could disconnect the 1st Pin (or second - depending on the type) +5V and plug it in again without having to reinitialise the lcd. Maybe you can save some ma that way..
Title: Re: Graphic LCD (KS0108) library now available
Post by: HULK on Sep 14, 2009, 10:15 pm
Thanks Nachtwind, it works great.
Did not think that would work but maybe test before asking next time...  :D
Title: Re: Graphic LCD (KS0108) library now available
Post by: foozinator on Sep 14, 2009, 11:31 pm
How easy is it to change the pins used?  Covering up the SPI lines makes it difficult to attach things like this SPI transceiver (http://www.hoperf.com/pro/RFM23.html).  Are there alternative ways of dealing with this?  XBee is much more expensive than the RFM radios.
Title: Re: Graphic LCD (KS0108) library now available
Post by: agib on Sep 14, 2009, 11:45 pm
Hi,

I've just got the library up and running with a GLCD from sparkfun and it worked first time! There's very few times that happens, so THANKS MEM!

I was also wondering if any thought had been put into having the ks0108 class implement Print?

I had a look at the LiquidCrystal library to see how they implemented it, and did the equivalent. It seems that all you have to do is implement a write method which just passes on a uint8_t to PutChar. I have implemented this and it seems to work, the LCD can be printed to using the familiar print syntax and methods. This has the added bonus of being able to use the Streaming library, which makes printing lots of text easier.

I've only had a quick play with this, but it appears to work as you would expect. Is there anything I might have missed? Would it be worth integrating this modification into the library?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 15, 2009, 12:21 am
Quote
I was also wondering if any thought had been put into having the ks0108 class implement Print?


Hi agib, thanks for the feedback.

Quote
I was wondering if any thought had been put into having the ks0108 class implement Print?


The elemental function of the LiquidCrystal library is to write characters, so its derivation from print makes a lot of sense. The elemental function on a graphical LCD is to write pixels so it does not seem so natural to derive the library from print.  But I would be interested to see the work you have done along those lines.

I have been thinking about abstracting the chip specific functions to make it easier to get chips other than the ks0108 to work, but have not had the time to do very much with that.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Sep 15, 2009, 12:26 am
Quote
How easy is it to change the pins used?  Covering up the SPI lines makes it difficult to attach things like this SPI transceiver.


The header files  (ks0108_arduino.h, ks0108_mega.h, ks0108_sanguino) describe the pin options for the various boards. There is not much choice on a standard arduino board but you can probably move things around to work.
Title: Re: Graphic LCD (KS0108) library now available
Post by: agib on Sep 15, 2009, 12:42 am
Yeah, I understand there isn't really an "is a" relationship in the same way that "LiquidCrystal is a Print(able) object".

My main motivation for doing it was so that it would be compatible with the Streaming library, it's a lot easier to do:

Code: [Select]
GLCD << hour << ":" << min << ":" << sec;

than

Code: [Select]

GLCD.PrintNumber(hour);
GLCD.Puts(":");
GLCD.PrintNumber(min);
GLCD.Puts(":");
GLCD.PrintNumber(sec);


It is useful for my application, so I figured other people might get some use from it too.

The changes are rather minimal, in ks0108.h:


Then in ks0180.cpp just stick

Code: [Select]
void ks0108::write(uint8_t c)
{
     PutChar(c);
}


somewhere.
Title: Re: Graphic LCD (KS0108) library now available
Post by: agib on Sep 15, 2009, 07:38 pm
Another minor thing, in keywords.txt, the constants are defined

Code: [Select]
#######################################
# Constants (LITERAL1)
#######################################
BLACK      KEYWORD2
WHITE      KEYWORD2
NON_INVERTED      KEYWORD2
INVERTED      KEYWORD2


Is that just a copy+paste error, should they be defined as LITERAL1?
Title: Re: Graphic LCD (KS0108) library now available
Post by: curious8 on Oct 16, 2009, 09:48 am
hi I'm new here... i was wondering if i could use atmega 164 instead of atmega 168.

Thanks! ;D
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 16, 2009, 11:11 am
Quote
i was wondering if i could use atmega 164 instead of atmega 168.


It may work with the Sanguino (ATmega644) version:

You will need to add the following line in ks0108.h  just after the line:
// Chip specific includes
#define __AVR_ATmega644__  // add this line for  chips compatible with ATmega644

But you need to check the datasheets to see if there are any differences other than memory between your chip and the 644
Title: Re: Graphic LCD (KS0108) library now available
Post by: curious8 on Oct 19, 2009, 04:42 am
Thanks!!
I'll be doing that now and hopefully it would work perfectly.
Thanks again! :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: webjack on Nov 03, 2009, 12:37 am
Hello,
First, sorry for my bad English, I do not speak this language.

I'm using the Arduino Nano and I wonder if I should change the configuration pins CSEL1, CSEL2, RW, RS, etc. ..? Because the port analog of Nano are between pins 19-26 and I am using # include <ks0108_Arduino.h>.

Thanks!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 03, 2009, 08:01 am
You should be able to use any valid pin for the Commands. In ks0108_arduino.h, change these defines to any free digital pin:
[font=Courier New]
#define CSEL1  14
#define CSEL2  15
#define R_W   16
#define D_I  17
#define EN  18[/font]

Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 15, 2009, 06:43 am
I know this is a old thread, but I was wondering if anyone has had any luck interfacing these graphic LCD's/libraries with LCD smartie? I have been poking around the LCD smartie code for the alphanumeric displays and it seems like it could work with a few function changes.

Anyone?
Title: Re: Graphic LCD (KS0108) library now available
Post by: tytower on Nov 15, 2009, 08:33 am
I attached this to the wrong thread. This is where it should have been. This error may well appear in the middle pages a bit .

The product sold by adafruit at Nov 2009 is KS0108 and 7 chipsets
The LCD is driven by on-board 5V parallel interface chipset KS0108 and KS0107. They are extremely common and well documented

http://www.adafruit.com/index.php?main_ ... cts_id=188

TAKE NOTE - If you make a mistake and reverse the board completely and connect up pins 1->20 as advised it works OK as far as lighting up and contrast control but that is all that you will get. Just reverse the unit completely by turning it around in the breadboard, if you can, and voila , all works.

From silly personal experience

[glow]Things[/glow] Good thing you did not hear my mutterings and curses. You are on the list as the tester of this same device
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 15, 2009, 10:37 am
Yeah, I was confused with the pinout at first too, so I just used the back of the LCD as reference to get it started.

I had to rewire the thing like 7 times before I got it working  :-/

Also, the backlight voltage on these things is 4.2V nominal, the resistor value given on the page should be fine. Infact, anything should work.

I am trying some simple stuff like trying to write to it from serial, but since there is no actual "rows" like on the alphanumeric displays, it's making it somewhat complicated to do anything with.

EDIT: Actually, I have noticed that you need to leave the RESET pin on the Arduino disconnected from the LCD or you get upload errors. Maybe I'll note that on the playground.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 15, 2009, 11:57 am
Quote
I have noticed that you need to leave the RESET pin on the Arduino disconnected from the LCD or you get upload errors.

I have not seen this behaviour on the LCDs I have tested. What Arduino board and LCD are you using and can you say more about the error you are seeing.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 15, 2009, 12:18 pm
I am using the KS0108 LCD from adafruit, and a Duemilanove w/ 328 .

I can't remember the error message exactly, next time I wire it up I'll check it out.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 15, 2009, 01:11 pm
I would appreciate if you could note the error message and say a few words about when and how often it is triggered so I can mention this in the troubleshooting section.  How are you resetting the LCD?
Title: Re: Graphic LCD (KS0108) library now available
Post by: tytower on Nov 15, 2009, 09:26 pm
To save things rewiring the thing ..
My experience with the same panel which is from adafruit is that uploading a sketch does not work with all the pins attached . I have to press the reset button immediately the sketch compiles .

Quote
Error-avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding


Removing the reset connection cures this but obviously must affect the reseting of the panel

While you are at it the supplied example sketch wipes part of the window line .Replacing this line will fix it
Quote
GLCD.FillRect(72,44,53,14, WHITE);   // clear text area that will be drawn below


and this fits the circle in a bit better
Quote
GLCD.DrawCircle(32,32,26,BLACK);  // draw circle centered in the left side of screen
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 16, 2009, 05:27 am
Quote
My experience with the same panel which is from adafruit is that uploading a sketch does not work with all the pins attached . I have to press the reset button immediately the sketch compiles.


It sounds like that panel is preventing the Arduino serial line pulling reset low. Does the display appear to function ok with the reset line disconnected once the sketch has been uploaded?

Quote
While you are at it the supplied example sketch wipes part of the window line. Replacing this line will fix it:
  GLCD.FillRect(72,44,53,14, WHITE);   // clear text area that will be drawn below


By wiped, do you mean the pixels are being turned off? Can you clarify what part of the screen is being wiped, perhaps you can identify the code in the sketch that seems to be doing the wiping.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 16, 2009, 06:32 am
The panel resets fine when the Arduino resets, although it doesn't clear while new code is uploading, sometimes messing with the display data and distorting the image until the Arduino auto-resets.

Not really a big deal, though :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 16, 2009, 10:28 am
Quote
... the supplied example sketch wipes part of the window line.

Things, are you seeing something like this on your panel?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mobyfab on Nov 16, 2009, 02:26 pm
Hey,

I'm currently having some issues with this lib,

So basically, as soon as i'm using drawrect or fillrect function, the contrast goes really low. (even with no refreshing, in static)
Drawbitmap and static text works just fine.

I'll give todotani's modifications and see if it helps. Maybe refreshing the whole screen at once works better.

Any ideas ?

Thanks
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 16, 2009, 03:02 pm
What panel are you using? Have you tried to increase the EN_Delay value?

You may want to try an expiremental version of the library that is more tolerant to slower panels:
http://www.arduino.cc/playground/uploads/Code/ks0108Alpha.zip

This code is work in progress and its not ready for distribution but would be intersting to see if it fixes your issue.



Title: Re: Graphic LCD (KS0108) library now available
Post by: mobyfab on Nov 16, 2009, 04:18 pm
Hi mem,

Here is my panel: http://www.artronic.pl/o_produkcie.php?id=721

I will try to play with that value, haven't yet. :)
If is doesn't work then I'll try that alpha version.

Thanks for the fast response.  :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 16, 2009, 04:34 pm
Try it with a high EN_Delay value (say 25), if that fixes it then you can reduce it to just before the problem re-occurs.

If not, try the work-in-progress version.  

Looking forward to hearing how you get on.

good luck
Title: Re: Graphic LCD (KS0108) library now available
Post by: mobyfab on Nov 17, 2009, 02:04 am
no luck with the delay variable...

I'm currently testing the frame buffer version, works good so far:

http://www.dailymotion.com/video/xb6a2z_arduino-mega-ks0108-frame-buffer-mo_tech
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 17, 2009, 08:38 am
Thought I would just post this here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1258442712/0#0

Buy, back with my original question, is there anyone who has had this working with LCD Smartie or knows how to get it working?
Title: Re: Graphic LCD (KS0108) library now available
Post by: tytower on Nov 17, 2009, 10:51 am
Things -Excuse me  I'll have a look at that question tomorrow if poss. I've got some travelling to do so it may be late.

Quote
mems -By wiped, do you mean the pixels are being turned off? Can you clarify what part of the screen is being wiped, perhaps you can identify the code in the sketch that seems to be doing the wiping.


Led by the nose. The program drawing the sketch above that things is using displays the Icon then draws a frame and so on .

When it writes
GLCD.FillRect(72,44,53,14, WHITE);   // clear text area that will be drawn below

the 53 is 55 and its too big it wipes through the line . My post is the replacement line needed.


Code: [Select]
#include <ks0108.h>  // library header
#include <Arial14.h>  // font definition for 14 point Arial font.
#include "SystemFont5x7.h"   // system font
#include "ArduinoIcon.h"     // bitmap  
#include "RoseanneIcon.h"
 int count = 0;

void setup(){
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted turns on written pixels
 GLCD.ClearScreen();  
 GLCD.DrawBitmap(RoseanneIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
 GLCD.SelectFont(Arial_14); // included font, you can also make your own fonts  
delay(15000);

}

void  loop(){   // run over and over again
   GLCD.GotoXY(72,12);    // position cursor at x position 72, y position 12  (0,0 is upper left)
   GLCD.Puts("Drawing");   // write a string to the current cursor position  
   GLCD.DrawRect(0, 0, 64, 62, BLACK); // rectangle in left side of screen
   GLCD.DrawRoundRect(68, 0, 58, 62, 5, BLACK);  // rounded rectangle around text area  
   for(int i=0; i < 62; i += 4)
     GLCD.DrawLine(1,1,62,i, BLACK);   // draw lines from upper left down right side of rectangle  
   GLCD.DrawCircle(32,32,26,BLACK);  // draw circle centered in the left side of screen    
   GLCD.FillRect(72,44,53,14, WHITE);   // clear text area that will be drawn below
   GLCD.GotoXY(72,44);                           // locate curser for printing text
   GLCD.PrintNumber(count++);      // print a number at the current cursor position
   delay(2000);
   
   GLCD.ClearScreen();   // clear the screen
}


pings - another new one , there is a pattern developing. Money is only useful for the things you can do with it . Its fun to track things using money to coax peoples best from them . Hold on to your hat
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 17, 2009, 12:29 pm
I assumed that everyone would be running the example code in the download and had neglected to update the playground text which was out of date.

The fillRect function is not needed when drawing text with the latest library (The font output functions now clears text).

I have updated the playground page so the code example is now based on (a simplified version of) the example sketch in the current library download.
Title: Re: Graphic LCD (KS0108) library now available
Post by: tytower on Nov 17, 2009, 12:42 pm
When I downloaded the library under "ks0108/examples" I get the directory "Processing" only. Under Processing I get "gdbcBitmap" only. To get the examples you have to go in and pull them out and save them.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 18, 2009, 08:01 am
Quote
When I downloaded the library under "ks0108/examples" I get the directory "Processing" only. Under Processing I get "gdbcBitmap" only. To get the examples you have to go in and pull them out and save them.

Selecting examples/ks0108 from the file menu should show two options:
 GLCDExample
 Processing

On my machine, clicking on GLCDexample brings up the example sketch. (The Procesing sketch should only be run from the Procesing IDE.)

Are you seeing something else?
Title: Re: Graphic LCD (KS0108) library now available
Post by: tytower on Nov 18, 2009, 10:39 am
Ive just said that . The file extraction process looks good from what I can see and the directory is there but does not show up on the Arduino examples menu. Only the processing folder is there.

I have noticed this at other times on I think VirtualWire but I'll have to recheck it.

It is something to do with how Arduino gathers its menu data . The permissions of both folders seemed the same  
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 19, 2009, 04:08 am
Would it be possible to add a class function that allows you to display stuff on the LCD upside down? If so, how? :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 04:53 am
Morgan, are you wanting to do something like displaying text or an image upside down, or are you wanting everything drawn upside down?  It would help if you can say more about your application.
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 19, 2009, 04:55 am
Everything. I am mounting it on a cramped breadboard space where it would have to be displayed upside down to be legible.

Thanks for your help.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 05:26 am
What you want to do would not be easy.

The ks0108 graphics chip that the library is driving has a complicated method of addressing the vertical axis and having a runtime check to flip the vertical axis would slow down every display. If you feel up to playing with this yourself, the function that needs to change is GotoXY where the values from 0 to DISPLAY_HEIGHT-1) would need to be transformed to range from DISPLAY_HEIGHT-1  to 0.  That part is easy, Y = DISPLAY_HEIGHT-1 - Y. The complicated bit is that the graphics chip divides the Y axis into pages that are 8 pixels high and the code needs to keep track of which page is active.

The low level library GLCD code is optimized for performance and is not easy to understand. This is further complicated by the unclear technical documentation in the chip datasheet (for example, the official Samsung ks0108 datasheet refers to the vertical position as the X page register and the horizontal position as the Y address counter)

One way to solve you problem is to flip the vertical coordinates  of the objects in your sketch. You would need to invert any bitmaps using a drawing tool before importing them and if you use the fonts you would also want to find a way to invert the definitions.
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 19, 2009, 05:33 am
Quote
What you want to do would not be easy.

Wow, it is optimized for speed. Reminds me of some Linux kernel boot code. :)

For this project, I'm simply displaying bitmaps. I suppose that drawing the bitmaps inverted would be a much better way to do it instead of having to get into the code. Thanks for the help.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 05:53 am
Yes, inverting the bitmaps in a drawing tool would be the easy way to do what you want.

Have fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 19, 2009, 07:32 am
Ok, now I'm having a problem. I'm positive stuff is wired correctly (I just double-checked it).

What's going on with my display? There's just one horizontal across it and no amount of resetting seems to do anything. It used to work just fine, but then I saw this horizontal line go out and rebooted it and it's messed up. Any suggestions?

(http://idisk.mac.com/maclover201-Public/arduino_glcd.jpg)

Morgan
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 07:40 am
If you turn the contrast up can you see all the pixels? If  the pixels have disappeared on that horizontal line even with the contrast up  then you may have a short circuit on the LCD PCB.
Title: Re: Graphic LCD (KS0108) library now available
Post by: tytower on Nov 19, 2009, 08:01 am
Perhaps you could adjust the horizontal hold just a little.
With mine I have a wire on every connection, I cant see yours enough to confirm this.

If it worked and now it doesnt it is a process of replacing each piece of hardware until the cause shows up. I find it necessary to have two of everything just for that reason. Hang the expense.

Every piece of hardware I have had ,has ,at some point ,given me the impression that I have blown it up. (Arduino board is the exception).

Cover it all with silver foil for an hour with as many contacts as possible contacting the foil (with no power obviously)
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 19, 2009, 09:47 am
Is it just me or are you missing a ground line on your contrast potentiometer?
Title: Re: Graphic LCD (KS0108) library now available
Post by: digiblue on Nov 19, 2009, 03:20 pm
I want use GLCD display serial usb input data.I write follow program,but Glcd can't display anything,but
I can read the input in IDE Serial Monitor.Anyone can help me?Thanks

void loop()
{
 // when characters arrive over the serial port...
 if (Serial.available()) {
   // wait a bit for the entire message to arrive
   delay(100);
   // clear the screen
   GLCD.ClearScreen();
   // read all the available characters
   while (Serial.available() > 0) {
     char inbyte = Serial.read();
     GLCD.PutChar(inbyte);
     Serial.print (inbyte);
   }
   }
}
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 03:30 pm
digiblue, can you post your setup code
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 19, 2009, 03:55 pm
digiblue, this should work.

Code: [Select]
#define MAX_LEN 16 // Change to your maximum input length

static char str[MAX_LEN];
static int a = 0;
 // Poll serial
 while( Serial.available() > 0 ) {
   // Get characters
   if( a < MAX_LEN )
     str[a] = char( Serial.read() );
   else
   {
     Serial.flush();
     
     // Reset vars and clear memory
     a = 0;
     memset( str, 0x00, MAX_LEN );
     break;
   }
   
   // Increase character index
   a++;
   
   // Wait for serial to catch up. Change as needed.
   delay( 1 );
 }


Which pin should I wire the ground on my contrast pot to? I will post high-quality pics if I can tonight. I was using my poor-quality webcam, so it's pretty hard to make out.

Actually, here's a high quality picture I already have of my once-working setup. I am running a random pixel program and driving 2 LCDs. For some reason both have inexplicably stopped working. It's like they aren't being initialized correctly, only the top row of the character LCD ever illuminates. I will check my wiring tonight again. That line on my graphic LCD hasn't totally disappeared, even with contrast all the way up. It's just pretty faint.

(http://idisk.mac.com/maclover201-Public/arduino_glcd_2.jpg)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 04:05 pm
Quote
Which pin should I wire the ground on my contrast pot to?

any of the ground pins will do. the wiring setup in the picture looks ok.

A good photo of the display as it is now will help to diagnose the problem.
Title: Re: Graphic LCD (KS0108) library now available
Post by: digiblue on Nov 19, 2009, 05:12 pm
mem,very thanks for you quick reply!
Setup code just add one line serial initial in ks0108 example file[ch65292]as follow[ch65306]
void setup(){
 Serial.begin(9600);
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
 GLCD.ClearScreen();  
 GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
 GLCD.SelectFont(System5x7); // switch to fixed width system font
 countdown(5);
 GLCD.ClearScreen();
 introScreen();              // show some intro stuff
 GLCD.ClearScreen();
}
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 19, 2009, 05:59 pm
If you have not set the cursor you may be trying to write outside the screen area.

First you should explicitly set the font you want as the last statement in setup. The system font is easier to use so start with that.

Then set the cursor to 0,0. Note that ClearScreen erases all displayed pixels but does not change the text cursor position.

look at the example code to see how the GLCD.CursorTo() function is used. Your serial code will need to keep track of the position to control where stuff is written to the screen.

Title: Re: Graphic LCD (KS0108) library now available
Post by: digiblue on Nov 20, 2009, 03:56 am
I rewrite the code[ch65292]as follow[ch65292]but still not display anything except initial Icon[ch65292]when I open the IDE Serial Monitor[ch65292]GLCD just ClearScreen and not output,but I can see Serial Print in IDE.

void setup(){
 Serial.begin(9600);
 digitalWrite (13, HIGH);      //turn on debugging LED
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
 GLCD.ClearScreen();  
 GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
 GLCD.SelectFont(Arial_14);
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
  // read the incoming byte:
     incomingByte = Serial.read ();

     // Store it in a character array
     str1[count] = incomingByte;
     count++;

     // check if we have over 49 characaters or we recieve a return or line feed
     if (count > 49 || incomingByte == 10 || incomingByte == 13)
       {
         // Display the string On GLCD
         GLCD.ClearScreen();
         GLCD.CursorTo(0,0);     // positon cursor
         GLCD.Puts("GLCD TEST");  
         GLCD.Puts(str1);
         Serial.print (str1);
         count = 0;
       }
  }
}
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 20, 2009, 04:34 am
Hey, with that code that prints text from serial, does it automatically move down 10 or so pixels if you exceed the character limit on a single row?

Code: [Select]
#define MAX_LEN 16 // Change to your maximum input length

static char str[MAX_LEN];
static int a = 0;
 // Poll serial
 while( Serial.available() > 0 ) {
   // Get characters
   if( a < MAX_LEN )
     str[a] = char( Serial.read() );
   else
   {
     Serial.flush();
     
     // Reset vars and clear memory
     a = 0;
     memset( str, 0x00, MAX_LEN );
     break;
   }
   
   // Increase character index
   a++;
   
   // Wait for serial to catch up. Change as needed.
   delay( 1 );
 }
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 20, 2009, 04:36 am
Nope, all it does is polls the serial until it gets a response and saves it in an array. You then have a character array you can do whatever you please with.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Nov 20, 2009, 04:38 am
Oh OK, would you be able to give me an example on how I could have it automatically move the cursor down by a pre-defined number of pixels, if there is more than 21 characters on a row?  
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 20, 2009, 04:40 am
Yep, it's pretty easy too. Record your start x and y positions and subtract the number of pixels from your y value every time you want to start a new line. Use a loop.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 20, 2009, 08:04 am
You can fit 21 characters on a line with the fixed width system font. The cursorTo function for this font operates on character rows and columns so you only need to keep track of how many characters you have printed on a column and what row you are on.

But its more complicated to use the proportional font you have in the sketch you posted. The width of each character is different so you need to use the CharWidth function to calculate the new x position when a proportional character is written. The CursorTo function should only be used with the fixed width system font.

It may be easier to get things going if you start with the system font and switch to a proportional font once you have something working.
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 21, 2009, 01:36 am
Actually, this version is better. Use it. Change the Serial.print stuff to whatever you want to do with your LCD. Enjoy! :)

Code: [Select]
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 16 // Change to your maximum input length
#define BAUD 115200 // Change to your serial data rate

static char * str = NULL;
static int a = 0;

void setup()
{
 str = calloc( MAX_LEN, sizeof( char ) );
 if( str == NULL )
   exit( 1 ); // Kill the program. It never should get here.

 Serial.begin( BAUD );
}

void loop()
{
 // Poll serial
 while( Serial.available() > 0 ) {
   // Get characters
   if( a < MAX_LEN )
     str[a] = char( Serial.read() );
   else
   {
     // Reset vars and clear memory.
       // In this case, the user has entered a message that is too long.
     Serial.flush();
     memset( str, 0x00, MAX_LEN );
       // Handle it right here.
     Serial.println( "Your message is too long." );
     break;
   }
   
   // Increase character index
   a++;
   
   // Wait for serial to catch up. Change as needed. 1 works for me.
   delay( 1 );
 }

 if( strlen( str ) > 0 )
 {
   // The string is valid and an appropriate length. Do something with it.
   // Remember to clear out the string when you're done using it.
   // Your code here.
   Serial.print( "You said: \"" );
   Serial.print( str );
   Serial.print( '\"' );
   memset( str, 0x00, MAX_LEN );
 }

 a = 0;
}
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 21, 2009, 09:04 am
Hi Morgan,

Why are you using calloc?  your code would be 650 bytes smaller if you used a static array.

Also I think digiblue would be better off with a static array that held all the screen characters, something like this:

const int nbrRows = 8;
const int nbrColumns = 21;
char screenBuffer[nrbRows][nbrColumns+1];

that would enable him to scroll the display when he gets to the end of the bottom line by redrawing previous lines one row higher up on the LCD.

There would be a fair amount of work involved in getting this going, perhaps digiblue can start another thread for this discussion so we can keep this one to more general discourse on the library.
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 21, 2009, 09:35 pm
Ok, good point. I forgot to change that in this version :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: maclover201 on Nov 22, 2009, 08:18 pm
Question: Can I modify bitmaps in PROGMEM while the program is executing (before displaying them)?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 22, 2009, 08:28 pm
Data in progmem can only be changed by uploading a new sketch. But you can do things like changing where on the screen the data is displayed.  You can also fiddle with the bits read from progmem before you display them. for example, creating wipe affects by displaying only selected bits (although the library has no specific support for this so you would need to impliment it yourself). What do you want to do?
Title: Re: Graphic LCD (KS0108) library now available
Post by: firebird on Nov 23, 2009, 08:35 pm
Hi all

I've got a MaxSerial Arduino and a GLCD from NKC Elecrtonics (http://www.nkcelectronics.com/graphic-lcd-module-112864.html), and they're working beautifully, thanks to Mem's library.

I've connected the GLCD to the Arduino with the typical headers, wires and the "mini-shield", but I'd like the finished product to be a slightly cleaner installation. A simple solution would be to build a shield, but the wiring from a "Pinout A" panel to the Arduino ports cause a lot of connections crossing each other.

This would be easily solved if pins 4-7 could be swapped the other way around(7-4), and pins 8-11 to 11-8. The picture demonstrates the problem. Is there a way to re-order the pins?

(http://ampli.fi/files/KS0108_wiring_problem.jpg)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 23, 2009, 09:22 pm
Hi Firebird,
currently, if you are using an arduino that only has digital pins 2-13 and analog 0-5 free, your only option is to connect GLCD pins D0-D3  to arduino pins 8-11. You can swap pins D4-D7 to analog pins 0-3 if that helps but the order of any of these pins cannot be swapped around. The valid options are described in more detail in the file named ks0108_Arduino.h.

The restriction is because the library writes 4 bytes at a time using direct port IO in order to get reasonable performance. This is at least 20 times faster than if digitalWrite was used, but the price paid is the limited pin assignment options.

That said, I am working on a new version of the library that may be much more flexible with little if any noticeable drop in performance. I can't make any promises for its availability but if you are not in a rush I may have something for testing in a month or so.
Title: Re: Graphic LCD (KS0108) library now available
Post by: firebird on Nov 24, 2009, 08:26 pm
Ok, I was afraid there might be a limitation like that.

Well, I've still got two options:
- Make the PCB slightly bigger, so I can route the traces around to the other side of the header.
- Jumper wires.

I think I'll muck about with these options for now, but it's good to know that there's a version coming up that allows more flexibility with regard to pin assignment.

Thanks!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Nov 24, 2009, 08:46 pm
I would be interested in hearing views about the tradeoff between flexability and performance. If the display was 20% slower when pins were assigned in any sequence (compared to using the existing limited pin assignments), would you still want to use that capability?
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Dec 03, 2009, 08:52 pm
Michael,
I think people need to know that that 20% trade-off for arbitrarly assigned pins cannot be worked around.
And that the 20% slow down is not 20% from the current code
but 20% from code that they don't have yet, which is faster than what they have.

Also, that this 20% slow down is only when using a pin configuration that currently is not supported, while when using any currently supported pin configuration, the code is the same speed or faster.

For those tracking this:
Things simply work faster when the i/o is more streamlined and
when the data pins are clumped together as nibbles or as a full byte inside of AVR registers.
The amount of instructions needed to access the pin data is dramatically different.
For example when all 8 pins are on the same register, it is single read/write.
When clumped as nibbles, it is 2 reads/writes along with some oring and possibly shifting nibbles if the nibbles are swapped within the AVR registers.
When pins are spread out all over the place, there can be a read/write for each pin and data bits have to be set/cleared for each bit.

So as you can see, there are simply more instructions when the data pins are not aligned with AVR bytes/nibbles.
All these extra instructions start to add up.

The multi-bit avr direct pin access code I've done is now being used to handle all the multibit i/o for the GLCD library code.
It handles all this transparently for the user and they can now select any pin for any function with no limitations. The user simply defines the pin for each glcd function. (still done at compile time vs runtime)
The multi-bit avr code can and will "automagically" figure out if pins are in related nibbles or in a single byte. It can then take advantage of pin configurations that use nibble/byte aligned pins, but there will always be a performance cost when the data pins are not aligned with nibbles/bytes. The code will generate the least possible amount of AVR instructions to handle this all the way down to single AVR instructions when possible, but there is no way around the additional overhead when pins are not aligned.

That said, the other modifications I've done to the low level driver access to the GLCD are now much faster so that even if pins are assigned totally randomly, the worst case overall speed with no nibble or byte alignment should not be any slower than it was and some cases will be faster. Byte and nibble aligned modes should be faster than before.

Micheal and I are still testing and finalizing this code and are right in the middle of putting in support for other displays like SED1520/VK5121.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Dec 05, 2009, 03:47 am
For some reason, the GLCD.CursorTo function isn't moving the text  :-?

I'm trying to create something like this on the LCD:

(http://i270.photobucket.com/albums/jj105/kenkassidy/display.jpg)

I have the graph worked out, I just can't seem to get the text in the right spot :(

Any help?
Code: [Select]
#include <ks0108.h>  // library header
 #include <Arial14.h>  // font definition for 14 point Arial font.
 #include "SystemFont5x7.h"   // system font
 int count = 0;
void setup(){
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted turns on written pixels
 GLCD.ClearScreen();  
 GLCD.GotoXY(0,0); // locate the graphic cursor at positions x and y, 0,0 is upper left corner
 GLCD.SelectFont(Arial_14); // included font, you can also make your own fonts  
 GLCD.DrawRect(0, 0, 70, 63, BLACK);
 GLCD.DrawLine(0, 60, 10, 16, BLACK);
 GLCD.DrawLine(10, 16, 20, 18, BLACK);
 GLCD.DrawLine(20, 18, 30, 28, BLACK);
 GLCD.DrawLine(30, 28, 40, 20, BLACK);
 GLCD.DrawLine(40, 20, 50, 40, BLACK);
 GLCD.DrawLine(50, 40, 60, 10, BLACK);
 GLCD.DrawLine(60, 10, 70, 17, BLACK);
 delay(200);
 GLCD.CursorTo(120, 100);
 GLCD.Puts("138mW");
 }
void  loop(){   // run over and over again

}

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Dec 05, 2009, 05:52 am
CursorTo is only for the fixed width system font. Use GotoXY to position the cursor for proportional fonts like Arial14.

You can use GotoXY for the fixed width font if you want.

To  convert from CursorTo coordinates to GotoXY coordinates, multiply the CursorTo column by 6 and the CursorTo row by 8. (the font is 5 by 7 with a single vertical and horizontal space between columns and rows)

For example GotoXY(96,40) would position any font at the same place as CursorTo(16,5) would position the system font.
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Dec 05, 2009, 05:55 am
What display are you using?
That's a mighty large col,row position you are trying to send your text to: 120,100

That is the equivalent to x,y position: 120*10, 100*14
or 1200,1400 probably not what you meant.

CursorTo(col, row) sets the character rendering x,y position
to the equivalent row,col text position.
X = col * font width
Y= row * font height.

If you really want x,y coordinates then simply
use GotoXY() instead. All CursorTo() does is calculate  X and Y values and then call GotoXY() for you.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Dec 05, 2009, 06:10 am
Arial_14 is a variable width/proportional font.

While CursorTo() is best used with fixed width fonts like the system font, it  can be used with proportional fonts.

The thing to to keep in mind is that there really isn't a clear notion of
what a text character "column position" is when using a proportional font because each character is not the same width.

The CursorTo() routine calculates its X coordinate based on the maximum width of the characters in the selected font.

As long as you keep that in mind you can use it with variable width fonts like Arial_14.
However, it probabaly makes more sense to use direct X,Y addressing
for variable width fonts.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: Things on Dec 05, 2009, 06:11 am
Those values in CursorTo were just me testing if it was moving at all, the GotoXY thing worked.

Thanks :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Dec 20, 2009, 06:08 am
Hello,

Did anyone tried to modify this Graphic LCD library ( KS0108) to make it work on ST7565 lcd controllers or equivalent?

I found this lcd controller is very common, and other similar lcd controllers are like KS0713 or NT7534.

I have coded a very simple program to test the lcd module, and can initialise it and display some simple data.

Cheers
Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Dec 20, 2009, 11:33 am
Hi Joseph,
There is a new version of the GLCD library under development that will be much easer to adapt to other lcd controllers.

I hope to have a beta version available early in the new year and although it probably wont work with the KS0713, SED1565, ST7565 family out of the box, it will be much easier to adapt than the current library.
Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Dec 21, 2009, 04:20 am
Hi,

I see. So in the meantime, I would try to play with this KS0108 library, maybe trim it down a bit just to only support my specific LCD module and my Arduino DM board, and make it work.

I love the graphics drawing features in this library, and would be great it can support more types of lcd controllers  :)

Cheers
Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Dec 21, 2009, 10:53 am
Joseph,
Not that this solves your immediate need but
support for the SED1520/21 chip has been added and is working.
The new config files provide a much easier way to configure all the lcd pins.
There has been a considerable amount of "under the hood" changes/updates to the low level i/o code that makes it much easier to add support for new devices.

Joseph, there were a couple of things in the ks0713 spec that were not quite clear to me. If you managed to get it inited, then that will tell me what I need to know to fix this in the library.
I'll PM you my email address so we can start to exchange information.

Michael, I'll go back and take a look at the ks0713 support to see if I can figure out why it isn't working. I'm sure it is probably something fairly simple. (hopefully not something like accidentally using the avr uart pins....)
It seems to be the same interface as the ST7565 so once the ks0713 is up and working the ST7565 should be right there as well.

--- bill



Title: Re: Graphic LCD (KS0108) library now available
Post by: mobyfab on Dec 22, 2009, 12:23 am
hey mem,

so about that contrast issue, I'm not good enough to fix it by myself, but you could find some answer. :)

for some reason, as soon as I'm drawing rectangles which are using more than one half of the screen, the contrast goes very low.

if I set the LCD to update every 200ms, it goes "black" (empty) in between.
that may explain the low contrast at high speed.

strange thing, because if i only display text or a rectangle on one half (controller) only, it doesn't blink and contrast is just fine.
Title: Re: Graphic LCD (KS0108) library now available
Post by: spatialguru on Dec 31, 2009, 09:30 pm
Quote
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.


Working with same LCD as tyggerjai and feeling close :)  I don't see "ifndef PUBLISH" in the ks0108.h file.  Did I download the wrong version somewhere?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Dec 31, 2009, 11:22 pm
Quote
Working with same LCD as tyggerjai and feeling close   I don't see "ifndef PUBLISH" in the ks0108.h file.  Did I download the wrong version somewhere?

the post was referring to the very first code release,  that define has been eliminated in all releases available over the last year or so.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Dec 31, 2009, 11:24 pm
mobyfab, Sorry I did not see your post sooner but I am not sure what to suggest. I have not come across that problem before, perhaps someone else here has.
Title: Re: Graphic LCD (KS0108) library now available
Post by: spatialguru on Dec 31, 2009, 11:41 pm
Okay, thanks mem.

After wrestling a bit with understanding how to set the contrast, I've had great success with using this lcd:http://futurlec.com/LED/LCD128X64.shtml
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Dec 31, 2009, 11:48 pm
spatialguru, Good to hear that. Did you need to change the code to get that panel working?
Title: Re: Graphic LCD (KS0108) library now available
Post by: spatialguru on Jan 01, 2010, 01:57 am
No changes whatsoever... I'm thrilled :)  Now just starting to hunt for any other code examples to do cool stuff ... any pointers welcome :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 02, 2010, 10:31 am
loving this lib :)

making a analog value appear in a rounded rectangle in comic sans and watch it change as u move a pot shouldnt be this fun XD

one thing tho..

is it possible to put many bitmaps in one header file to store as animation frames, if so, how would i go about this?

It would be a bit messy doing an #include for each bitmap frame wen u could just include one file containing all the frames.
then it would just be a matter of including the anim_name.h and then glcd.drawbitmap anim_name_name for each frame, or another method if someone knows an easy way to add in a GLCD.animate function to the lib :3 (hint hint :P )

either way awesome work :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 02, 2010, 10:48 am
A GLCD bitmap consists of an array of characters - two bytes indicating the width and height followed by bytes defining the pixels. A 64x128 pixel bitmap requires 1026 bytes.

Header files can include other header files so you can have one header that includes all the individual header files for each frames.
Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 02, 2010, 01:34 pm
so u say i can make a folder for the frames header files and then make a single header file for them to use in the sketch.

do u have an example syntax i can use for this? as im not too familiar with how to arrange a header file like this.. i have looked at the data inside the bitmap files when i tried making one containing bitmap data for 2 frames as a test.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 02, 2010, 02:02 pm
You can create a subdirectory under the ks0108 library directory, perhaps  named  'bitmaps'.

Create header files for each frame in this bitmaps directory. For example:
Code: [Select]
/* frame1.h bitmap file for GLCD library */

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef Frame1_H
#define Frame1_H

static uint8_t Frame1[] PROGMEM = {
 64, // width
 64, // height

 // pixel data goes here....
 
};
#endif

Code: [Select]
/* frame2.h bitmap file for GLCD library */

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef Frame2_H
#define Frame2_H

static uint8_t Frame2[] PROGMEM = {
 64, // width
 64, // height

 // pixel data goes here....
 
};
#endif



Create a header file in the main ks0108 directory that includes all your header files for the frames:
Code: [Select]
/* frames.h bitmap file for GLCD library */

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef Frames_H
#define Frames_H

#include "bitmaps/frame1.h"
#include "bitmaps/frame2.h"

#endif



You sketch code would look something like this:

Code: [Select]

 GLCD.DrawBitmap(Frame1, 0,0, BLACK);
 delay(30);
 GLCD.DrawBitmap(Frame2, 0,0, BLACK);
 delay(30);


if you need more help getting this going, perhaps create a new thread on the topic of bitmap animation so that this thread can focus on basic help.
Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 02, 2010, 06:57 pm
thanks :) i'll give that a go :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jan 03, 2010, 08:44 am
On the bitmap animation. Until the new library is out, you will need to make sure that the bitmaps that you use are multiple of 8 pixels in height and more importantly that the y coordinate is a multiple of 8. Otherwise the bitmap data will be ORd into the existing data on the LCD rather than re-written.
This means that LCD pixels in subsequent images will be turned on but the pixels that are off in the new images will not turn off the pixels on the LCD.

Just make sure that the y coordinate and the the height of the bitmap are even divisible by 8.

For example, if you have several bitmaps that compose an animation and it is 32x32 then if you start it at 0,0  or 1,0 or 2,0 or 9,8 or 11,16 etc... it will work just fine.
However, if you start it a 0,1  or 0,5 or 11,7  etc... then it won't work properly because the y coordinate is not a multiple of 8 and the bits within each image will turn on pixels but leave the pixels from the previous images on as well. So the image area will get "blacker" and "blacker" as more images turn on more pixels.


There is a simple 2 line patch to the library function DrawBitmap() that can remove (fixes) this limitation.

If you want to patch the library code yourself (which I recommend as it is very simple fix), then you will need to insert these 2 lines into the function DrawBitmap() in the ks0108.cpp file.

Code: [Select]

 if( (y & 7) || (height & 7))
   this->FillRect(x, y, width, height, WHITE);


These to lines go inbetwen the two lines below as follows:


Code: [Select]

 height = ReadPgmData(bitmap++);
 for(j = 0; j < height / 8; j++) {


It should look like this:
Code: [Select]

 height = ReadPgmData(bitmap++);
 if( (y & 7) || (height & 7))
   this->FillRect(x, y, width, height, WHITE);
 for(j = 0; j < height / 8; j++) {



This will clear the rectangular area of the bitmap, when needed, before the new bitmap is painted  so that the pixels that should be off will be off on the LCD when the new bitmap is painted.

--- bill

Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 03, 2010, 06:33 pm
thnx added that fix and ure info also answered a problem i was having with a sprite i was trying to make but the processing converter wouldnt work.
turns out the height was 60 pixels and i had to add 4 more.

just wondering would it be complicated to store bitmap data in the eprom rather than in the flash? if im thinking right. to make more space for the program. i had a large anim that took up more space than was available (prolly would have fit on a 328), was ok cos i just halved the frames.
but they do tend to waste space that can be used for other things mebe..

just a thought.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 03, 2010, 07:20 pm
Yes you could store bitmap data in EEPROM, although there is only space (on the ATmega328) for one screen full (1k).  

You would need to add code in your sketch along the lines of the DrawBitmap function but reading  from EEPROM instead of Flash
Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 03, 2010, 07:39 pm
so if u were to make some kind of mini game that had lots of graphical components (sprites, scenery) then u would need some kind of external storage for them..
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jan 04, 2010, 03:14 am
With the patch to DrawBitmap() you shouldn't have to increase the height to a multiple of 8. Are you still seeing bitmap drawing issues after the patch in place? i.e. does your 60 pixel tall bitmap work after the patch?


Reading bitmap data from eeprom isn't difficult as Michael pointed out.
What may be a bit tricky is to get the bitmap data into eeprom.
If arduino used normal makefiles, you could easily update the flags and rules to force certain data sections or variables into a section that then could be forced to the eeprom.
I have no idea how the Arduino IDE works with respect to linking
or how the arduino IDE does its downloading and if it will allow you write to EEPROM as part of the upload process.

I've tried to use avrdude to write to eeprom and there is
an incompatibility between the arduino/adaboot bootloaders and the way avrdude wants to write to eeprom.
While the bootloader supports writing to eeprom, avrdude uses an older pasthrough mode that the bootloader does not support.

For space savings, if possible crunch down the bitmaps to the smallest rectangle possible to eliminate excess "white space" along the edges.

Another good space saving trick is to avoid any/all floating point.
That quickly can save you 1-3k of space. The trick that *all* floating point
must be avoided and even though you might not be doing a floating point operation a "library" might be doing a floating point operation
somewhere in its code.

For more flash space room, 328 is a nice easy upgrade if you
have the DIP version,
and if you really want some room, you could jump to something like a teensy++ and then have 128k of flash space.

--- bill

Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 04, 2010, 10:12 am
the 60 pixel high problem wasnt with the lcd lib, it was with the processing sketch that converts them, it just threw up an error wen i ran the thing, but wen i extended the bmp file to 64 px high it converted without complaint.

i believe the fix worked. for the lib anyway, tho my last anim had the other 2 frames wider than the 1st so they left parts outside the boundery of the 1st. nothing a clear screen didnt fix.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 04, 2010, 11:36 am
One way to load EEPROM with image data on the arduino platform is to write a simple 'loader' sketch to read the data from one or more header files and write each byte to EEPROM.

pgm_read_byte(address);  returns the byte at the given address, see:
http://www.arduino.cc/en/Reference/PROGMEM

eeprom_write_byte( address, value); writes the given value into eeprom at the given address

in your runtime GLCD sketch, use:
eeprom_read_byte(address);  returns the value in eeprom at the given address

You will probably need these includes in your skethches:
#include <avr/pgmspace.h>  // for progmem
#include <avr/eeprom.h>     // for eeprom

Make sure your 'loader' sketch only writes the EEPROM values once (you don't want loop constantly rewriting  eeprom values over and over !)
Title: Re: Graphic LCD (KS0108) library now available
Post by: The_Bongmaster on Jan 05, 2010, 02:43 pm
hmms that will have to wait til i know more..

in the meantime i will have to work out wat i can do with it :3
Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Jan 13, 2010, 12:36 am
Hello,

I have a question of ksSOURCE defined in ks0108.cpp

May I know the purpose of such define?

in line 36:
#define ksSOURCE
#include "ks0108.h"

Cheers

Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 13, 2010, 01:02 am
Joseph,

Its used because there are defines in the ks0108_Panel.h file that are handled differently when the library is compiled than it is when that file is included in the sketch.

Title: Re: Graphic LCD (KS0108) library now available
Post by: rgc on Jan 18, 2010, 07:27 pm
Hello,

Newbie here running the GLCD display from Adafruit with the KS0108 library.  Worked perfectly with Duemilanove (168 and 328) and now with Mega using big (30pt) font.  Thanks to all for your hard work (and sharing).

My end goal is to run two independent displays simultaneously.  The easy question is...has this been done?  Lots of searching makes me think that it hasn't.

If two GLCDs can be run, the next question concerns pin assignments.  The novice in me thinks that I could change the defines and the pin assignments in the header files to create new header files.  This looks straight forward for the command pins (33-37), but not so for the data pins (22-29). I've also learned that this this stuff is never straightforward as first thought.  Any help/guidance would be appreciated.  Thanks.  

Bob
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 18, 2010, 08:05 pm
Hi Bob, I don't think it has been done with the Arduino library and although possible, it I don't think it would be easy.

Have you considered using two boards, each driving a Display and connect them up using serial or I2C?

If you want to go the multiple arduino board route, or look at trying to get drive two displays from a single mega then then I suggest waiting a little while for a new version of the library that is easier to interface and has more functionality. The code is being finalized over the next few weeks and I hope to have a release for testing in February.

There is a serial interface that is not part of the release but could be developed to remotely drive one or more displays if someone was inclined to pick this up.

Driving two panels from one Mega may be easier with the new library but its still going to be tricky because the port io makes heavy use of compile time optimization and with the current code it is not easy to compile two instances of the low level driver in the same sketch.
Title: Re: Graphic LCD (KS0108) library now available
Post by: rgc on Jan 18, 2010, 08:39 pm
Hi Mem,

Thanks for the quick reply.  Hearing you say it wouldn't be easy makes me think that it would be impossible.  I will wait patiently (and anxiously) for your new library.  Will that be announced here, playground or both?  

My application is not, I don't think, very CPU intensive.  I am reading a serial stream, an array of <50 bytes, coming in at up to 115200baud (using 9600 now).  This stream is sent as-is to a VDIP1 to write to a USB stick.  Certain variables from the array are parsed, calculations performed, and sent to the GLCD at a ~5Hz refresh.  I can show two large values per screen and would like two screens.

I considered using character LCD's but couldn't find a large/clear font suitable for a race car dash.  Should I revisit the character LCD display option?

Perhaps using another board is a good alternative.  Thanks Again.  Bob

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 18, 2010, 09:49 pm
I suggest you consider the two board option. Something like the Modern Device RBBB kit for $12.50 would be more than adequate to drive the second display.

If you are only displaying text then the code to handle the inter-board communication is relatively easy because you don't need to send all the graphics commands.

For this application it probably makes little difference using the current or new library.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Fratsen on Jan 21, 2010, 02:57 pm
I've been using this library for a couple of different projects. Thanks!

For my latest project, I needed to free up 1 IO port..

I did this successfully by removing the CSEL2 connection and replacing it by a signal inverting circuit triggered by CSEL1 (very simple, 1 transistor and 2 resistors)  I commented out all CSEL2-code in the library and it worked all perfectly fine!

I'm willing to help anyone who's also just 1 IO port short to do the same! Just send me a PM.. If I find some time later on, I'll type a quick howto.
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jan 22, 2010, 09:27 am
As far as supporting 2 two displays with 1 AVR/board. Unfortunately, currently the data structure memory is not dynamically allocated and
there is only 1 instance of the information.
That could be changed, but right now the focus has been on other things:
speeding up the level code, adding new text capabilities, aligning the API calls with JAVA graphic API calls, adding in support for additional glcd chips, and making the configuration of pins much much simpler.

Here is a thought....
I think it would be easier to "trick" the code into thinking the display was one 256x64 module rather than than two 128x64 modules.
Since the code already knows how to deal with multiple chips on a module (128x64 modules have 2 chips), all that would be necessary is to trick it to thinking the two displays were a single larger display with 4 chips.
The nice thing about the ks0108 chip is the all the lines are tri-stated and ignored when a chip isn't selected.
So that means you can hook all the pins from both displays together and share all the pins other than the CSEL lines.

So to support a 2nd display would only need 2 more i/o pins.
Or it could be done with one i/o pin if there was a a tiny amount of external circuitry to mux the 2 CSEL pins between the two modules.
It would also require a small mod to the code to use
more than 2 CSEL pins.

If a 1 of 8 external decoder chip was used, so the AVR fed its CSEL i/o pins into the decoder which in turn drove the GLCD CSEL pins,
that would support up to 8 chips or four 128x64 GLCD modules with only 3 AVR i/o pins.
Or only 1 more pin than what is required for a single module!


But that will have to wait until we get other things of our plate.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: Fratsen on Jan 22, 2010, 06:06 pm
Since you only want to write to 1 chip at the same time, a 2-bit binary decoder could drive 4 CSEL pins (= 2 LCD's) with only minor changes to the chip-select part of the library code. (and using no more than 2 IO ports needed, so equal to the original library)

see: http://circuitscan.homestead.com/files/digelec/combination1.htm for an interactive visualisation of how such a 2-bit decoder works
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 22, 2010, 06:17 pm
Driving the chip selects is the easy part. However RGC says he wants "to run two independent displays simultaneously"
If that is indeed what he wants to do then there is some non-trivial software work needed to manage the state of the two displays.

I would be interested to hear more about RGC's application and how the two displays would be used.
Title: Re: Graphic LCD (KS0108) library now available
Post by: rgc on Jan 22, 2010, 07:24 pm
mem, I am working in the two board option, as you suggested.  I actually think that this may be an easier approach and will afford benefits in addition to controlling display #2.

My application involves my track car.  I am developing an integrated engine management / dash display / data logger.  I have been using a diy engine management system (MegaSquirt or MS) for a few years.  The plan is to add a GPIO that will communicate with MS via CAN.  MS will then send a serial stream to Arduino Mega where the data will be parsed, calculations performed, and sent to the GLCD's.  In addition, if invoked, the raw data will be written to the VDIP1.  This is all operational on the bench presently.

The reason for GLCD rather than text is the need for huge font - I am displaying only two variables on a 128x64 display.  The plan is to have two displays flanking a central tachometer, showing a total of four variables.  There will be push buttons next to the displays to select which of the 8-10 relevant variables to display at that spot.

The purpose of all this is to be able to closely monitor and datalog parameters from a fully instrumented race motor.  Just a fun hobby/obsession that eats all my spare time.

Thanks to the likes of you and the rest of the Arduino community I have been able to dust-off my ancient (by now) skills in electronics and programming, and get all this stuff "working" in short order.  Thanks again for sharing your knowledge.

Bob
Title: Re: Graphic LCD (KS0108) library now available
Post by: Ran Talbott on Jan 23, 2010, 04:18 am
Quote
The reason for GLCD rather than text is the need for huge font - I am displaying only two variables on a 128x64 display.


If you only want big fonts,  why not use something like this 7-segment LCD (http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=170285967514),  or some big 7- or 14-segment LED arrays?

Title: Re: Graphic LCD (KS0108) library now available
Post by: rgc on Jan 29, 2010, 10:44 pm
Hi Ran,

I considered an LCD like that, or using a big-font library for a 4x20 LCD or something, but in all cases I was dissatisfied with the font quality/legibility.  The need is for large, clear fonts that can be read with only a quick glance.

I searched for a while and didn't find a character LCD with big (12-15mm) font size.  If there's one out there, I'd like to hear about it.  Thanks.

Bob
Title: Re: Graphic LCD (KS0108) library now available
Post by: steve325 on Jan 29, 2010, 11:04 pm
Hey guys,

First of all, thank you all for your time and assistance in advance.

I'm new to this forum and relatively new to working with the Arduino in general, but I've been following this thread for quite some time in the hopes that I can get my Duemilanove successfully talking to my graphic lcd screen. For starters I'll just fill you in on some of the details of my setup. I'm using a Duemilanove with the Atmega 328 processor and a Sparkfun 128x64 STN backlight graphic lcd (PN: LCD-00710, type A pinout). I have a 10k pot for contrast adjustment and a 150ohm resistor hooked up for the backlight as per the datasheet. Everything is connected on a solderless breadboard and powered with a 5 volt regulated supply. All in all, I think it's a pretty standard arrangement.
     However, the only thing I can get to come up on the screen when running the test sketch is a garbled mess. From what I've read, this seems to be a timing issue requiring the delay value in the panel's H file to be increased. I've tried to edit the ks0108_panel.h file to increase the delay value in the EN_DELAY line, but I don't think it had any effect. I know that a file with a ".o" extension needs to be deleted after any of the library files are modified, but which file is it? I found files with the .o extension in the applet folder in the sketch folder, and also a few others inside the ks0108 library folder. However, all of these files end in ".cpp.o". Is this the extension that I'm looking for? Which one(s) need to be deleted?
     I know this is a lot of questions for one post, but I'd really like to get this figured out, it seems like it should be pretty easy based on other posts. Please let me know what you think, maybe you guys can clarify some of the mysteries with the library files. Thanks again.

-Steve
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jan 29, 2010, 11:32 pm
Steve, if you are using Arduino 0017 then you no longer need to delete the .o files - this happens automatically when you rebuild your sketch.

Perhaps if you post a picture or video of the display there may be some clues for what is going wrong.
Title: Re: Graphic LCD (KS0108) library now available
Post by: steve325 on Feb 01, 2010, 10:21 pm
Hey mem,

Thanks a lot for the prompt reply and info about the different procedure for Arduino 17. I'd like to post a short video of the display that I can produce, but unfortunately I seem to have killed my screen. I had it connected to 5 volts as per the diagram with the recommended resistors controlling contrast and backlight current. Then, all of the pixels went to solid black and soon after smoke started coming from under the screen module. I've been working with electronics for years, and i'm reasonably certain that everything was connected correctly. I'm not sure what to suspect because the lcd operated normally (albeit with garbled pixels) for a half hour or so. While I wait for a new one from Sparkfun to try again, do you have any recommendations in the meantime?

-Steve
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Feb 06, 2010, 09:49 am
Wow, actual smoke. Usually that takes quite a bit of current. Did you check the pot to make sure it wasn't shorted and was the proper value?
with the wiper going to VO (pin 3).
There isn't much that can drive that much current other than the power lines. Maybe if something goofy like the E line was stuck on and the AVR was fighting the LCD on its data lines.


Not something goofy like the pin numbering backwards?
If I remember from the picture on the SparkFun site there aren't pin #s on the board. Just a square marker for pin 1.

Was the LED backlight working?

What voltage were you running things at?

I'd be happy to look over the connections if you think another set of eyes would help.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: steve325 on Feb 07, 2010, 03:42 am
Bill,

It turns out you were right about the power lines being the only thing that can supply screen-killing current levels, I seem to have misinterpreted "Operating Voltage for LCD" as meaning 5 volts when I was looking at the datasheet for the screen. However, the handy table provided on the library page clearly shows that pin 3 is the wiper of the contrast pot as you recommended. I suppose this solves the smoke issue, without the kohm-magnitude resistance between pin 3 and 5v wayyyy too much current would pass. I guess I'll triple check my wiring against the table when I get my new screen next week. Then I'll be back to troubleshooting the garbled display. Thanks for the advice, I appreciate it.

-Steve
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Feb 07, 2010, 07:48 am
Steve,
Good find.

I just went and looked at the glcd datasheet on the sparkfun site again.
I've looked at many of these lcd data sheets and nearly all of them
have things that are confusing and in some cases wrong.

That datasheet is confusing on the pin connections table on page 3 for
pins #3 and #18.
The VEE signal (#18) is a fixed negative voltage output
while the VO line (#3) is a variable voltage input yet both are described the same in the table.

See page 9 of that data sheet for how to hook up the contrast control pot.

I'm sure we can help you get the display up and going.

--- bill

Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Feb 07, 2010, 04:08 pm
I have a question about this library.

First of all, i have built it with 2 different GLCD's and it works geat.  Thanks to those who contributed to all of this.  I have an idea in mind that would require that I need 4 analog pins (to read some Voltages) and still a couple of Digital IO's...

Problem is, the ATMega328 is quite limited when the GLCD sketch is also used.

I would like to use a keypad with my sketch a well, (not matrix, but up down left right clear and enter) If I were to cram all of this on an arduino, I would have to somehow move pin assignments from Analog to digital ones, and then use multiple buttons on 1 analog pin...ect.  I have no idea how to do that (change pin assignments), or if it is even possible because i read that they have to be assigned to the same port.  

The other possibility is to use another arduino and somehow use the rx/tx lines to communicate with each other and send values back and forth.  The LCD will be used to graph the voltages on the screen over a period of time, so im not sure if serial communication is best suited for that.

This whole setup will be used to watch different voltages and currents coming from a Power supply.  the outputs are displayed on the GLCD and the keypad switches between screen modes

Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 07, 2010, 05:05 pm
The command pins that are assigned to the Arduino analog pins can be assigned to any unused arduino pin. Read through the section titled 'Changing the Arduino Pin Assignments' for instructions on how to move these from the analog pins to an unused digital pin.  See: http://www.arduino.cc/playground/Code/GLCDks0108

For example, if digital pins 2,3, 12 and 13 are free you can change the ks0108_Arduino.h file as follows:

#define CSEL1   2 // was 14 (Analog pin 0)
#define CSEL2   3 //was 15 (Analog pin 1)
// digital pins 4-11 are used for display data
#define R_W     12 // was 16 (Analog pin 2)
#define D_I     13 // was 17 (Analog pin 3)

//The next pin is unchanged because there no more digital pins free (if you use serial)
#define EN      18 (Analog pin 4)

That leaves analog pins 0-3 and 5 free to use as analog or digital ports.

If you need more than that you may want to consider using a Teensy board: http://www.pjrc.com/teensy/teensyduino.html

It has lots of pins and there is a download for the glcd library ready to use with this board.
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Feb 08, 2010, 12:04 am
that will do, thanks...

I remember reading that they have to be in the same port...I wasnt sure exactly what that meant...but if it works, what you posted should work great


Thanks
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 08, 2010, 05:54 am
Good to hear you have it going.
The documentation in the playground does say that you can split pins across ports. There is no significant disadvantage in using the connections suggested above.
Quote
Ideally the command pins should all be on one port and all the data pins together on another. In practice this is not easy to do on a standard arduino. If you split command pins or data pins across ports the code will run slightly slower, but for all but the most speed critical graphic applications its not significant.

Title: Re: Graphic LCD (KS0108) library now available
Post by: vicma on Feb 09, 2010, 05:51 pm
hello!

i follow the Example GLCD sketch in playground, but not luck.  my Panel is Pinout B and i use duemilanove. i try to change the "#define EN_DELAY_VALUE 2" in ks0108_panel.h, but the panel sill no working. some one could help me ..... :'(
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 09, 2010, 06:14 pm
vicma, check that all data and command pins are wired correctly, this is the most common cause of problems. Reading through this thread you may be surprised how many people were convinced that everthing was wired correctly only to discover that fixing a bad connection or misplaced wire fixed the problem.

Also check contrast voltage (typically between -3 and -4 volts) on contrast-in pin of LCD panel. While the sketch is operating, try gradually adjusting the pot through its range. Some displays are very sensitive to this setting.

Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 09, 2010, 08:25 pm
Hi all,

I bought these:

http://www.sparkfun.com/commerce/product_info.php?products_id=710

http://www.sparkfun.com/commerce/product_info.php?products_id=8977

http://www.sparkfun.com/commerce/product_info.php?products_id=9170

And, I read this information:

http://www.arduino.cc/playground/Code/GLCDks0108

and this topic regarding this LCD and the above mentioned code.

From what I gathered, it seems that the LCD Library should work with this LCD.

I have not worked with LCDs or Touchscreens, but I think I have the basic idea here.

Here is what I want to do:

I want to create a menu-driven interface on the LCD, but instead of using tactile pushbuttons to select the menu options, I want to use a touch screen.

So the touchscreen is basically a set of invisible buttons that are laid over the LCD.  When a person touches a particular location of the touchscreen, the program interprets that as a button press and it executes the routine associated with that button press.  To the user, it appears that they are actually pushing the pseudobutton on the LCD.

So, as the user navigates through the various submenus, the information displayed on the LCD will obviously change, and if they need the ability to select options on those submenu screens, then the touchscreen "buttons" will have to change position accordingly, right?

So, here are my questions:

1. Will all anticipated softbuttons on the touchscreen have to be defined seperately, or can you reuse certain button definitions in more than one routine?

2. Can the code for the touchscreen and the LCD be contained in the same routine, or would it be better to separate them into two different functions so that the touchscreen inputs change the LCD outputs and relocate the touchscreen softbuttons?

3. I will be prototyping with a Mega, and then converting it over to a smaller Arduino once I have it working (possibly a Nano, or similar).  Is there any issues with doing this?

This LCD/Touchscreen combination will be used to improe a circuit I designed for work.  The current circuit utilizes DPDT switches and rotary switches to select various test cases, but I want to convert it over to use relays in place of the switches and a LCD/Touchscreen to toggle the correct relays for the desired test.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 09, 2010, 09:09 pm
Wiley, cool project and it all sounds doable.

The touchscreen needs two analog inputs and that will not leave many pins free after connecting up the LCD, what is it that you want this to control?

There are many ways you could implement the menus, which one to pick will depend on the complexity of the menu structure and your programming knowledge.

I think this project deserves its own thread, why not start one up and put a link here so people can find it. Perhaps there you can say more about your thoughts on the menu structure and give an indication of your experience writing arduino code.
Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 09, 2010, 09:27 pm
OK, thanks.  I will start a new topic in "Interfacing."

I guess I wanted to be sure that the latest library posted in the playground is current and will work for the LCD I purchased.  In addition, I wanted to know if there was going to be a problem migrating the final sketch and design to another, smaller Arduino like the Nano.

By the way, I read all 22 pages of this topic, and you did a very fine job, mem.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 09, 2010, 10:28 pm
The nano should be fine if it has enough pins for everything you want to do. Another option is the Teensy or Teensy++ if you need lots of pins in a small form factor: http://www.pjrc.com/teensy/teensyduino.html

I have not tried the sparkfun panel but I can see no reason why it would not work.
Title: Re: Graphic LCD (KS0108) library now available
Post by: ARDX.eu on Feb 09, 2010, 11:28 pm
Anyone knows whats wrong here?
I used the example sketch (and tried some others),
I use pinmode B.

http://twitpic.com/12a7ld/full

thanks!
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 09, 2010, 11:49 pm
it could be a timing problem, you could try increasing EN_DELAY_VALUE
in ks0108_Panel.h

Title: Re: Graphic LCD (KS0108) library now available
Post by: ARDX.eu on Feb 09, 2010, 11:55 pm
Thanks for the suggestion;
Tried that before (and tried it just now again with different values) but it doesn't seem te help...

== EDIT ==

Got it fixed!
Made a stupid wiring mistake;
Pin 18 should connect to Pin 3 (wiper) in stead of to a custom 25kohm resistor. :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Feb 10, 2010, 02:46 am
Ok, in my previous post, there was a need for the analog pins, and the person that responded tole me to change the pin assignments in the .h file.

I have done this as described.  here's what happens...

The screen initializes and i see the Arduino Logo, and it appears perfect.  Then when the character library screen comes up, it seems like they are cut in half from top to bottom.  Then when the next screen comes on (with FPS) it looks like it was cut and reversed horizontally...

The left and right sides are on the correct sides...but it looks like what should be in the top left corner, is in the horizontal center to the left.

this may sound strange...i wish i could show a pic.  

but i dont get it, the beginning image is fine!
Title: Re: Graphic LCD (KS0108) library now available
Post by: Metalfan1185 on Feb 10, 2010, 03:46 am
I got it...


There was another option in the .h file that says to uncomment if pins are from same port...but this was uncommented bydefault, so i simply commented it and it works great yet again


thanks
Title: Re: Graphic LCD (KS0108) library now available
Post by: vicma on Feb 10, 2010, 06:52 am
hi mem

this is my  Panel and duemilanove. i check Pinout B so many times, but the panel only show all black(Contrast). does  i miss something in "KS0108 Graphics LCD library"...  :'(

http://picasaweb.google.com.tw/lh/photo/5j8BnZ79hw-4mBJ7jkSCHQ?feat=directlink
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 10, 2010, 09:15 am
Its difficult to see where all the wires are going in that picture but it looks like nothing is connected to analog pin 1. If you use the standard wiring this should be connected to the panel chip select pin 16.

Recheck that all the wiring matches the info in the playground.
Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Feb 10, 2010, 02:52 pm
Hello,

I am now using the drawbitmap function, and just wondering if there is any sw tool to convert an ordinary bitmap file (.bmp or .xbm) into the data format suitable for it.

Cheers
Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 10, 2010, 03:47 pm
Joseph, you can use an ordinary graphical drawing package (like windows Paint) to read a file and save as a monochrome bmp file.
The utility that creates the bitmap header file is written in Processing and included in the library download. In the current release this utility is primitive and the height of the source bitmap should be an even multiple of 8.

Any Java programmers out there with some time to polish of the rough edges of the utility would be very welcome
Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Feb 10, 2010, 09:24 pm
Thanks again Mem,

I just googled and found there's a project in sourceforge which is doing similar kind of conversion.

It is using g++ instead of using "Processing"

Let's see who can help to re-code it for Arduino.

http://fr.sourceforge.jp/projects/sfnet_bmp2glcd/releases/

This sourceforge project doesn't seem to have any limitation on heigtht of source bitmap file

:) :)

Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Feb 10, 2010, 10:37 pm
You can use Sami's bmp2glcd program as is.
The limitation is that it does not insert the width and height into the data structure before the bitmap data starts, which is what the glcd library wants.

You can either manually insert the width and height bytes into the
data array, or modify the bmp2glcd code to do it automatically.
The change to insert the dimensions is pretty minimal.

Modifying the code is better if you intend to write a script to automate converting many bitmaps at once.


--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: steve325 on Feb 11, 2010, 12:19 am
Hey guys,

I just wanted to report back that I finally got my display working. I'm not sure if it was the new lcd, the complete rewire, or the complete library reinstall that did it, but now i'm up and running. Much thanks to mem and bill for helping out.

Now that i'm actually able to start working on my project, I've found that the 2 supplied fonts are a bit small for the viewing distance that i'm planning on. I downloaded the GLCD Font Creator software and have been able to import and modify a system font, but i'm having a bit of trouble figuring out how to export it as a header file for the Arduino to read. Do I have to create a custom export scheme to accomplish this? I've searched around and can't quite find a straight answer. My end goal is to make a large, bold font somewhat like that is shown on the Sparkfun example clock.

Any help would, as always, be appreciated.

-Steve
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Feb 11, 2010, 04:16 am
I assume you are running the java tool GLCD FontCreator2

- Select [File]->[New Font]
- Type in the name you want to call the font array in the header file
  in the name box of the "New Font" dialog box.
  This will be the name you use for SelectFont().

- Select the font you want in the "Inport Font" drop down box.
- Select the size you want. It isn't exactly the height of the final font but
  larger numbers will be taller/bigger.
- Click [OK] to import the font.

- Click [Export]->[Export Font]
- Type in name of .h file in the "File Name" box of the dialog.
  (The name of the saved file will be exactly what you type so
   don't forget the ".h" on the filename) - you can rename it later
   if you need to.

- click [Save]

That's it. You will now have a new font that is ready to include
into your sketch.

You may need to play around with the size to get what you want.
Numbers can be a bit tricky depending on the font and how you use them.
This is because not all numbers are the same width. Most fonts use variable widths, so say a "1" is narrower than a "0" this can cause digits not to align depending on the application and how the digits are used.

--- bill


Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Feb 11, 2010, 09:42 am
Bill, Mem,

Thanks for the tip.

I was thinking that glcdBitmap is a sketch under Arduino, and got a lot of errors.

Now I know it's supposed to be compiled under Processing.

I just downloaded Processing 1.0.9, and the sketch compiles as good as it can.

It goes without any problem with the Arduinoicon.bmp, which is 64 x 64 pixels.

But if the source bitmap is eg height of 83, I get this error:

ArrayIndexOutofBoundsException: 5312

Maybe when I get more versed with Processing, I may try to fix it


;D ;D

Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 11, 2010, 10:07 am
Joseph, the readme.txt file supplied with the glcdbitmap utility does say it is a Processing sketch, but perhaps it would be clearer if I added a link to the Processing web site for people not familiar with Processing

The readme.txt file says:  "The source bitmap must have a height and width no greater than the height and width of the LCD display"
If your image is greater than 64 pixels high then you will get an array out of bounds error.

There are a number of things that could be done to make the utility more user friendly and robust, but not sure when I will find some time to get to it. If someone has the time and skill to work on this it would be appreciated.
Title: Re: Graphic LCD (KS0108) library now available
Post by: local_dani_21 on Feb 13, 2010, 12:22 am
Hi mem and all! I also try to convert monochrome bitmaps into header-files I can use with my GLCD using Photoshop and mem's glcdBitmap-Sketch. As found in the note by trunk on the 14.9.2009 in the Thread «Re: Graphic LCD (KS0108) library now available Reply #201» and Joseph of today, I also can only convert square images.

The file-format of the files I use seems to be exactly the same in alle the files (Windows-Bitmap, 1bit depth, bitmap-format), but the glcdBitmap-sketch throws an ArrayIndexOutOfBoundsException: 1360 when trying to convert a non-square image.

I tried to crop a non-square image that didn't work to a square image --> it converted perfectly.

What else is there I should make sure to convert non-square images?

Thanks a lot! Dani
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 13, 2010, 12:52 am
Dani, what was the size of the non-square image? can  you post the image on a site like flickr and post a link here
Title: Re: Graphic LCD (KS0108) library now available
Post by: local_dani_21 on Feb 13, 2010, 11:45 am
Sure, you'll find the non-quare picture under (http://www.wunderwald.ch/pics/delfin_am_eintauchen_40x34.bmp) and the square one that is similar under (http://www.wunderwald.ch/pics/delfin_am_eintauchen_40x40.bmp). You'll find the error-messages in the screenshot under (http://www.wunderwald.ch/pics/error.gif)

Dani
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 13, 2010, 12:17 pm
Dani, the problem is not because its not square, its because the height is not a multiple of 8 pixels. If you modify the image by removing the bottom two lines, the 40x32 image will work with the Processing app.

The LCD hardware works in pages of 8 pixels and handling images and fonts that are not even multiples of 8 is something that is being improved for the next release. For now you should use bitmaps with a height that is multiple of 8 pixels.
Title: Re: Graphic LCD (KS0108) library now available
Post by: local_dani_21 on Feb 13, 2010, 12:59 pm
Cool, thanks! Dani
Title: Re: Graphic LCD (KS0108) library now available
Post by: bigtrumpet on Feb 13, 2010, 10:21 pm
Hello Mem, Bill, all,

I've just made some simple changes to S Varjo's bmp2glcd, and should now add the width and height at the beginning of the array. I ain't sure if anyone is interested


Cheers
Joseph
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 14, 2010, 12:13 am
sure, can you post it on a public site?

BTW, I have just modifed the Processing utility to handle images that were causing problems before.
PM me with your email if anyone would like me to send you an early version to test.
Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 16, 2010, 05:29 am
I have a problem that I didn't find a solution for:

It is this display:

http://www.sparkfun.com/commerce/product_info.php?products_id=710

And I'm using the Mega.

I wired it per Pinout A, and I get a backlight and I can adjust the contrast.  However, the display is intermittent.  If I hit the reset button on the Mega, I can sometimes get the Arduino Icon (splashscreen) for a couple of seconds, and then it's hit or miss as to whether or not it will continue through the rest of the routine.  But, when it does continue through the routine, it only draws the left side of the screen (the right side never shows up), and what does show up goes away after approximately 125 seconds (per the counter).  Sometimes, hitting the reset button on the Mega only produces about half of the splashscreen, but ironically, when this happens, only the RIGHT side of the icon shows up.  This tells me that both sides of the screen work, but are somehow not timed properly?  I don't know.

Here is the code I am using, which is what I copied and pasted from the playground:

Code: [Select]
#include <ks0108.h>  // library header
 #include <Arial14.h>  // font definition for 14 point Arial font.
 #include "SystemFont5x7.h"   // system font
 #include "ArduinoIcon.h"     // bitmap  

 unsigned long startMillis;
 unsigned int iter = 0;

void setup(){

 GLCD.Init(NON_INVERTED);   // initialise the library
 GLCD.ClearScreen();  
 GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
 delay(3000);
 GLCD.ClearScreen();
 GLCD.SelectFont(System5x7);       // select fixed width system font
}


void loop(){ // run over and over again

 startMillis = millis();
 while( millis() - startMillis < 1000){ // loop for one second
   GLCD.DrawRect(0, 0, 64, 61, BLACK); // rectangle in left side of screen
   GLCD.DrawRoundRect(68, 0, 58, 61, 5, BLACK);  // rounded rectangle around text area  
   for(int i=0; i < 62; i += 4)
     GLCD.DrawLine(1,1,63,i, BLACK);  // draw lines from upper left down right side of rectangle  
   GLCD.DrawCircle(32,31,30,BLACK);   // draw circle centered in the left side of screen  
   GLCD.FillRect(92,40,16,16, WHITE); // clear previous spinner position  
   GLCD.CursorTo(5,5);               // locate curser for printing text
   GLCD.PrintNumber(++iter);         // print current iteration at the current cursor position
 }
 // display number of iterations in one second
 GLCD.ClearScreen();               // clear the screen  
 GLCD.CursorTo(13,2);              // positon cursor  
 GLCD.Puts("FPS= ");               // print a text string  
 GLCD.PrintNumber(iter);           // print a number
}


I did notice that the playground mentioned the #include <ks0108_mega.h> library, but when I try to modify the library call to include the _mega, it won't compile.

Here is what I'm talking about:

Code: [Select]
#include <ks0108[glow]_mega[/glow].h>

I get this error:

Code: [Select]
In function 'void setup()':
error: 'GLCD' was not declared in this scope In function 'void loop()':


If you need more information, please let me know.   :-/
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 16, 2010, 09:36 am
Wiley, the playground says that the pin assignments are contained in header files and the ks0108_mega.h is the one that has the assignments for the Mega. Edit this file if you have a Mega and change the wiring. But I don't think it says you need to add an include statement in your sketch for this. That happens automatically when you compile the sketch for the Mega board.

You may want to try a longer delay, try doubling the EN_DELAY_VALUE and see if that makes things better. If it does you can experiment to find the smallest value that makes the  display function correctly
Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 16, 2010, 05:07 pm
mem,

Thank you for the reply.  I guess I'm still a little bit confused...

Maybe I'm on the wrong playground page.  This is the one I went to:

http://www.arduino.cc/playground/Code/GLCDks0108

I downloaded the file on this page, and the page mentions that there is a test sketch available:

"The test sketch included in the download demonstrates many of the capabilities of the library and if you start with this and use the default Arduino pin assignments, it is a good way to make sure that everything is working before you customize your configuration."

Now, I can navigate to the ks0108 folder in the download, and there is a folder called "examples" with a GLCDexample.pde file in there, but when I go in the Arduino 0018 program, and try to bring in an example sketch, the only example available is the GLCDbitmap.pde example, not the GLCDexample.pde example.

As an alternative, I copied and pasted the "simplified" sketch from the playground page, and it is behaving as I described before.

Oh, and I did look at the readme file and verified that the Mega and the LCD display are wired correctly, and they are.  I might be able to post a picture of the setup at a later date, but I will have to open a flikr account and I'm not sure how much time I'll have do that with everything that's going on at school and work at the moment.  If you think it would help to see a picture of the setup I will get pictures and post them.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 16, 2010, 05:59 pm
You can open the example file by clicking open from the file menu and navigating to the ks0108 library directory, click on examples and you should see the file.
You can create a subdirectory below examples and name it  GLCDexample,  then move the GLCDexample.pde there if you want to open the file using the Examples menu option.

Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 16, 2010, 06:34 pm
Quote
You can open the example file by clicking open from the file menu and navigating to the ks0108 library directory


I am almost too embarrased to admit that I didn't think of this.   :-[

Thanks, mem.  I'll update my status after doing this.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 16, 2010, 06:57 pm
Don't feel bad, I should have put the example in a subdirectory so it can be found using the Examples menu option. But this library was created before the IDE had an examples option. Anyway, the next release will have the examples in the right place.

Have fun!
Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 17, 2010, 01:37 am
Alright, it works!   :)

OK, so the playground says that Pin 14 of the display is, "normally high.  Can go to +5V." in the comment section.

I must have read "CAN go to +5V" as "OPTIONAL".  When I connected Pin 14 to +5V it worked correctly.

Thanks a lot for the help, mem.
Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 17, 2010, 02:01 am
Here's my first sketch on my new display!  Simplistic I know, but one has to start somewhere!

Code: [Select]
#include <ArduinoIcon.h>
#include <Arial14.h>
#include <ks0108.h>
#include <ks0108_Arduino.h>
#include <ks0108_Mega.h>
#include <ks0108_Panel.h>
#include <ks0108_Sanguino.h>
#include <SystemFont5x7.h>

void setup()
{
 GLCD.Init(NON_INVERTED);
 GLCD.ClearScreen();
 GLCD.DrawBitmap(ArduinoIcon, 32, 0, BLACK);
 delay(1000);
 GLCD.ClearScreen();
 GLCD.SelectFont(System5x7);
}

void loop()
{
 GLCD.ClearScreen();
 GLCD.CursorTo(4,2);
 GLCD.Puts("Hello, world!!");
 delay(3000);
 GLCD.CursorTo(5,3);
 GLCD.Puts("How are you?");
 delay(3000);
 GLCD.CursorTo(6,4);
 GLCD.Puts("I'm fine!!");
 delay(3000);
 GLCD.CursorTo(6,5);
 GLCD.Puts("K Thx Bye!");
 delay(3000);
}


:D

Now, tackling the next part.  The touchscreen.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 17, 2010, 04:45 am
Good to hear you have it going
Quote
? the playground says that Pin 14 of the display is, "normally high.  Can go to +5V." in the comment section.

Good point, I have changed the comment in the playground to: Connect to reset pin

I am working on new documentation for the next release and will add something like:

[font=Arial]The ks0108 needs to have its reset pin taken low for a brief period after power is applied. The diagram shows the display's reset pin connected to the Arduino reset pin and this will automatically reset the display when the Arduino resets.  You can also wire the display reset pin to a spare Arduino pin and control reset in software by adding a define in the panel configuration file (see configuration section), but this is only necessary if the display reset is not wired to Arduino reset.[/font]
Title: Re: Graphic LCD (KS0108) library now available
Post by: WheelerMDW on Feb 17, 2010, 04:59 pm
I don't know if it makes a difference or not, but I connected Pin 14 of the display to the 5V rail of my Mega and it worked just fine.

If I understand the purpose of Pin 14 of the display, this pin should actually be tied to the Reset pin of the Mega, not to the +5V rail right?

Does the reset pin automatically send a reset signal to the display via the library functions, or something?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Feb 17, 2010, 08:09 pm
It depends on the panel. Some panels have an internal reset on power up so the reset pin can be connected to +5 volts. Others need an explicit reset where the pin is connected to the Arduino reset pin.

If yours works ok connected to +5v then don't worry about it
Title: Re: Graphic LCD (KS0108) library now available
Post by: local_dani_21 on Feb 26, 2010, 10:21 pm
Hi. I had problems whenever I wanted to put characters on the GLCD using the PutChar(char c)-function with characters above 127.

I finally found out that in the function PutChar of the library ks0108 a signed char is used
Code: [Select]
int PutChar(char c); . When changed to
Code: [Select]
int PutChar(unsigned char c);, the library displays all the characters the fontcreater produces including those above 127.

So if you have this problem as well, you might change the above code in the files ks0108.cpp and ks0108.h and you're set.

Best regards, Dani
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Mar 02, 2010, 12:13 am
Dani, thanks for pointing this out. I will make sure that this is fixed in the new version of the library.
I think I'll fix it a bit differently so that that there won't be any argument type issues for the function and the original "char" type for the argument can remain as it was to prevent certain types of warnings and remain fully backward compatible with existing code.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: mikem on Mar 15, 2010, 02:53 am
I have this library working with the SG12232A LCD module, which is 122x32 pixels, with only very minor changes to the original code.

The SG12232A is smaller (but cheaper) than the KS0108, and easier to get here in Australia. It also has a LED backlight. I tested with a part labelled SG12232AULB-GS-K from Altronics, data sheet is http://www.gecw.co.kr/data/sunlike/sg12232a.pdf
(although there are a number of errors in the data sheet)
I tested with Arduino Mega.

The differences are:
1. SG12232 requires a 2kHz clock, which is easy to implement with the Tone library and its hardware timers on, say, pin 13 like this:
#include <Tone.h>

Tone sg12232_clock;
#define CLOCK_PIN 13
#define CLOCK_FREQ 2000
void setup(){
 // Sg12232 needs a 2kHz clock, use pin 13
 sg12232_clock.begin(CLOCK_PIN);
 sg12232_clock.play(CLOCK_FREQ);

2. The CS1 and CS2 are inverted compared to the KS0108, so CS1 and CS2 wires need to be reversed

3. The value of some commands are different:
#define LCD_ON                        0xAF
#define LCD_OFF                        0xAE
#define LCD_SET_ADD                  0x00

4. Display dimensions are different:
#define DISPLAY_WIDTH 122
#define DISPLAY_HEIGHT 32
#define CHIP_WIDTH     61  

5. The sample test program is too high, causing various artifacts. Rewrite to use the smaller dimensions and its OK.

Pinouts are:
SG12232   Mega      Function
1                GND         VSS
2                5V            VDD
3                GND         Contrast, or can connect to trimpot
4                36            RS also called D_I
5                34             /CS1
6                33             /CS2
7                13             clock input
8                31             E
9                35             R/W
10              22            DB0
11              23            DB1
12              24            DB2
13              25            DB3
14              26            DB4
15              27            DB5
16              28            DB6
17              29            DB7
18              RES         RESET
19                          LED backlight, +4.2V, 195mA
20             GND         LED GND

Cheers.
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Mar 15, 2010, 09:14 am
hi mikem, interesting display, good to hear you got it going.

You may want to try the built in Tone function on 0018 to generate the clock signal, this would avoid the need to download and install the external library.

There is a new version of the library coming soon that would be even easier to get working with that display and should be faster. Send me a PM with your email if you would like to  get on the list of beta testers.
Title: Re: Graphic LCD (KS0108) library now available
Post by: nnoel on May 23, 2010, 12:15 pm
Hi Mikem,
Seems to be good news but I didn't got the mods working on my duemilanove with my lcd 12232A.
Did you modify directly the ks0108 library or did you put the mods (the #define's) in the sketch?
Do you have a sample sketch I could try?
Title: Re: Graphic LCD (KS0108) library now available
Post by: aoran-lcd on May 23, 2010, 04:46 pm
Got some supply of KS0108 LCDs, check them out if they would be helpful: http://www.cn-aoran.com
Title: Re: Graphic LCD (KS0108) library now available
Post by: Helliouse on May 23, 2010, 06:59 pm
Hello,
I just got all my wiring done. I have rechecked it a couple of times, (still doesn't mean it right :P). But what I am getting is a mirror image of the first half of the screen overlayed on the second half.

I have tried adjusting the timing "EN_DELAY_VALUE 5" up to 50 with no effect. I have also uncommented the second EN_DELAY() on the enable function.
If I reverse CSEL1 and CSEL2 I get the back half of the image displayed on each side, with an overlap front half of the image on the right side.
It seems like I have wires cross connected feeding each half of the display the same data...its wired and very frustrating. I have made sure there are no wires touching as well. - I should clarify that the left had side never seems to get any overlay.

Does any one have any suggestions on a fix, or what I may have done wrong.

Thank you!
Brad

--Edit-- As I said, pins might not be right...Well...they weren't. Mind I was checking them at 2:00am...
Title: Re: Graphic LCD (KS0108) library now available
Post by: nnoel on May 26, 2010, 08:18 am
Hi mikem,

"5. The sample test program is too high, causing various artifacts. Rewrite to use the smaller dimensions and its OK."

could you show us a working test program for the 12235A?


Title: Re: Graphic LCD (KS0108) library now available
Post by: djsb on May 26, 2010, 12:04 pm
Hi,
I'm new to this forum and arduino's in particular.
I have a Nano V2.3 and I'd like to use a graphics LCD with it.
Can anyone tell me if they have bought a KS0108 compatible display from a UK supplier at a reasonable price? Also are there any problems with using the KS0108 library with the nano?
Thanks.

David.
Title: Re: Graphic LCD (KS0108) library now available
Post by: robinet_pl on May 26, 2010, 01:14 pm
Hi everybody :)

Below you can find images of GLCD I've bought on eBay (as "unused stock") - M24064-1B1-E (MSC-G24064DVSV-1N-E):
(http://img199.imageshack.us/img199/3079/dsc04514jb.th.jpg) (http://img199.imageshack.us/i/dsc04514jb.jpg/) (http://img541.imageshack.us/img541/9949/dsc04516w.th.jpg) (http://img541.imageshack.us/i/dsc04516w.jpg/) (http://img189.imageshack.us/img189/6741/dsc04517p.th.jpg) (http://img189.imageshack.us/i/dsc04517p.jpg/)

and here is the way I've connected it to Arduino - by using HDD IDE cable ;) :
(http://img697.imageshack.us/img697/5143/dsc04511f.th.jpg) (http://img697.imageshack.us/i/dsc04511f.jpg/) (http://img52.imageshack.us/img52/5229/dsc04515n.th.jpg) (http://img52.imageshack.us/i/dsc04515n.jpg/)

here is link to datasheet:
http://www.trulydisplays.com/monochrome/specs/240x64%20MSC-G24064DNEW-1N%20Spec.pdf
(I think it's the right datasheet)

Wiring is exactly like in library description - with of course altered pins in GLCD module - and only CS1 and CS2 are used.

But it looks like totally dead :( shows nothing :(

I've modified code by adding Serial comm and by sending controll message after each line in example code - but sometimes it hangs at the beginning - sometimes before "introScreen();" in setup():

Code: [Select]
void setup(){
 pinMode(ledPin, OUTPUT);   // ledPin=13
 Serial.begin(9600);
 digitalWrite(ledPin, HIGH);   // set the LED on    
 Serial.println("start " );
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
 Serial.println("init " );
 GLCD.ClearScreen();  
 Serial.println("cls " );
//  GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given x,y position
 Serial.println("icon " );
//  GLCD.SelectFont(System5x7); // switch to fixed width system font
 countdown(5);
 GLCD.ClearScreen();
 Serial.println("intro " );
 introScreen();              // show some intro stuff
 GLCD.ClearScreen();
 Serial.println("after intro " );
}


With these modifications it execute countdown() but then hangs or reset.

Could anybody please take a look at the datasheet and tell me what could be wrong ?

I've two of them and both are "dead" :(
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on May 30, 2010, 07:07 pm
RobiNET,
I've looked at the datasheet and your photos.
It's hard to tell from the photos what is hooked up but here are a few comments:

#1 of highest importance. Make sure you have the correct data sheet. If it is incorrect, the display can damaged by improperly connecting power signals.

Assuming the datasheet is correct,

The display you have uses a EL backlight vs a LED. This means you will need a high voltage power supply to drive it. You may not be able to see anything until you get the backlight working.
You can purchase a small EL step up power supply that will bump the 5v up to 100+ volts from the EL wire shops for ~$5 USD.

Assuming you will be able to see some sort of pixels using ambient light,

Next, your display uses 4 chip selects. 1 for each chip.
The current ks0108 library isn't setup for using more than 2 chip selects - which you probably have already noticed.
There is a new version of the library that Michael and I are finishing up that does support this and even has a diagnostics sketch to help debug wiring & configuration issues, but unfortunately, it isn't quite ready for general release yet.

In the mean time, you can either use only 2 chip selects, which it sounds like you are tying to do, or modify the code for 4 chip selects.

There are a few tricky issues, with either of these options.

1) Using only 2 chip selects.

If you want to attempt to use only 2 chip selects, you will need to ground the unused chip selects (pins 18 & 19) on your glcd module). This ensures that the unused chips are not selected. If the lines are left floating, the chips are often selected and if multiple chips are selected, things won't work properly and the code can even get stuck in a busy wait loop.

Also, in order to do this, you will need to define the display size to be 128 pixels wide. (DISPLAY_WIDTH in ks0108_panel.h)

2) supporting 4 chip selects.

This is not too complicated to get working but there are some "gotchyas" for the display size you are using.

One of the problems is that the current library assumed display display widths were always a multiple of 64 pixels. Because the display you have is not a multiple of 64, there are rounding issues in some of the calculations that calculate the number of chips. (this also has been fixed in the new code).
The issue is all the places that use DISPLAY_WIDTH/CHIP_WIDTH
(There are 2 places in the code that do this)

They will incorrectly come up with 3 instead of 4 for this display.
For testing you can either hard code these to 4, or replace them
with a new define like: glcd_CHIP_COUNT
and then create a #define for glcd_CHIP_COUNT near the top of ks0108.cpp (just above the EN_DELAY define)

Code: [Select]
#define glcd_CHIP_COUNT ((DISPLAY_WIDTH + CHIP_WIDTH - 1)  / CHIP_WIDTH)


Make sure to correct both places in ks0108.cpp that have this DISPLAY_WIDTH/CHIP_WIDTH calculation with this new define.


Then you still have to deal with with 4 chip select lines.
While there is a better way to do this (which has been done in the new code), an easy way to do this for your specific module will be to modify/replace the SelectChip() function
Replace it with this:

Code: [Select]
__inline__ void glcd_Device::SelectChip(uint8_t chip)
{  

     if(chip == 3) fastWriteHigh(CSEL4); else fastWriteLow(CSEL4);
     if(chip == 2) fastWriteHigh(CSEL3); else fastWriteLow(CSEL3);
     if(chip == 1) fastWriteHigh(CSEL2); else fastWriteLow(CSEL2);
     if(chip == 0) fastWriteHigh(CSEL1); else fastWriteLow(CSEL1);
}


Then you will need to add pin defines for CSEL3 and CSEL4 in your ks0108_Arduino.h file.
Then define the DISPLAY_WIDTH to be 240 in the ks0108_Panel.h file.

Note: I have not actually run the code with these modifications, but I believe that it should get you going.

The ultimate solution is to move over to the new library once it becomes available as it has support for this type of display configuration as well as many new features including a diagnostic sketch to help debug wiring and configuration issues.

--- bill





Title: Re: Graphic LCD (KS0108) library now available
Post by: arian on May 31, 2010, 12:52 pm

Hello,

I just want to tell you that library works fine with
ABG128064A23-BIW-R 128x64 lcd screen :) Great job!

Also I want to ask, if there is something that interfere from control CS1 and CS2 pins with basically only one pin and two transistors? (high state on this pin drive CS1 high and CS2 low, low state drive CS1 low and CS2 high). It will require only small change inside library's code.

It's because I use serial, i2c bus, 3 buttons and none pins left unused on Arduino Duemilanove :(

excuse me my English, I'm from poland
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 01, 2010, 07:07 am
Arian,

I assume you mean to be able to control CS1 and CS2 with 1 Arduino pin using external logic.

The new version of the library allows configuring how the chip select lines work to support this capability.
(I need to talk with Michael and see if we can start beta testing the new code soon)

If you are wanting to get this capability working with the existing library, you will need to modify the SelectChip() routine.

Simply modify the code to something like:

Code: [Select]
__inline__ void glcd_Device::SelectChip(uint8_t chip)
{  
     if(chip == 0) fastWriteHigh(CSEL1); else fastWriteLow(CSEL1);
}


That will set the Arduino pin CSEL1 (defined in ks0108_Arduino.h) high for chip0 and low for chip1 and ignore CSEL2.
Make sure to comment out this line:
Code: [Select]

   pinMode(CSEL2,OUTPUT);


in the ks0108::Init(boolean invert) function.


You will need to add your external logic to drive the actual
CSEL1 and CSEL2 lines.
It could be done with 1 transistor by running the Arduino pin
directly to CSEL1, then use a transistor to set CSEL2 low whenever
the arduino pin is high.

An alternative that only needs a few resistors and does not require modifying the ks0108 library, would be to use an analog input for the buttons.
Use a resistor voltage divider to create different voltages for each button.
Each button would create a slightly different voltage.
That way 3 (or even more) buttons could share a single Arduino pin. Each button would be represented by a different ADC value.
(in reality it would be a small range)
Not quite as easy as a simple digital input,
but it would allow several buttons with only a single arduino pin.
This method also assumes that only one button is pressed at a time.

Hope that helps.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: arian on Jun 01, 2010, 02:24 pm

Thanks, this is exactly what i mean, your reply was very helpful :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: robinet_pl on Jun 01, 2010, 06:19 pm
bperrybap,

Thanks for your help.
Problem is in connection of LCD to IDE cable - I had to solder pins :(
One LCD looks like could be working - second one even after soldering shows garbled pixels ... I need to re-solder everything :(
Title: Re: Graphic LCD (KS0108) library now available
Post by: robinet_pl on Jun 02, 2010, 11:49 am
hi,

After re-soldering everything - one LCD is totally broken - shows nothing "readable".

Second one - shows everything almost perfectly fine - with FPS=9 for EN_DELAY_VALUE=1 ... almost, because contents of 2nd chip is duplicated on 3rd chip and on 4th chip ... but no wires is attached to CS3 and CS4 ?!?!

And the correct datasheet is here:
http://www.pdfsea.com/down/down.php?downid=9374&id=0
It's not MSC-G24064DVSV-1N-E - but MSC-G24064DYSY-1N-E.
It has LED backlight which works fine with 4.5V.

[edit]
after grounding CS3 and CS4 - everything seems to work fine on "good" LCD module :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: Beta on Jun 08, 2010, 11:58 pm
Hi all.

Are there any instructions out there that explain how to use the FontCreator software?
Title: Re: Graphic LCD (KS0108) library now available
Post by: jbf1 on Jun 14, 2010, 05:05 am
Thanks for the library.

Works really well on a GLCD from newhavendisplay.com (NHD-12864WG-BTFH-V#N in case anyone is looking for a part.)

I was running into some problems with very large font sizes, but made a small change to ks0108.cpp to fix this. I altered the PutChar(char c) method. The page variable was declared as a byte, which didn't hold enough locations for my large characters.

Changing its declaration to 16 bit fixed this. That is, I changed line 392 from:
           uint8_t page = i*width;
to:
           uint16_t page = i*width;

and now my large fonts draw correctly.


In case it helps anyone...
jf
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 15, 2010, 07:16 pm
jbf1,
oooo.. Interesting. Are you using a font that is 32 pixels or wider?
The new version of the library renders fonts very differently but looks like it will suffer from the same overflow issue.
I'll look into fixing this in the new version of the library.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 15, 2010, 07:21 pm
Beta,
I haven't seen any documentation.
You kind of have to play with it and look at the generated file to see what happens.
Make sure you get the right version of "FontCreator2".
Don't get the Microelectronika version.
Make sure to use the one with the link at the bottom of the palyground page.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: arian on Jun 21, 2010, 11:06 am

Hello,

I have small issue with method ks0108::WriteData.

When the yOffset is properly aligned it simply overwrites single page.
But when doesn't it will use logical OR for split bits into two pages, which can produce unexpected results on the LCD. Probably that code assumes that screen was cleared earlier.

So to prevent it i just clear used bits before that OR operation.

Code: [Select]

// first page
...
displayData &= (uint8_t) ~(0xff << yOffset);
displayData |= data << yOffset;
...
// second page
...
displayData &= (uint8_t)  (0xff << yOffset);
displayData |= data >> (8-yOffset);

Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 21, 2010, 09:11 pm
This is actually much more difficult to solve than you might think.
The only real solution is to dump and re-write the putchar rendering routine
(which is what I've done in the new version of the library - that is just entering beta testing).

The original code from Thiele which was used for the current ks0108 library
attempted to solve the lcd page spanning issue as you have noted.
It keeps the rendering very simple but there are many issues
because the WriteData() routine does not know which bits in the byte
are part of the character bitmap data and which are not.

Some of the zero bits in the byte are legitimate zero bits that should
be set to 0 but some of the zero bits are actually not part of the
data at all and should be left alone.
And there is the dilemma.
The only entity that has access to this information, PutChar(), isn't
using it or communicating it to anybody else.

One big factor with doing things like pre-clearing the bytes as you have done done potentially creates other problems as it stomps on pixels above or below the boundary of the character glyph.
Consider a font that is 9 pixels tall. This will span 2 pages. If your font starts on a page boundary and you clear
the pages before ORing in the data, in this case, the 7 pixels below the character data are also cleared. That is often not desired, particularly
if you are re-writing a line of text above an existing line of text.
This effect even happens with the system font when the y coordinate is not on a page boundary. i.e. using the system font on y coordinate 1, the lower 7pixels of lower page will be clobbered rather than left alone.
Move the starting y coordinate to say 7, and you have the opposite problem. The 7 pixels above the font get clobbered.
So if you try to put a line of text below another line, the pixels from line of text above gets stomped  on.

Things also get really hairy when trying to support inverted/reverse-video text.


There are so many issues that crop up
with trying to let the WriteData() handle the lcd page spanning.
It is so seductively simply sounding
yet the bottom line is that there is no way to fix this kind of stuff in WriteData().

The only way to make it work reliably and consistently, is actually to write a better character rendering routine that sets and clears only the bits within the character data and leaves the bits in the page outside the character data alone - which is what is in the new version of the library.

The new PutChar() is actually quite complex, but it is all necessary to properly handle allowing any font size to be rendered on any horizontal or vertical pixel boundary along with normal and inverted text. It turned out that adding text areas was a  simple addition, so the new PutChar() code also supports scrolling,
wrapping and multiple user defined scrollable text areas.

So with the new rendering method used in the new library, not only is wrapping and scrolling supported but you can do over-strike properly as well as inverted text and even move the text right up close to a graphic object above or below the text and not have to deal with all the crazy rendering problems which vary depending on font size and y location that are in the current code.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: arian on Jun 22, 2010, 09:43 am

Thanks for clearing this up. Indeed i was too hurry. I have this problem during tests with animated bitmap (just drawing few frames loaded from external eeprom) and i completely forgot that it affect also fonts :-[

I can't wait for new version :)
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 22, 2010, 07:31 pm
If all you need is a fix for bitmaps:
Insert this code (which is in the new version of the library)
in function DrawBitmap()


Code: [Select]
 if( (y & 7) || (height & 7))
 {
       this->FillRect(x, y, width, height, WHITE);
 }


Just above the for loop.
Code: [Select]
for(j = 0; j < height / 8; j++) {

This code will pre-clear the area under the bitmap when necessary.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jun 24, 2010, 07:45 am
I just ported a routine to plot ellipses:

Code: [Select]
void PlotEllipse(long CX, long  CY, long XRadius,long YRadius, int color) {
// portted the algorithm found at
// http://homepage.smc.edu/kennedy_john/belipse.pdf
// by John Kennedy

 long X, Y;
 long XChange, YChange;
 long EllipseError;
 long TwoASquare,TwoBSquare;
 long StoppingX, StoppingY;
 TwoASquare = 2*XRadius*XRadius;
 TwoBSquare = 2*YRadius*YRadius;
 X = XRadius;
 Y = 0;
 XChange = YRadius*YRadius*(1-2*XRadius);
 YChange = XRadius*XRadius;
 EllipseError = 0;
 StoppingX = TwoBSquare*XRadius;
 StoppingY = 0;

 while ( StoppingX >=StoppingY ) //first set of points,y'>-1
 {
   Plot4EllipsePoints(CX,CY,X,Y,color);
   Y++;
   StoppingY=StoppingY+ TwoASquare;
   EllipseError = EllipseError+ YChange;
   YChange=YChange+TwoASquare;
   if ((2*EllipseError + XChange) > 0 ) {
     X--;
     StoppingX=StoppingX- TwoBSquare;
     EllipseError=EllipseError+ XChange;
     XChange=XChange+TwoBSquare;
   }
 }
 //{ first point set is done; start the 2nd set of points }

 Y = YRadius;
 X = 0;
 YChange = XRadius*XRadius*(1-2*YRadius);
 XChange = YRadius*YRadius;
 EllipseError = 0;
 StoppingY = TwoASquare*YRadius;
 StoppingX = 0;
 while ( StoppingY >=StoppingX ) //{2nd set of points, y'< -1}
 {
   Plot4EllipsePoints(CX,CY,X,Y,color);
   X++;
   StoppingX=StoppingX + TwoBSquare;
   EllipseError=EllipseError+ XChange;
   XChange=XChange+TwoBSquare;
   if ((2*EllipseError + YChange) > 0 ) {
     Y--;
     StoppingY=StoppingY- TwoASquare;
     EllipseError=EllipseError+ YChange;
     YChange=YChange+TwoASquare;
   }
 }
}; //{procedure PlotEllipse}

void Plot4EllipsePoints(long CX,long  CY, long X, long Y, int color){
 GLCD.SetDot(CX+X, CY+Y, color); //{point in quadrant 1}
 GLCD.SetDot(CX-X, CY+Y, color); //{point in quadrant 2}
 GLCD.SetDot(CX-X, CY-Y, color); //{point in quadrant 3}
 GLCD.SetDot(CX+X, CY-Y, color); //{point in quadrant 4}
}

Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 25, 2010, 10:50 pm
The ellipse code looks like a modified version of the
the midpoint circle algorithm.
With a small tweak, it can also fill the ellipse as well.
(I've tested the code above with both ellipses and modifed code for filled ellipses)
The new library already has circle routines (draw and fill),
but I'll look at folding in ellipse capability as well.

I'd prefer to fold in ellipse capability in with circle and rounded rectangle
code to save space.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jun 26, 2010, 04:25 am
bperrybap

I'd love to see it integrated into the library! I just bought a LCD and the pixels are not square, so when I draw a circle I see an ellipse, so - to correct the aspect ratio, I'm using that function. Maube I'll code something for automatic aspect ratio correction...or maybe it's overkill...

I'd like to ask another question:

Is it possible to print the text rotated by 90 degrees?

I'm thinking about using it on portrait orientation (width = 64 and height = 128)

Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 28, 2010, 07:54 am
Who makes the GLCD that you have?

I totally understand about the non square pixels.
Luckily most of the ks0108 128x64 GLCDs have square pixels, but
I do have some GLCDs (sed1520) that are not square pixels and circles on those are not "round".

As far as rotated text goes....
Technically, the answer is yes, but not with this glcd library.
There are several things that enter into this.
Right now, the text rendering code is "hard coded" to the current orientation.
Currently, the fonts themselves are encoded with the bits in the
the same positions as the GLCD memory pages when in this orientation.
i.e. byte 0 of a font glyph is up to 8 vertical pixels on the left side of the glyph. (same is true for bitmap data)

Also, the ks0108 and other chips have an auto address increment mode inside the chip that advances each time a byte is written.
On the ks0108, the column address increments. The rendering code takes advantage of this as well
as it draws up to 8 pixels tall horizontally across the glyph, then drops down if there are additional vertical pixels to render.


So while the code could be written to rotate things around to render it
in a different orientation which is potentially different from the bit
representation in the data (font & bitmap), the current code does not support this.

Michael and I have talked about it, but decided it was too big of a change to tackle at this point in time for this upcoming release.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jun 28, 2010, 08:21 am
Ok, no rotation then... I would use it for a temperature logger so the y-axis would have more definition (128 pixels high)

My display is made by FORDATA, it's model is FDCG12864G and I'm not sure, but it's pinout seems to be different from the types "A" and "B" - I just followed the pin names and it worked OK from the beggining - tho I had to increase the delay a bit - it was missing some pixels

You can see a datasheet here:http://www.soldafria.com.br/datasheet/FDCG12864G.pdf

I plan to scroll the graph, so this week I'll give a go on the frame buffer mod, but i saw it was made for a older version of the library, any news on that front?

I also found a display with a LC7981 controller, but didn't have the time to take a look on how it works. When I get to know, I'll share. Do you know if is it possible to adapt your library for that?

THANKS a lot for your good work and quick replies on this topic!!!

If you think I can help, just ask and I will
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 28, 2010, 09:49 am
I looked at the data sheet for the FORDATA module.
I've seen 8 or 9 different pinouts for ks0108 modules, but that one is a new one.
That data sheet didn't have any hardware timings in it.

With respect to the timing. The ks0108 library wasn't handling the delay timing very well and certain hardware delays were not properly accounted for.
The new code has proper delays for all the necessary hardware setup times. As a result, the new code is much more robust and also allows adjusting individual timing values in nanoseconds rather than some odd loop counter value.
That said, the new code should work "out of the box" as we have tested it on many different panels, processors, boards, and configurations with no issues. The new code is also quite a faster than previous version.

The LC7981 is different type of chip. (it is smarter with additional capabilities) While it definitely can be made to work with the library, it would be nice to take advantage of some of the additional features - like built in fonts.
At first glance this chipset looks similar in functionality to the SED1330F which we are just starting to look at.

Support for this kind of chip is on the radar, but for now the immediate focus is to get the new version of the library out to people so that they can start using it.

--- bill

Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 28, 2010, 09:54 am
I'm not sure what you mean by  a "frame buffer mod".
Fill me in on what you mean by that.

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jun 28, 2010, 03:21 pm
Bill
I read that todotani was modifying the libraryto use a frame buffer with the arduino mega - I'm using a mega.
The reply number is 124 I guess.

Yesterday I finally read one datasheet for the Lc7891 and my first impresion is that it has a text mode and a graphic mode. the fonts are just for the text mode. On the graphics mode it has a set pixel command that deals with individual pixels. Also read that the pixel are organized on horizontal bytes, what is different from the  ks0108.

Are you working on a new version? I didn't get it right from your message - or you mean by NEW the current version 2?

Thanks again!
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 28, 2010, 07:10 pm
On the new library.
Michael (mem) and I are finishing up a new version of the ks0108 library.
(it is currently in early beta testing and will eventually replace the current ks0108 library on his ks0108 playground)
While it is an update to the ks0108 library, it is now called "glcd" rather than ks0108 as it supports more than the ks0108 chip. It has many updates/fixes and new features. While backward compatible with the ks0108 library. The underlying i/o has been completely redone to make things much easier to configure, more flexible and is also higher performance.

With respect to using a frame buffer.
This is actually quite a complex subject. The end result
is not always what is initially expected.

It is possible to write code to use a frame buffer. Many implementations that provide the type of functionality in the glcd library
(especially the new multiple scrolling text areas) do use a frame buffer. When using a frame buffer, the code is actually easier to write, smaller and in some cases (but not all), faster. One big problem is the frame buffer itself. For example, when using a 128x64 display a frame buffer would use 1k of RAM. While not that big an issue for chips like the mega1280 or mega1286/7, it  is 100% of what is available on a m168 and half of what is available on a m328.
And that is for a 128x64 glcd.
The glcd library supports glcds up to 256x256 and there users out there already using displays of 240x64.
NOTE: with some slight modifications the code could go beyond the 256x256 limit. The current limitation is due to using 8 bit variables to save code space and increase speed.

I think one of the big pluses of the glcd library is it can run on a m168 even with a very large display as currently the code only needs a small calling stack frame, a few working temporaries and only 3 bytes of "buffering" to do all the rendering regardless of the size of the display.

With a frame buffer you need to have a dedicated ram buffer large
enough to hold all the pixels of the display. This can get very large
as the display get large.
As far as performance with a RAM buffer goes, it isn't always necessarily faster. It depends on the nature of the updates.
When using a frame buffer, the fastest way to update the physical
display from the frame buffer is to slam it all out, potentially overlapping
writes to the multiple chips memory to allow the internal updates to happen in parallel and also take advantage of the internal automatic column address increments.
While very fast, it is sending every single byte to the display.
Also, when using a RAM frame buffer, you have to deal with the pixel
data multiple times.
- once to write to the ram buffer
- once a bit later to read it from the ram buffer
- once to write to the glcd.

So if you are only updating small portions of the screen, the additional
overhead of sending all the bytes to the display can overshadow
the slightly slower i/o method of sending only the data you need to send
to update the small portion of the screen.

Additional code can be added to try to avoid sending portions
of the RAM to the screen that have not been updated, but eventually it starts
to get quite complex and you end up doing about the same thing as the current code does when updating the glcd.

For very large updates such as bitmaps, the current code should be just as fast if not faster than using a RAM buffer for bitmaps that are page aligned (8 pixel boundaries) and multiple of a page size (8 pixels) tall.

The biggest thing a ram buffer does is "time shift". For example, it allows moving around when the physical display is updated.
It allows the updates to the ram buffer to accumulate and then
to flush those updates to the physical screen when convenient.
It also allows interrupt contexts to update the ram buffer which eventually are flushed to physical display.
Without a RAM buffer it is not possible to have foreground and interrupt contexts both updating the display.
So if you want/need to update the display from in interrupt routine,
a RAM buffer is pretty much a necessity.

The good news is that the new version of the library, through the use of some somewhat complex code, now only does the minimum i/o accesses to the chips. If the chip is already where it needs to be it is no longer told to reset its registers. The code also takes advantage of the internal auto address increment and scrambles around the font rendering to ensure the absolute minimum number of access to the GLCD page memory. While this may look like larger/slower code
it is actually quite a bit faster as it is avoiding talking to the GLCD chips
and glcd memory as much as possible since some of those operations
can be costly in terms of time.

So its all kind of a trade off.
Right now it appears that the best alternative for a generic glcd library that supports a broad range of glcds of different sizes on many different AVR chips, is to not depend on the use of a frame buffer.

--- bill


Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jun 28, 2010, 07:31 pm
May I suggest scrolling graphics? That's what I need! Even if it's restricted to multiples of 8 pixels high.

How to I obtain the beta version of the library?

Last night I found sombody who did something like what I'm doing: http://www.youtube.com/watch?v=_sH5kaKO8Vw&feature=related

I'll try to code something today only drawing lines and verifiy if it's fast enough.

Sorry if I'm bugging you with all these questions. I swear I'm coding as well, but who's better than you to give me the hints?

Again, thanks a lot!

[edit]I'll try to scroll each page and then only add the last column of temp data. That's how you scroll text isn'it?[/edit]
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 30, 2010, 03:44 am
If you have all the data sample values in memory, then it might be quicker to redraw all the shifted line segments for each sample value in the graph rather than move the existing graph over.
This is because to move data requires reading the GLCD memory as well as writing to it, whereas to re-draw the graph segments is primarily writes.
(might be only writes depending on how it is done).



--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jun 30, 2010, 03:56 am
Yeah, I was thinking about it, and scroll the pages won't work for me, as I plan to use a auto scale for the graph.

Didn't realise it could be only writes, how to do that?

I made a test routine scroling the graph and drawed it using the filled rectangle function, it's pretty fast, but I cleared the screen every update and it caused the graph to flicker.

My idea now is to rewrite it to update each column of the graph at a time, scanning the whole graph every update (1 a second or 1 every 5 seconds maybe). My first impulse was to draw a black rectangle for the value and above it a white rectangle to clear some eventual old value printed over there.  It should eliminate the flickering, I guess.

After I test it, will post the result if it works.

Other thing, I was reading the library and found some "fastWrite" functions, but I just took the .cpp file with me. Is it defined somewhere else? can I use it in my code for my I/O pins? Anyway, I'll google it after, but if you can give me the tip I'll appreciate it.
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Jun 30, 2010, 09:17 am
MauJabur,
Check your PMs.

The "fastwrite" stuff is not intended for user code.
It is not part of the API and can't really help out.
It is for setting digital pin values and replaces the VERY SLOW arduino
function digitalWrite().
Slow is relative. In my world of fast i/o, "slow" is tens of microseconds
where as a direct i/o pin write on a 16mhz AVR is only 62.5 nanoseconds.

To speed up your graph drawing, you can write the code to avoid drawing both the white and the black "bars".
Simply store the data in an array but use a circular index to indicate where the data starts. That way you don't ever move the data around just the index. Then because it is circular, you can also know the previous value stored at any location in the graph as you update it.

Because you can know the previous value of a vertical "bar" in your graph, all you need to know is if the new value in that position is larger or smaller or the same as the value that was previously drawn there.
If the same, you draw nothing and leave that position alone
If it is larger, draw the black portion.
If it is smaller, draw the white portion on top which will erase some of the previous bar.

In the case of something like temperature readings, the values may tend to move fairly slowly so comparing if the value is equal to the previous value may eliminate many updates.

If you have enough information and want to, you could even optimize it
further by only updating the individual portions of the bar that need to be overwritten to make the bar taller or shorter as needed.
For example, if the previous bar was 8 "ticks" tall and you need a bar 10 "ticks" tall, then you draw the 2 "ticks" on top of the existing 8 "ticks" that are already on the glcd screen rather than the full 10 "ticks". Likewise if the previous bar was 8 "ticks" and you need to draw a bar 6 "ticks" in that position, you draw 2 white "ticks" to erase the top 2 "ticks".



--- bill




Title: Re: Graphic LCD (KS0108) library now available
Post by: spinnaay on Jul 07, 2010, 10:14 pm
Hi everyone,

Has anyone got any experience with these LCD drivers? I want to drive on from my Duemilanove.

http://www.alldatasheet.co.kr/datasheet-pdf/pdf_kor/163771/ETC/SED1561.html

Thanks

Thom
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jul 08, 2010, 06:46 am
Spinnaay

I never worked with this display, but found some products that share the same controller:

SED 156x series
Nokia 7110      96 x 65      monochr.      
NEC 21a      132 x 32
LPH7508      100 x 64       - display kit sold by pollin
Hyundai HP12542R      - display kit sold by pollin

This info was found here: http://serdisplib.sourceforge.net/ wich seems to be a library writen in C for displays, but I still don't know if it's for use on a PC or on a microcontroller. [edit]UPDATE: it's for linux[/edit]

I would google the display names above with the arduino word to see what comes up.

some results:

http://home.broadpark.no/~rrbakke/lcd.html
http://forums.adafruit.com/viewtopic.php?f=25&t=11880


Title: Re: Graphic LCD (KS0108) library now available
Post by: spinnaay on Jul 08, 2010, 11:44 pm
Hi thanks for this.

I'll pursue the Nokia route as that seems to be a common one.

Just to mention when I brought this display I got two PDF manuals and all the code to get it working with a PIC18.
Now if I was a smarter lad I could work with this and get it running with my arduino..... sadly not.
I can show people if you want. It's all in a 418k zip.

So say I bail on this gLCD and get a very arduino supported one. What do you recommend?

Thanks.
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jul 08, 2010, 11:48 pm
Spinnaay

I've been using a display with the KS0108B controller without problems!
If you want, send me the PDFs and I'll take a look, but I don't promise a fast response nor that I'll make it work, I'm not super skilled, but have done some code tranlations from pic to arduino.

Check your PMs
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Jul 14, 2010, 07:26 pm
An early beta release of the next version of the GLCD library is now available, see  this thread (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279128237/) for details
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jul 19, 2010, 10:34 pm
In response to spinnay, I translated the code he sent me (PIC originally)
to the arduino, but something seems not to be quite right.

If someone else could help, please. I am not sure the SPI library works, if somebody could check it.

Where should I upload the code to make it available here?
Title: Re: Graphic LCD (KS0108) library now available
Post by: spinnaay on Jul 30, 2010, 10:31 pm
Hi Everyone,

Big thanks to the gLCD crowd for helping me with my random display. It's going to MJ now so he can get it working and post the results.
I am playing with a KS0108 now which is Pin Out B, not because I have the manual but because the display lights up that way around!

I am getting garbled pixels. Piccy.
(http://farm5.static.flickr.com/4087/4838589496_5279f141e5.jpg)

Anyone seen this before.

Thanks

Thom
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Jul 31, 2010, 12:56 am
@Thom

I found this datasheet for your display (from the picture you sent me):
http://www.willar.com/upload/shop/JHD529M1.pdf

It's almost Pin out B, but it does not have the CS1 and CS2 lines.

I read somewhere that this controller (st7920) is compatible with the ks0108 instructions [edit] [update:maybe it's not][/edit] , but I'm not sure how to make it work here. Maybe you have to select somewhere that your LCD has only one chip and NO CS...

I'll try to learn more about it, but maybe someone could help...
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Aug 01, 2010, 11:24 am
Thom,
Be very careful about hooking up the glcd. Connecting pins incorrectly
can blow up the glcd, its internal controller, or even the AVR chip.

I'm a bit confused here about which glcd you are running vs
what MauJabur is looking at.

Before I can help you with the display related to the picture you posted, I'll need some additional information.
- Which library are you using? The ks0108 or the new beta glcd library?
- Which specific glcd module are you using?
 and a link to a data sheet for that display.
- How you have wired up the panel.
- What code/Sketch are you running when you see this?

If it is the glcd  in the data sheet that MauJabur posted a link to (JHD529M1), then it is not compatible with a ks0108.

None of the commands in the JHD529M1 are the same as a ks0108.
The way to get that chip supported would be to add support
for it into the new GLCD library vs attempting to add it back into the ks0108 library.

As far as your display with the "snow" on it, yes
I have seen similar results to what you are seeing.
Some GLCDs power up with an alternating block pattern.
Yours may do this. Then if things are incorrectly wired up, the hardware timing is off or if the display is not ks0108 compatible, then you can see trash
pixels being lit up on the screen which kind of look like "snow".

My recommendations is to move to the beta glcd library (if you aren't already using it) as it has much better diagnostic capabilities,
including a diagnostic sketch and you should not have any hardware timing issues as the new code should properly honor
all the hardware timing automatically.

And for any discussions related to the beta glcd library,  post over
on the beta library thread vs this thread, just to keep things
separate since the two libraries are fairly different especially with
respect to configuration capabilities and diagnostic information.
Link to beta thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279128237/

--- bill
Title: Re: Graphic LCD (KS0108) library now available
Post by: madepablo on Aug 01, 2010, 07:11 pm
just FYI, i tried it with AGM1264B model of this 128x64 Graphic LCD... and it works perfectly.

Thanks for the library and the different ideas posted in this forum.

Cheers,
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 01, 2010, 08:21 pm
@madepablo, did you try the existing release (version2 ) or the Beta release of version 3. If you have not tried version 3, I think you will be pleased.  We are looking test feedback so it can be formally released - give it a try

see: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279128237/

edit: I note that you replied in the other thread so ignore this
Title: Re: Graphic LCD (KS0108) library now available
Post by: madepablo on Aug 01, 2010, 08:26 pm
Hi mem,

In this post i used version 2.

But a couple of minutes ago, i also tested the new version, and it also works fine!!! Thanks!
See my configuration in the other post.

Just only.. i wired the pin 19 to ground with a 330Ohms resistance, and pin 20 to +5V... but backlight doesn`t light... how should i have the backlight running?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 01, 2010, 08:33 pm
Quote
Just only.. i wired the pin 19 to ground with a 330Ohms resistance, and pin 20 to +5V... but backlight doesn`t light... how should i have the backlight running?

Check your datasheet but many GLCD panels use pin 19 for +v to the backlight and pin 20 for ground. The resistor can go on either side
Title: Re: Graphic LCD (KS0108) library now available
Post by: madepablo on Aug 01, 2010, 08:40 pm
My datasheet say:

19 K  BL Cathode
20 A  BL Anode

It runs now. Seems that 330ohms is so much... y used 5,6 ohms in agreement with the datasheet, what propose 5ohms for +5V Vcc. Now it works perfect.

Thanks!
Title: Re: Graphic LCD (KS0108) library now available
Post by: maujabur on Aug 01, 2010, 09:37 pm
@bperrybap about Thom:

he sent me this picture:

(http://www.jdat.com.br/images/stories/thom.jpg)

And after identifying the controller, this library worked:

http://www.arduino.cc/playground/Code/LCD12864
Title: Re: Graphic LCD (KS0108) library now available
Post by: bperrybap on Aug 02, 2010, 12:33 am
I've had a chance to look closer at the st920 chip interface.
It is very different from a ks0108 style type of display.
It has some higher level commands, ,built in fonts,  user definable
fonts plus bitmap graphics capability.
It also has 3 interfaces: 8 bit, 4 bit, & serial.

The ks0108 type of device is a very "dumb" interface.
It is just a big bit mapped memory display with an 8 bit interface.

While it looks like a nice feature superset compared to a ks0108,
there will be some challenges trying to get this type of device
integrated into the glcd library (the ks0108 library really isn't a good option).


Because the ks0108 is a dumb bit mapped interface, the ks0108 type of device requires doing everything yourself. Which includes rendering fonts from font data stored in the user code (sketch).

The ks0108 on board graphic memory is based on 8 bit display pages that when the display panel is viewed with a wide aspect ratio (vs tall), the 8 bit pages draw 8 vertical pixels on the screen with bit 0, being the the top most pixel. Every time a page is written the address counter advances to the right.

In my initial look at the st920, it appears that it uses a 16 bit page split across 2 writes and also advances the address counter to the right. The real challenge with respect to a "ks0108" style library is that it appears that the 16 bit page draws 16 pixels horizontally when the display panel is viewed horizontally with the left
most pixel being bit 15.
This is a fundamental difference between it and the ks0108 style glcd pages.

The difference between vertical and horizontal pixel page display mapping is potentially a big deal depending on how the code is written.
Currently the ks0108 & glcd library code does not use a frame buffer.
This was very intentional to allow it run on smaller MCUs and not consume extra RAM memory regardless of the display panel geometry.

Because the ks0108/glcd code does not use a frame buffer, there are several places in the code that "understand" the page to pixel mapping direction and do pixel to page mappings on the fly, the biggest being the character rendering code.

Also, the font data created is currently generated for 8 bit vertical pages.

It is still possible to slide in support for a horizontally page mapped device, but it won't be a drop in. And there will have to be some design design decisions made as how to best fit it in.
Things like having different font data that maps to this style of device or map the font data from 8 bit vertical pages, to 16 bit horizontal pages on the fly as characters are rendered.

There is also a potential issue of how to handle the st920 built in fonts vs custom graphic rendered fonts. The built in fonts have some limitations on them that the glcd library fonts do not. Like pixel location and size. The glcd library can render any sized font on any x,y pixel value. The st790 has very limited number of internal fonts and has distinct boundaries where fonts must be drawn.
The glcd library also provides some options like inverse video mode and reverse (top to bottom) scrolling within user defined text areas that isn't supported by the st920 built in fonts.

But the st790 is not alone in these types of compatibility issues with the current ks0108/glcd library code. There are several other displays that have these capabilities including some that do not have read capability so it may be that adding support for this type of device is tied in with a bigger picture view of how to add support for this class of device and devices that do not provide read capability, rather than looking at it from the viewpoint simply getting support for the st790.

--- bill


Title: Re: Graphic LCD (KS0108) library now available
Post by: zooto68 on Aug 23, 2010, 08:03 pm
I am trying to use this library with a 128x64 LCD from Sure Electronics. This one :-

http://www.sureelectronics.net/goods.php?id=132

But I am getting nothing on the display except every pixel being lit. Everything seems to be connected as it should be. I'm using a Mega.

Any ideas?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Aug 23, 2010, 08:17 pm
Mike, try it with the beta version of the next release - see this thread:http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279128237/0

The most common cause of problems is wiring, double check that you have the LCD pins connected to the correct pins for the mega
Title: Re: Graphic LCD (KS0108) library now available
Post by: jccjoanne on Oct 07, 2010, 09:04 am
I know this sounds like a very dumb question... I am a total beginner... I just got my very first 128x64 LCD and Arduino board today! (Worked with 8051 and 16x2 LCD before) And this is my very first comment on this forum!  ;D

From ReadMe:

To install this library, just place this entire folder as a subfolder in your Arduino hardware/libraries folder.

When installed, this library should look like:

Arduino/hardware/libraries/ks0108                                (this library's folder)
Arduino/hardware/libraries/ks0108/ks0108.cpp             (the library implementation file)
Arduino/hardware/libraries/ks0108/ks0108.h                 (the library header file)
Arduino/hardware/libraries/ks0108/ks0108_Panel.h       (the Panel configuration header)
Arduino/hardware/libraries/ks0108/ks0108_Arduino.h   (header used to define pins for Atmega168/328)
Arduino/hardware/libraries/ks0108/ks0108_Mega.h      (header used to define pins for Mega)
Arduino/hardware/libraries/ks0108/ks0108_Sanguino.h (header used to define pins for Sanguino) - untested
Arduino/hardware/libraries/ks0108/SystemFont5x7.h     (definition for 5x7 system fonmt)
Arduino/hardware/libraries/ks0108/Arial14.h                 (the definition for 14 point Arial Font)
Arduino/hardware/libraries/ks0108/keywords.txt           (the syntax coloring file)
Arduino/hardware/libraries/ks0108/examples                 (diectory containing the example test sketch)
Arduino/hardware/libraries/ks0108/readme.txt               (this file)


However, I can't find Arduino/hardware/libraries/...
Can anyone tell me where I should place my extracted folder?  :P

HELP NEEDED... Thanks!

PS. I am using Arduino-0019
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 07, 2010, 09:55 am
Contributed libraries such as this one are now located in a directory called libraries in the directory that contains your sketches.

See the section on Contributed Libraries in this link: http://www.arduino.cc/en/Reference/Libraries
Title: Re: Graphic LCD (KS0108) library now available
Post by: jccjoanne on Oct 07, 2010, 04:09 pm
:-?Thank you! So, I have to open a "libraries" folder then import the library in arduino program. :-?
Title: Re: Graphic LCD (KS0108) library now available
Post by: mem on Oct 07, 2010, 04:39 pm
Open your Arduino sketchbook folder. If there is already a folder there called libraries, place the library folder in there. If not, create a folder called libraries in the sketchbook folder, and drop the library folder in there. Then re-start the Arduino programming environment, and you should see the new library in the Sketch > Import Library menu