Unable to compile GKOS example sketches

Yesterday I soldered together a GKOS keyboard on some perfboard but was unable to verify/upload the example sketches. The circuit I built and the library and example sketches are from http://playground.arduino.cc/Main/GkosMain. I suspect the errors I’m getting are because the code hasn’t been updated in a few years. I have tried with Arduino 1.0.5, and 1.5. I’m on a Mac and also tried my linux box. On the Mac I installed the Gkos library under /Applications/Arduino/Contents/Resources/Java/libraries and also tried using the Import Library… Add Library menu item.

This is the sketch I would like to run:

/* Test your Gkos with the Serial Monitor of the Arduino IDE

This is a simple test to check that your GKOS keypad is
working, by showing on serial monitor the text you type.

*/

#include <Gkos.h>

  char* gEntry = ""; 

// Initialize Gkos library with pin numbers for keys A to F.
// Digital pins 14...19 are the same as analog pins 0...5
  Gkos gkos(14, 15, 16, 17, 18, 19);

void setup(){

  Serial.begin(9600); // Set up Serial library at 9600 bps.
  // Use the Arduino SDE Serial Monitor to view the output! 

}

void loop(){

  gEntry = gkos.entry(); // Will return empty immediately if no entry
  if (gEntry != 0){gPrint();}

  // Add your other code here

}

void gPrint(){ // Convert commands depending on your application
  
  if (strcmp(gEntry, "_Enter") == 0){
      //Serial.println("");
      Serial.print(10, BYTE); Serial.print(13, BYTE); return;
  }
  if (strcmp(gEntry, "_BS") == 0){
      Serial.print(8, BYTE); return;
  }
  if (strcmp(gEntry, "_Del") == 0){
      Serial.print(127, BYTE); return;
  }
  if (strcmp(gEntry, "_Tab") == 0){
      Serial.print(9, BYTE); return;
  }

  // Default  
  Serial.print(gEntry);
  
}

Initially I got the following errors:

(In red) no matching function for call to 'Gkos::Gkos(int, int, int, int, int, int)'
(And in black below)

 In file included from sketch_dec09a.ino:8:
