Keypad library compiling errors

hi,
I am relatively new to arduino, but having a good time experimenting.
I am trying to get the keypad library to work with the example program, using arduino 1.0, and getting the following errors.

I have tried a variety of things, but cant figure out what i am doing wrong. i realise it must be something simple, but any assistance would be welcome!

Program:

#include <Keypad.h>

/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
//#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{‘0’,‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’,‘7’},
{‘8’,‘9’,‘A’,‘B’},
{‘C’,‘D’,‘E’,‘F’}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();

if (customKey != NO_KEY){
Serial.println(customKey);
}
}

compilation errors:

CustomKeypad:50: error: redefinition of ‘const byte ROWS’
CustomKeypad:13: error: ‘const byte ROWS’ previously defined here
CustomKeypad:51: error: redefinition of ‘const byte COLS’
CustomKeypad:14: error: ‘const byte COLS’ previously defined here
CustomKeypad:53: error: redefinition of ‘char hexaKeys [4][4]’
CustomKeypad:16: error: ‘char hexaKeys [4][4]’ previously defined here
CustomKeypad:59: error: redefinition of ‘byte rowPins [4]’
CustomKeypad:22: error: ‘byte rowPins [4]’ previously defined here
CustomKeypad:60: error: redefinition of ‘byte colPins [4]’
CustomKeypad:23: error: ‘byte colPins [4]’ previously defined here
CustomKeypad.cpp: In function ‘void setup()’:
CustomKeypad:65: error: redefinition of ‘void setup()’
CustomKeypad:28: error: ‘void setup()’ previously defined here
CustomKeypad.cpp: In function ‘void loop()’:
CustomKeypad:69: error: redefinition of ‘void loop()’
CustomKeypad:32: error: ‘void loop()’ previously defined here

I just installed the keypad library and your example compiles without error with the V1.0 IDE.

Pete

The compiler appears to be seeing two copies of your program. Check that if you scroll down in the editor, you don't find that your sketch contains a second copy of the program.

I am having similar problems when I try running one of the example keypad sketches on Arduino-1.0, Uno, WinXPHome:

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
}

void loop(){
char key = keypad.getKey();

if (key){
Serial.println(key);
}
}

C:\Program Files\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -IC:\Program Files\arduino-1.0\hardware\arduino\cores\arduino -IC:\Program Files\arduino-1.0\hardware\arduino\variants\standard -IC:\Program Files\arduino-1.0\libraries\Keypad C:\DOCUME~1\EP4CD1~1.JAS\LOCALS~1\Temp\build290490409380960528.tmp\HelloKeypad.cpp -oC:\DOCUME~1\EP4CD1~1.JAS\LOCALS~1\Temp\build290490409380960528.tmp\HelloKeypad.cpp.o
HelloKeypad:56: error: redefinition of ‘const byte ROWS’
HelloKeypad:11: error: ‘const byte ROWS’ previously defined here
HelloKeypad:57: error: redefinition of ‘const byte COLS’
HelloKeypad:12: error: ‘const byte COLS’ previously defined here
HelloKeypad:58: error: redefinition of ‘char keys [4][3]’
HelloKeypad:13: error: ‘char keys [4][3]’ previously defined here
HelloKeypad:64: error: redefinition of ‘byte rowPins [4]’
HelloKeypad:26: error: ‘byte rowPins [4]’ previously defined here
HelloKeypad:65: error: redefinition of ‘byte colPins [3]’
HelloKeypad:28: error: ‘byte colPins [3]’ previously defined here
HelloKeypad:67: error: redefinition of ‘Keypad keypad’
HelloKeypad:31: error: ‘Keypad keypad’ previously declared here
HelloKeypad.cpp: In function ‘void setup()’:
HelloKeypad:69: error: redefinition of ‘void setup()’
HelloKeypad:33: error: ‘void setup()’ previously defined here
HelloKeypad.cpp: In function ‘void loop()’:
HelloKeypad:73: error: redefinition of ‘void loop()’
HelloKeypad:37: error: ‘void loop()’ previously defined here

