Anyone successful using the Keypad library with an ATMega1284P ???

Hi all,

I'm in the process of migrating a project that incorporates a 2x3 matrix keypad from a '328 to a 1284P . I'm using 1.0.1 and maniacbug's 1284P bootloader, cores etc. I immediately ran into the undefined INPUT_PULLUP problem, for which there is an extensive discussion on the forum. However, the discussion is mostly about the finer points of how the Arduino team chose to deal with internal pullups, and less about making the Keypad library work with other than '328 hardware. I've read the thread several times and, while it makes a bit more sense to me each time- I still can't figure out what's going on.

For anyone who has already seen this thread, I've eliminated the compile error by placing (v 1.0.1) copies of Arduino.h and wiring_digital.c in the 1284P hardware directory structure. Unfortunately, my kepad still does not work. I have also tried placing

pinMode(pin, INPUT);
digitalWrite(pin HIGH);

in my code to force the row, column pins to be inputs with pullups enabled. Still no keypad. So now I'm wondering what else might be preventing it from working. Maybe something else specific to this chip? So, if you've managed to get a keypad working with a 1284P, I'd sure appreciate some pointers!

thanks,
Pat

I'll try to remember to check out my RF remote control code on a '1284 board when I get home. Used a 4x4 keypad vs 3x4.

Running this simple code, I also cannot get a 1284P to read a keypad.

Looked at signal lines with a scope, all pins involved are just sitting at high level - no scanning appears to be happening.
Attached are the files in the Keypad library.

// Keypad example from playground with Bobuino pinout of ATmega284P
// read a character from 4x4 matrix

// Velleman 4 x 4 matrix keypad 
// keypad 1 (Col1) to D21
// keypad 2 (Col2) to D20
// keypad 3 (Col3) to D19
// keypad 4 (Col4) to D18
// keypad 5 (Row1) to D17
// keypad 6 (Row2) to D16
// keypad 7 (Row3) to D15
// keypad 8 (Row4) to D14

// Rows have Internal Pullups

// bring in the library(s)

#include <Keypad.h>         // Matrix Keypad library

// set up the Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns

// Define the Keymap
char keys[ROWS][COLS] = 
{
  {  '1','2','3','A'        }  ,  // row 1
  {  '4','5','6','B'        }  ,  // row 2
  {  '7','8','9','C'        }  ,  // row 3
  {  '*','0','#','D'        }  ,  // row 4
};

// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins.
byte rowPins[ROWS] = { 
  14,15,16,17,  };  // Keypad uses internal pullups? No externals supplied

// Connect keypad COL1, COL2, COL3, COL4 to these Arduino pins.
byte colPins[COLS] = { 
  18,19,20,21 }; 

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

char key;

// ***********************************************************************
// set up the pins as Inputs, Outputs, etc.
void setup()
{
  Serial.begin(9600);
  Serial.println ("alive");
}
// ***********************************************************************
// Main loop for reading the keypad and sending the button pushed out
void loop()
{
  // read the keypad
  Serial.println ("reading");
  key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
  {
    Serial.print ("key");
    Serial.println(key);                         // reset count up to sleep if transmitted a key press

  }   
  delay(200);  // added to prevent screen from just blasting by

}                                             // end of void loop

Keypad.cpp (8.7 KB)

Keypad.h (5.57 KB)

keywords.txt (733 Bytes)

Here’s a scope trace what I could capture.
Occurs too far apart to see two of them on the screen at once.

DS0010.BMP (1.37 MB)

OK, I just tried re-installing maniacbug's '1284P package and then your keypad test code. Lo and behold, it worked!
Then I tried it with my project code, and that worked as well. (I also removed any later code that attempted to set the INPUT/OUTPUT and pullup status of the keypad input pins 'manually'.)

Still not sure why it wasn't working, but I'll take it for now!

tnx,
Pat

Still not working for me tho.
I've had the same mighty1284 setup for ages, this is the first time something hasn't worked.

-- Pat, that's really good news! It also gives me an idea of what went wrong.

-- CrossRoads, based on what happened with Pat I believe it might have been caused by how he moved the Arduino.h and wiring_digital.c files from the Arduino cores and placed them in maniacbug's build. Is there any chance you might have done the same thing? Also, what version of the IDE are you running? I've had a statistically significant number of problems that were fixed by moving away from version 1.0.3 of the software.

Nope - I haven't changed the arduino cores at all, and only copied the might1284 files in the same variants location as they were in under 1.0.3

The scope plot looks like the column pin is trying to go low but for some reason it won’t. Can you try adding an external pulldown resistor and scope it again? 4.7k to 22k should do.

We could also try adding a small delay in the keypad.cpp file. Look for the scanKeys() function and find the line:

     pin_write(columnPins[c], LOW);	// Begin column pulse output.
     delay(1);      // <------- Add this for testing and scope it again.

I wonder, too, if it could be a problem with my virtual function pin_write()? Try changing the code again:

     // Comment this out:
     // pin_write(columnPins[c], LOW);	// Begin column pulse output.
     // Then add this:
     digitalWrite(columnPins[c], LOW);	// Begin column pulse output.

I’m just trying to figure out how such a simple function can fail to change the pin.

Ok, will check it out when I get home after fencing classes.

You might want to check out my sketches for larger keypads:

OldMicroGuy's web page says:
"You can often get a MEGA on eBay for less than $15 with free shipping."

As you have to buy 6000+ Atmega2560s to get their unit price under $15,

and then the price of the board, all the rest of the components, assembly, packaging, shipping, and let's not forget about some profit for the e-bay seller, I am pretty confident saying any sub $15 "Arduino Mega" is counterfeit and of dubious quality.
And any one selling a $15 or less Atmega2560 based board, even Not saying Arduino on it, will be of dubious quality, such as:
http://www.ebay.com/itm/US-Mega-2560-ATmega-2560-16AU-Microcontroller-Board-R3-USB-Compat-f-Arduino-/321357805282?pt=LH_DefaultDomain_0&hash=item4ad26af6e2
$10.99? Really? At least this China-made boards has been pre-shipped to the US and they charge for shipping.

Well, they may be counterfeit but they were very good counterfeit. Over the last year I have purchased three different units on eBay auction for an average of $13.50 with free shipping. They have all worked perfectly. (And I have also purchased one of your kits) :slight_smile:
Roger

The post from CrossRoads made me recall that his ATmega1284P board has a row of 10 I/O locations so the BG Micro 25 key membrane keypad can be connected without jumper wires. I made a slight modification to the sketch.
See:

Roger