/Users/me/foo/libraries/Gkos/Gkos.h:10:22: error: WProgram.h: No such file or directory
In file included from sketch_dec09a.ino:8:
/Users/me/foo/libraries/Gkos/Gkos.h:20: error: expected `)' before 'APin'
/Users/me/foo/libraries/Gkos/Gkos.h:26: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:27: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:28: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:34: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:35: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:36: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:37: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:38: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:39: error: 'uint8_t' does not name a type
/Users/me/foo/libraries/Gkos/Gkos.h:40: error: 'uint8_t' does not name a type
sketch_dec09a:14: error: no matching function for call to 'Gkos::Gkos(int, int, int, int, int, int)'
/Users/me/foo/libraries/Gkos/Gkos.h:17: note: candidates are: Gkos::Gkos()
/Users/me/foo/libraries/Gkos/Gkos.h:17: note:                 Gkos::Gkos(const Gkos&)
sketch_dec09a.ino: In function 'void gPrint()':
sketch_dec09a:36: error: 'BYTE' was not declared in this scope

As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.

At some point yesterday I found a forum post somewhere that explained what to find/replace all instances of BYTE with. I couldn’t find what I did or the updated code - wait! - yes, I just found it. Thankfully ST2 saved it for me automatically. I was real close to fixing that error but gave up apparently. I just now found two more instances of Serial.print so I just fixed them and that BYTE error went away. So then I got the error about WProgram.h needing to be replaced in the library with Arduino.h. I just fixed that as I composed this post too. I’m left with one error now.

/Users/me/foo/libraries/Gkos/Gkos.cpp:10:10: error: #include expects "FILENAME" or <FILENAME>

There’s something on Stackoverflow talking about how you shouldn’t use standard text editors to manipulate code, so I opened SublimeText2 again and made sure line 10 of Gkos.cpp reads #include "Arduino.h".

So my current sketch is:

/* Test your Gkos with the Serial Monitor of the Arduino IDE

This is a simple test to check that your GKOS keypad is
working, by showing on serial monitor the text you type.

*/

#include <Gkos.h>

  char* gEntry = ""; 

// Initialize Gkos library with pin numbers for keys A to F.
// Digital pins 14...19 are the same as analog pins 0...5
  Gkos gkos(14, 15, 16, 17, 18, 19);

void setup(){

  Serial.begin(9600); // Set up Serial library at 9600 bps.
  // Use the Arduino SDE Serial Monitor to view the output! 

}

void loop(){

  gEntry = gkos.entry(); // Will return empty immediately if no entry
  if (gEntry != 0){gPrint();}

  // Add your other code here

}

void gPrint(){ // Convert commands depending on your application
  
  if (strcmp(gEntry, "_Enter") == 0){
      //Serial.println("");
      Serial.write( byte(10) ); Serial.write( byte(13) ); return;
  }
  if (strcmp(gEntry, "_BS") == 0){
      Serial.write( byte(8) ); return;
  }
  if (strcmp(gEntry, "_Del") == 0){
      Serial.write( byte(127) ); return;
  }
  if (strcmp(gEntry, "_Tab") == 0){
      Serial.write(byte (9) ); return;
  }

  // Default  
  Serial.write(gEntry);
  
}

and the error I get is still:

/Users/me/foo/libraries/Gkos/Gkos.cpp:10:10: error: #include expects "FILENAME" or <FILENAME>[

Thanks for help resolving this! I imagine once it’s fixed it would be good to update the files at http://playground.arduino.cc/Main/GkosMain.

Hey I fixed it! I deleted the Gkos library folder and reimported it, editing the Gkos.cpp and Gkos.h library files with ST2 only and not TextEdit to take WProgram.h and change it to Arduino.h. Then the example serial read sketch worked with my changes from Serial.print to Serial.write.

I can now verify and upload the code without issue. I prefer the hardware side of stuff but I guess just articulating the problems in a forum post and doing as much research as I would expect other people on this forum would expect me to do worked. Joy.

By the way how ever was saying that you can't edit the code with notepad and such text editors is a complete fool.

Mark

Edited the Gkos main page with the following:

"In order to use the software library and example sketches with Arduino 1.0+, line 10 of Gkos.cpp and Gkos.h should be updated from WProgram.h to Arduino.h, and instances of Serial.print(x, BYTE) should be changed to Serial.write( byte (x) )."

Also, as of day one I can touch type about 6 words a minute with 95% accuracy using a tiny perfboard and tactile push buttons.

Day three with my GKOS project! Instead of connecting the Arduino to a computer and opening up a serial port monitor to show off my project, I wanted something self contained that only needed power. I really prefer the Nokia 5100 over the LCD used in the example sketch for the Gkos library, and plus it’s what I have laying around.

I just figured out how to adapt the LCD test example sketch for this particular display. This requires the PCD8544 and GFX libraries from Adafruit in addition to the Gkos library.

/*
 December 10th, 2013
 Wade Smith
 Test a Gkos keyboard on the Nokia 5100 series LCD
 Free code
*/

// include libraries:
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Gkos.h>

  char* gEntry = ""; 

// initialize libraries with numbers of the interface pins
// pin 7 on Arduino is pin 3 on LCD
// pin 6 on Arduino is pin 4 on LCD 
// pin 5 on Arduino is pin 5 on LCD
// pin 4 is N.C. to CS on LCD
// pin 3 on Arduino is pin 7 on LCD
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
Gkos gkos(14, 15, 16, 17, 18, 19);

void setup(){

  // set up the display
  display.begin();
  delay(0);
  display.clearDisplay();
  display.setContrast(100);
  display.setCursor(0,0);

}

void loop(){

  gEntry = gkos.entry(); // Will return empty immediately if no entry
  if (gEntry != 0){gPrint();}

}

void gPrint(){ // Convert commands depending on your application
  
  if (strcmp(gEntry, "_Enter") == 0){
      //Serial.println("");
      Serial.write( byte(10) ); Serial.write( byte(13) ); return;
  }
  if (strcmp(gEntry, "_BS") == 0){
      Serial.write( byte(8) ); return;
  }
  if (strcmp(gEntry, "_Del") == 0){
      Serial.write( byte(127) ); return;
  }
  if (strcmp(gEntry, "_Tab") == 0){
      Serial.write(byte (9) ); return;
  }
  
  // Put text on the screen 
  display.display();
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.print(gEntry); 
}