GLCDdiags - compile error

Trying to follow the OpenGLCD reference document and trying to interface a KS108 based GLCD to the UNO.

First problem I came across is that the GLCDdiags in the library did not compile and threw an error :

GLCDdiags:153: error: ISO C++ forbids declaration of ‘SerialPrintP’ with no type [-fpermissive]
SerialPrintP(PGM_P str )

Second Problem :

All the pin connections to the UNO from the GLCD are exactly done as per the reference document.

Powering up from UNO itself as the total current including backlight comes to about 170mA. But on power up its just a blank lit screen with no characters for the full range of Contrast adjustment ( I am trying to run the ks108example.ino which is compiling OK )

The GLCD data sheet ( attached ) says for Contrast I need to use a 10K resistor between Vout ( -15V)and GND and connect the wiper to contrast Pin. This is unusual ( or is it usual for GLCDs? ) as I normally use a 5K pot between 5V and GND and use the wiper for 4Lx20C LCDs.

Then there are two pins called A1 and A2 which as per data sheet are mentioned as A1 = Yellow Green and A2 = Red or Orange. What are these pins and how to connect the A1 if I need Yellow Green ?

Lampex_LG128641.pdf (90.7 KB)

Trying to follow the OpenGLCD reference document

Give it a rest. By now, you KNOW that this is not enough information. You KNOW that you have to post a link!

Here we go :

There is no code in that zip file.

Oh I thought you wanted the reference document !!

Here is the link for the GLCD library and I am usin the latest version.

( Incidentally to make it easy for you I tried to post the offending sketch alone but it was exceeding the allowed size of 9000 letters :frowning:

On that page, there is a Downloads link, with 14 things to download. I have only a 7% chance of downloading what you did if I just stab at one line.

Trying to follow the OpenGLCD reference document and trying to interface a KS108 based GLCD to the UNO.


Then there are two pins called A1 and A2 which as per data sheet are mentioned as A1 = Yellow Green and A2 = Red or Orange. What are these pins and how to connect the A1 if I need Yellow Green ?

Googling on the Contrast pin detail for the GLCD, the hook up is now clear.

Has anyone used a module with the above A1 and A2 pins as referred in my post ? Any idea to activate them if one of then needs to be connected to Vcc or GND. I am scared to do a trial and error as these modules are pretty finicky about wrong connections...


Just to help someone checkout why I am getting the error "Two or more datatypes in declaration of ‘setup’ " I have removed initial comments and all code from inside of loop() and posted the rest. When I try to compile this the error shows up. Not sure why… or am I the only one getting this error ? Since its a code in public domain, I thought it must have happened to someone else also??

 * GLCDdiags

#include <openGLCD.h>
#include "openGLCD_Buildinfo.h"
#include "include/glcd_io.h"
#include "include/glcd_errno.h"

#if defined(__AVR__)
#include <avr/pgmspace.h>
#ifdef PROGMEM
#undef PROGMEM
#define PROGMEM __attribute__((section("")))
#define PROGMEMDIAG __attribute__((section(".progmem.diag")))
#define P(name)   const char name[] PROGMEMDIAG   // declare a const string in AVR Progmem

// The rest of the world is so much simpler and normal
#define P(name)   const char name[]   // declare a const string

#define chip2x1(chip) ((chip * CHIP_WIDTH) % DISPLAY_WIDTH)
#define chip2y1(chip) (((chip * CHIP_WIDTH)/DISPLAY_WIDTH) * CHIP_HEIGHT)
#define chip2x2(chip) ((chip2x1(chip) + CHIP_WIDTH) >= DISPLAY_WIDTH ? DISPLAY_WIDTH-1 : chip2x1(chip) + CHIP_WIDTH-1)
#define chip2y2(chip) ((chip2y1(chip) + CHIP_HEIGHT) >= DISPLAY_HEIGHT ? DISPLAY_HEIGHT-1 : chip2y1(chip) + CHIP_HEIGHT-1)

#define MAX_ERRORS 10 // maximum errors per indivual test

#ifdef _AVRIO_AVRIO_
void _SerialPrintPINstr(avrpin_t pin, const char *pinstr, uint8_t avrport,
	 uint8_t avrbit);

#define SerialPrintPINstr(x) \


void _SerialPrintPINstr(const char *pinstr);
#define SerialPrintPINstr(x) _SerialPrintPINstr(str(x))

 * Prototypes
void showGLCDconfig(void);
uint8_t lcdmemtest(void);
uint16_t getglcdspeed();
uint8_t lcdw1test(void);
uint8_t lcdrwseltest();
int lcdhpagetest(uint8_t x1, uint8_t x2, uint8_t spage, uint8_t epage,
	 uint8_t sval, uint8_t eval);
int lcdvpagetest(uint8_t x1, uint8_t x2, uint8_t spage, uint8_t epage,
	 uint8_t sval, uint8_t eval);

 * declare a string for a horizontal line in program memory
P(hline) =  "--------------------------------------------------------------------\n";


#define xstr(s) str(s)
#define str(...) #__VA_ARGS__

 * Function to print a simple Quoted string to serial port.
 * The string is automagically forced to live in AVR flash/program space.

#define SerialPrintQ(str) SerialPrintP(PSTR(str))

 * print Progmem string to the serial port
 * (have to insert carriage returns as serial port runs in 'raw' mode)

SerialPrintP(PGM_P str )
  char c;
  PGM_P p = str;

  while ((c = pgm_read_byte(p++)))
    if(c == '\n')


 * Define a REAL printf since Arduino doesn't have one
 * SerialPrintf() will automatically put the format string in AVR program space

#define SerialPrintf(fmt, ...) _SerialPrintf(PSTR(fmt), ##__VA_ARGS__)

extern "C" {
  int serialputc(char c, FILE *fp)
      if(c == '\n')

_SerialPrintf(const char *fmt, ...)
FILE stdiostr;
va_list ap;

  fdev_setup_stream(&stdiostr, serialputc, NULL, _FDEV_SETUP_WRITE);

  va_start(ap, fmt);
  vfprintf_P(&stdiostr, fmt, ap);

 * Define an eprintf() function for error output
 * (map it to the SerialPrintf() defined above)
#define eprintf(...) SerialPrintf(__VA_ARGS__)


 * GlcdPrintf() will automatically put the format string in AVR program space
#define GlcdPrintf(fmt, ...) GLCD.Printf_P(PSTR(fmt), ##__VA_ARGS__)

void setup()
  delay(5);	// allow the hardware time settle

#if defined(CORE_TEENSY) || defined(__AVR_ATmega32U4__)
	// wait on USB serial port to be ready but timout out after 10 seconds
	if(millis() > 10000) // millis starts at 0 after reset
  } while(!Serial);


  SerialPrintQ("Serial initialized\n");

{   // run over and over again

// All code removed from here to make the atachment small for forum post..


What version of the IDE and openGLCD are you using?
There are a few versions of the IDE that have serious errors in them that could cause those types of errors.
They are noted in the "known issues" section on the wiki.
Also, I put out a patch release in Feb 2016 to work around one of issues in IDE 1.6.7 so make sure you have the latest version available installed.

For your contrast pot, there is information about this in the included documentation. The data sheet is correct; it does not work like a typical hd44780 contrast pot.
There is a full paragraph on how to wire up the contrast pot on the Wiring->KS0108 page of the included documentation.

You will see no pixels until all the wiring is correct and everything is working.

For A1 and A2 it looks like that display has two different backlights that are controlled by two different anode connections using a common ground with the lcd chipset.
Of the MANY ks0108 displays datasheets I have, I have never seen this done before.
I'm guessing if you turn on A1 you get yellow green. If you turn on A2 you get red, and if you turn them both on you get orange?

--- bill

Since its a code in public domain, I thought it must have happened to someone else also??

Just as point of clarification, while the code is open source and readily available, it is not "public domain".
It is licensed GPL v3.

as to why it isn't working, I'm guessing you have combination of an older version of openGLCD (which is missing some work arounds for various bugs in the newer IDEs) and are using a newer IDE like 1.6.5 through 1.6.8

For sure avoid 1.6.6 and 1.6.8 those IDEs have serious issues. 1.6.8 is so broken that they should have immediately removed it from the arduino site.

--- bill

Hi Berrybap,

SO refreshing to see your positive responses .

Got your point regarding the Open licence.

I am using IDE version 1.6.7. And the GLCD library is

My GLCD module of course seems to be an odd one - but one that was working well with my earlier 8051 MCU kit ( no longer with me ). Anyway that pins A1 and A2 are indeed odd and I have ordered a few fresh modules from Amazon. Let me check them out.

I did read all about the contrast adjustment in the Arduino learning pages.

So I guess I will not waste anymore time ( of mine and others !!) on the seemingly dud module that I have and wait for the new ones to arrive to start trials again.

Thanks for your support !

The IDE has lots of funky code in it that attempts to allow improper C/C++ code to work by converting "Arduino" code back to proper C++ code.
Unfortunately, you are running into one of the many IDE issue that mangles up perfectly valid code and breaks it when trying to insert function prototypes.

I've worked with the IDE developers to try to help them fix most of these issues, but they have not been able to solve all of them.
I have put work arounds into the openGLCD code to avoid triggering their errors.

I never intended the 1.0 release to drag out so long.
I've been quite distracted with other things for a quite some time.
For now, just go get the v1.0rc2-14 patch release and use that.
It should resolve the issue.

I would think that module would work with openGLCD.
Other than the backlight signals, everything else looks pretty typical for a ks0108 display.
I assuming that A1 and A2 are the anode signals for the backlights.
So all you need to do is connect Vcc to them to enable either one or both.
I'd first start out using a resistor as isn't clear if one is needed. Or look on the PCB and see if you can see a resistors in line with the A1 and A2 signals as many glcds have the resistors already on the PCB.
But you said in your first post that the backlight was working so I'm not sure the problem there.

Once you get the new library installed, you should be able to run the diag sketch and that will help
getting the rest of the wiring connections debugged.

Unfortunately, with ks0108 dipslays, nothing shows up on the display until pretty much all the connections are correct. It isn't like a hd44780 display where some pixels will show up when power is applied.
The ks0108 requires a command to turn on the pixels.

--- bill

Wow …BerryBap ! I am frankly stunned to see your commitment to a cause. Kudos !

The patch you referred to compiles perfect. Thank you so much.

The current GLCD module seems to be broke as you can see from the Serial Diagnostics below. I tried with BL on and the result was same.

Serial initialized
Reported Arduino Revision: 1.6.7
F_CPU: 16000000
Lib Configuration: openGLCD ver: 1.0rc2-14 build: v1.0rc2-14-ga8b9f57
Panel Configuration:ks0108-128x64
Pin Configuration:ks0108-Uno
GLCD:ks0108 DisplayWidth:128 DisplayHeight:64
Chips:2 ChipWidth:64 ChipHeight:64
 RW:A2(PIN_C2) DI:A3(PIN_C3) EN:A4(PIN_C4)
 D0:8(PIN_B0) D1:9(PIN_B1) D2:10(PIN_B2) D3:11(PIN_B3)
 D4:4(PIN_D4) D5:5(PIN_D5) D6:6(PIN_D6) D7:7(PIN_D7)
Delays: tDDR:320 tAS:140 tDSW:200 tWH:450 tWL:450
 CHIP0:(A0,0x1, A1,0x0)
 CHIP1:(A0,0x0, A1,0x1)
Data mode: 
 d0-d3:nibble mode-Non-Atomic
 d4-d7:nibble mode-Non-Atomic
Backlight: <Not configured>
Diag Loop: 1
Initializing openGLCD
GLCD initialization Failed: RESET wait Timeout (status code: 2)
Test Count: 0 PASSED 1 FAILED

Once the new GLCD is received from Amazon I will check it out. Once thanks for taking the time to clarify things. Super !!

In over 6 years of of users using this library and its predecessor glcdv3, I've only seen 2 broken glcd modules.
All the others were wiring related. Either bad/broken wires, poor soldering, or miswiring.
And the 2 that were broken, were fried from miswiring
So the odds are highly likely that the glcd is good and there is some sort of wiring issue or possible configuration issue.
Usually when there is a configuration something still shows up on the display, but not always.

That error means that the library polled for the glcd to indicate that it was finished with its reset initialization and after looking for a period of time that was way too long it gave up.
In order to work it requires that data bit6, R/W, DI, EN, CS1, CS2, and reset all be hooked up correctly
AND.... it requires that the library know how the active states for CS1 and CS2 work in order to be able to select each chip to talk to it.
While the default config file uses the most common CS selection states, not all glcds work the same.
Unfortunately, the datasheet you posted does not have enough information to tell how the CS pins work.

My money would still be on a wiring issue.

--- bill