Pages: 1 [2] 3 4 ... 29   Go Down
Author Topic: Graphic LCD (KS0108) library now available  (Read 46924 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: September 01, 2008, 09:07:37 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
.
Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
« Last Edit: September 02, 2008, 07:21:47 am by HULK » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-wink

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

Here is as sketch that shows how to print floating point to the GLCD.
Code:
/*
 * 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()
« Last Edit: September 02, 2008, 08:19:59 am by mem » Logged

Sweden, Malmö
Offline Offline
Full Member
***
Karma: 2
Posts: 200
Rooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

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



Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino mola
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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”
« Last Edit: September 23, 2008, 06:00:25 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino mola
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Mem,
I have posted a short video in youtube:

I also insert here the code for the sample program.

Code:
#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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino mola
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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;
« Last Edit: September 23, 2008, 09:52:15 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino mola
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...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.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
« Last Edit: September 23, 2008, 12:17:00 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino mola
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
}
« Last Edit: September 24, 2008, 03:16:00 am by mem » Logged

Pages: 1 [2] 3 4 ... 29   Go Up
Jump to: