Using Graphics LCD: KS0108 LCD 128x64

I am using the KS0108 LCD. I have used the LCD on my Uno board and had no problems. I cannot get it to display anything on the Mega 2560. I have tried using the same program developed for the Uno on the Mega. I changed the program to include the header files:

#include <ks0108.h>
#include <ks0108_Mega.h>
#include <Arial14.h>
#include “SystemFont5x7.h”
#include “ArduinoIcon.h”

I also changed the pin mapping to

(LCD Pin, Mega Pin)

(1 [VSS], +0v ground)
(2 [VDD], +5v power)
(3 [VO], Center Pin PIN 18 Potentiometer)
(4 [D/I], 36 )
(5 [RW], 35)
(6 [E], 37)
(7 [DB0], 22)
(8 [DB1], 23
(9 [DB2], 24)
(10 [DB3], 25)
(11 [DB4], 26)
(12 [DB5], 27)
(13 [DB6], 28)
(14 [DB7], 29)
(15 [CS1], 33)
(16 [CS2], 34)
(17 [RST], Reset)
(18 [VEE], Left POT with Right POT to +5v)
(19 [A], +5v - 100 - 200 ohm resister for overload protection)
(20 [K], ground)

Any ideas on how to get this working?

Are we to presume that the code matches the pin layout that you defined?

The header file "ks0108_Mega.h" contains the following:

define CSEL1 33 // CS1 Bit

define CSEL2 34 // CS2 Bit

define R_W 35 // R/W Bit

define D_I 36 // D/I Bit

define EN 37 // EN Bit

My LCD doesn't label a pin D_I, so I am using the pin labeled RS (pin 4) for this. This interpretation worked for the Uno.

My wiring is consistent with the header file for these 5 pins. Also, the header states "This version uses pins 22-29 for LCD Data" which is consistent with how the device is connected to the board.

The header file "ks0108.h" doesn't seem to specify pins.

So for the pins above, I believe my wiring is correct. Is there another file that needs to be edited?

Has anyone here had any experience with using a graphics LCD with the Mega2560. If so, I would appreciate any help you could give me.

I Think I solved your problem. Go into the KS0108.h and where the defines for chipsets is, add an elif define for the AVR_ATmega2560 and include the 1280 include file.

// Chip specific includes

if defined(AVR_ATmega1280)

include "ks0108_Mega.h" // include this for the Arduino Mega other ATmega1280 boards

elif defined(AVR_ATmega2560)

include "ks0108_Mega.h" // include this for the Arduino Mega2560 other ATmega1280 boards

elif defined (AVR_ATmega644) // TODO - check this define

include "ks0108_Sanguino.h" // include this for Sanguino or ATmega644 boards

else

include "ks0108_Arduino.h" // include this for the Arduino or other ATmega168 boards

endif

Worked for me.

Tracked it down by serialing out print statements as to where the code was and then included defines to figure out what files the compiler had actually worked with.

:)

PHIL, YOU NAILED IT!!!

Wow, much thanks. I appreciate your taking the time to come in here and make a post to let me (us) know what the problem was.

As you stated, I went into the file

C:\Program Files\arduino-0021\libraries\ks0108\ks0108.h

and in the existing section

// Chip specific includes
#if defined(__AVR_ATmega1280__)
#include "ks0108_Mega.h"  // include this for the Arduino Mega other ATmega1280 boards
other ATmega1280 boards
#elif defined (__AVR_ATmega644__)  // TODO - check this define
#include "ks0108_Sanguino.h"   // include this for Sanguino or ATmega644 boards
#else
#include "ks0108_Arduino.h"  // include this for the Arduino or other ATmega168 boards
#endif

I inserted

#elif defined(__AVR_ATmega2560__)
#include "ks0108_Mega.h"  // include this for the Arduino Mega2560

to give the final form of

// Chip specific includes
#if defined(__AVR_ATmega1280__)
#include "ks0108_Mega.h"  // include this for the Arduino Mega other ATmega1280 boards
#elif defined(__AVR_ATmega2560__)
#include "ks0108_Mega.h"  // include this for the Arduino Mega2560 other ATmega1280 boards
#elif defined (__AVR_ATmega644__)  // TODO - check this define
#include "ks0108_Sanguino.h"   // include this for Sanguino or ATmega644 boards
#else
#include "ks0108_Arduino.h"  // include this for the Arduino or other ATmega168 boards
#endif

#include "ks0108_Panel.h"      // this contains LCD panel specific configuration

My Hello World application is (From AdaFruit)

  #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 totalNumberOfLoops = 0;

void setup()
{
  // initialise the library
  GLCD.Init(NON_INVERTED);
  GLCD.ClearScreen();
  //Draw the bitmap at the given x,y position.
  GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); 
  delay(3000);
  
  GLCD.ClearScreen();
  
  // select fixed width system font 
  GLCD.SelectFont(System5x7);
}

void loop()
{
  startMillis = millis();
  //Loop for the specified number of milliseconds.
  while( millis() - startMillis < 5000)
  {
    //Rectangle on the left side of the screen.
    GLCD.DrawRect(0, 0, 64, 61, BLACK);
    
    //Rounded rectangle on right side around the text area.
    GLCD.DrawRoundRect(68, 0, 58, 61, 5, BLACK);
    
    //Draw lines from upper left corner to right side of rectangle. Each
    //loop moves the line down 4 pixels.
    for(int i=0; i < 62; i += 4)
    {
      GLCD.DrawLine(1,1,63,i, BLACK);  
    }
    //Draw circle centered in the left side of screen.
    GLCD.DrawCircle(32,31,30,BLACK);
    
    //Clear previous spinner position
    GLCD.FillRect(92,40,16,16, WHITE);
    
    //Locate curser for printing text.
    GLCD.CursorTo(2,5);
    
    //Print current loop count at the current cursor position 
    GLCD.PrintNumber(++totalNumberOfLoops);
  } 
  //Display total number of loops.
  GLCD.ClearScreen();
  
  GLCD.CursorTo(12,2);
  GLCD.Puts("Count:");
  
  GLCD.CursorTo(12,3);
  GLCD.PrintNumber(totalNumberOfLoops);           
 }

Phil, thanks again for the help.

One note I’ll add is that when uploading to the board, you have to disconnect the reset wire. Once the application is uploaded, you can reconnect the reset. If you don’t disconnect the reset, the program will not load. Once the reset wire has been reconnected, make sure you press the reset button on the board to get things going correctly.

Old FORTRAN’r… hunt it down, kill it, and eat it with lots of write statements to track down the varmant!

These are really nice boards… because of the extensive open source libraries tied to the open design.

Cheers!

Phil :sunglasses:

Phil, I am interested in how you tracked down the problem. When you say you were using write statements, were you writing to a Serial window? What were you writing out? Did you go into the library to insert these write statements?

The process is almost as important as the solution.

Thanks.

First, I reviewed the header file and identified the conditional compilation statements: #if etc. and identified the defines being used to trigger which include file is used. I had previously in my code added a serial out debugging the code. I put in Serial.println statements in my code so I could in the terminal output and see if the program was running. Putting in a series of these print statements identified the program would start but bombed on attempting to put any text out to the display. I became suspicious the code generated was trying to talk via the pins for say an Uno.... because the board's display was lighting up properly.

So... when I found the mega1280 define, I copied those statements into my code and substituted Serial.println statements for the include files. When I ran my code again I could see in the terminal output that the include file declarations were falling through to the catch all include. So now we know my suspicion about usage of the wrong pins was correct. Next put in an conditional println statement using what I guessed would be the define to use, if the toolchain supported the mega2560. Bingo... the println statement popped up in my serial output. So.... to finish off the bug issue, tweaked the header file to add the mega2560 tied to the earlier mega's include file. End of story. Except for deleting all those hack and chop println statements.

:)

Thanks for the quick reply.

When I had originally tried to debug with the serial print statements, I got nothing. I had also tried including the 2560 header file directly into my sketch and that didn't solve my problem. So apparently it makes a difference where you do the include. Odd.

I am glad you were more methodical and stuck with it. That is a lesson learned for me.