Strange, I just installed the keypad library from http://arduino.cc/playground/uploads/Code/keypad.zip, cut and pasted that code into Arduino 1.0 IDE, and it compiled OK.

Is it just the keypad library that is giving you problems or does the blink example give you problems too?

Blink works fine. I have had previous success using the LCD and Servo libraries. I have also run a toy motor; no library was involved.

Keypad.h & keypad.cpp are in the Library subdirectory of the Arduino-1.0 directory--- for what it is worth.

EJasper:
Blink works fine.
I have had previous success using the LCD and Servo libraries. I have also run a toy motor; no library was involved.

It looks like a problem I was having when I had the library files open in tabs in the Arduino IDE but unless you made an effort to do something really strange then that can’t be the case.

I could use some more error reporting. Can you go to the menu File->Preferences, find and check the checkbox for Show verbose output during: compilation then post the errors. There should be quite a bit more output.

Keypad.h & keypad.cpp are in the Library subdirectory of the Arduino-1.0 directory— for what it is worth.

That should be fine. I see the include -IC:\Program Files\arduino-1.0\libraries\Keypad in the compilation command.

hi, thanks for the comments.

here is the error log on compiling with verbose switched on:

C:\Users\Jon\Documents\Admin\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -IC:\Users\Jon\Documents\Admin\arduino-1.0\hardware\arduino\cores\arduino -IC:\Users\Jon\Documents\Admin\arduino-1.0\hardware\arduino\variants\standard -IC:\Users\Jon\Documents\Admin\arduino-1.0\libraries\keypad C:\Users\Jon\AppData\Local\Temp\build5103281910444848493.tmp\CustomKeypad.cpp -oC:\Users\Jon\AppData\Local\Temp\build5103281910444848493.tmp\CustomKeypad.cpp.o CustomKeypad:50: error: redefinition of 'const byte ROWS' CustomKeypad:13: error: 'const byte ROWS' previously defined here CustomKeypad:51: error: redefinition of 'const byte COLS' CustomKeypad:14: error: 'const byte COLS' previously defined here CustomKeypad:53: error: redefinition of 'char hexaKeys [4][4]' CustomKeypad:16: error: 'char hexaKeys [4][4]' previously defined here CustomKeypad:59: error: redefinition of 'byte rowPins [4]' CustomKeypad:22: error: 'byte rowPins [4]' previously defined here CustomKeypad:60: error: redefinition of 'byte colPins [4]' CustomKeypad:23: error: 'byte colPins [4]' previously defined here CustomKeypad.cpp: In function 'void setup()': CustomKeypad:65: error: redefinition of 'void setup()' CustomKeypad:28: error: 'void setup()' previously defined here CustomKeypad.cpp: In function 'void loop()': CustomKeypad:69: error: redefinition of 'void loop()' CustomKeypad:32: error: 'void loop()' previously defined here

cheers jon

Hmm, something didn't work right. There should have been tons more output. But before we go down that road lets clean out any temp files and try again.

Close the Arduino software and then delete the folder:

C:\Users\Jon\AppData\Local\Temp\build5103281910444848493.tmp

Also, any other folders in Temp that start with build*.

Then restart the Arduino software and try again.

By the way, do the other keypad examples compile without errors?

-Mark

I just ran into this exact same problem. Looking for answers I found this post and upon seeing the comment that it appears to be thinking there are 2 copies of the sketch i check the library folders and found the there is both a *.ino and *.pde so i just deleted the *.pdes for the example folders and it is working now.

Thanks tempist235,

I tried to provide two separate folders for the examples. One for .pde files and one for .ino files. I don’t think it’s because I provided two separate copies. It seems that using Arduino 1.0 finds the .pde’s and saves them as .ino. I’m not sure what I’ll do but I’ll watch for people with this problem.

You are THE MAN!!! I deleted .pde files and HelloKeypad compiles and uploads without any errors..... but still doesn't work. I am using different pin assignments though.

Thanks to jonl for letting me ride on his thread and everyone that contributed to the solution.

Hi, Thanks all, this has done the trick for me too :)

cheers jon