Simultaneous Button pressing with 64 Button Shield

Hi all,

I'm working on an arduino based midi controller with a button layout analogous to that of a B-Griff chromatic accordion. What I have so far is a matrix of Gateron mechanical keyswitches connected to the SpikenzieLabs 64 Button Shield (Shield Page).

I have the buttons wired with diodes as in the photo in the B64 page I linked. I can push any combination of buttons and have them read correctly, but the issue comes when I try to push multiple buttons residing on one column.

Multiple buttons in a row is fine. To clarify, the problem is only when the buttons are actually depressed simultaneously. Pressing and holding multiple buttons in a column is fine when only one button was depressed at a time.

The test code is that provided by the designers of the shield.

My main questions are: Do you think a software solution/workaround is possible? Should I completely go back to the drawing board if I want to be able to press 4 buttons simultaneously?

void setup()
{

Serial.begin(115200); // Only used to send data to PC for this DEMO

delay(1000);
attachInterrupt(0, SPI64B, FALLING); // Required for 64 Button Shield (SPI Only)

}

//*******************************************************************************************************************
// Main Loop
//*******************************************************************************************************************

void loop()
{

if(Button > 0) // If Button is > 0, then it was pressed or released (SPI only)
{
Serial.print("Button: ");
if(Button > 128) // Example of how to decode the button press
{
Button = Button - 128; // A pressd button is the button number + 128
Serial.print(Button, DEC);
Serial.print(" - Pressed");
}else
{
Serial.print(Button, DEC); // A released button is from 1 to 64
Serial.print(" - Released");
}
Serial.println(" ");
Button = 0;
}

}

//*******************************************************************************************************************
// Required for 64 Button Shield (SPI Only) Functions & Subroutines
//*******************************************************************************************************************
//
// This void is called if the Interrupt 0 is triggered (digital pin 2).
//

void SPI64B()
{
Button = 0;

volatile uint8_t val = 0;
volatile uint8_t clk = 0;

#define DataInPin 3
#define ClkPin 4

clk = digitalRead(ClkPin);
while(clk == LOW)
{
clk = digitalRead(ClkPin);
}

for(volatile int i =0; i<8;i++)
{
val = digitalRead(DataInPin);
clk = digitalRead(ClkPin);

while(clk == HIGH)
{
clk = digitalRead(ClkPin);
}

if(val == HIGH)
{
Button = Button +1;
}

if(i != 7)
{
Button = Button << 1;
}
else
{
break;
}

clk = digitalRead(ClkPin);

while(clk == LOW)
{
clk = digitalRead(ClkPin);
}

}
} // End of SPI64B void
// -------------------------------------------------------------------------------------------------------------

Please edit your post and replace quote by code.

Don't think I can help further; I suspect that their code can only report a single button at a time.

If the buttons at [1,1] and [8,8] are pressed at the same time, how would you know if, for example [1,8] is being pressed as well?

I don't think it is physically possible to correctly identify simultaneous button presses.

lg, couka

I have some clue to this matter and I am interested in going further.

A few months ago I was trying to control a machine that needed many buttons to make several movements. I wanted to use a keypad to minimize the number of inputs. I also needed to control several movements at the same time.

After trying many things I came across the keypad library by Mark Stanley and Alexander Brevig.
I managed to control several buttons at once. My problem was it took too much time to complete a loop, about 0.3 seconds, too slow for my application, so I forgot abut it. But I think if I had gone deeper into understanding the library, I would have done better.

There's a ton of work in that library. It is the best starting point I know about.

Couka, the problem you refer is solved.

I will try to find my code and post it.

Also, the forum thread about this library is very, very interesting and very large, though this thread can became interesting by itself, because it adresses this specific problem of using multiple keys at the same time, with a real time feeling.

Most likely, Mark Stanley can tell us the solution, since he wrote the library and the examples, for multikey.

I don't remember if the library can handle an 8x8 matrix. Nevertheless, I think it is the way to go.

The library is available in tha Arduino IDE library manager.

how would you know if, for example [1,8] is being pressed as well?

Because you scan a matrix outputting only active row at a time.

Maybe cameronmo's problem is that there are no diodes in his matrix.

Mark's library avoids the use of diodes.

I don´t remember the details

nickanor:
Mark's library avoids the use of diodes.

I don´t remember the details

because you are mistaken, without diodes you can not avoid phantom presses.

Exactly as Grumpy Mike says. The Diodes are a must.

If you for example pressed any button in column 2, the entire of column 2 becomes HIGH/LOW without the diodes.

I'd dare go for 8 x SN74HC165N + 64 pull up resistors (use resistor networks...some 8 resistors at 10k ohm...so 8 resistor networks).

An ATMEGA328P-PU with 16Mhz crystal.

ISP header (6 pin)

A couple of hours in Eagle and you might have something quite nice.

If you only power 1 row at a time you could read the columns all at once (if you have an Arduino with 8 bit port, 2 port reads on Uno) into a byte. 8 bytes for 8 rows could be read in well under 100 micros and there is NO WAY that pressing multiple buttons will result in false output. Fun part might be seeing if powering rows with INPUT_PULLUP would register 8 row buttons at the same time but since digitalRead() only "eats" 1 microAmp per read it just might.

I'm thinking that the OP should check his wiring before looking for code solutions.

I think that the problem with the SB64 shield is that it does the work for you; it has a PIC micro on board.

Johnny010:
I'd dare go for 8 x SN74HC165N + 64 pull up resistors (use resistor networks...some 8 resistors at 10k ohm...so 8 resistor networks).

I would go for a 23017 or 23S17 :wink:

sterretje:
I think that the problem with the SB64 shield is that it does the work for you; it has a PIC micro on board.
I would go for a 23017 or 23S17 :wink:

Agreed. Avoid the shield.

Sorry, I just made some irrevlevant statements and replaced them with the next post.

I have just read that certain combination of keys will produce ghosting. I wasn't aware.

BY the way, the playgrund states that this library does not need diodes or resistors.

here:
http://playground.arduino.cc/Code/Keypad

but mark stanley himself states that diodes are needed to prevent ghosting & jamming here:
https://forum.arduino.cc/index.php?topic=107430.0

I have asked him to make a comment on the playgroung, so that newbies like me are aware of these issues.

Nevertheless, was I right when I said that Mark's library is the way to go?

I think it is the only keypad library for matrix keypads that is available in the library manager( there are two other keypad libraries but these are not for matrix keypads).

That makes it a bit of a standard, doeesn't it?

I don't mean it is the best possible, not even pretending I can have a qualified opinion about the quality of the software, but it is something readily available, and that's good for the reuse of software sake.

I found this link interesting:

It is about jamming and ghosting, and related stuff.

I think this will give a broader view of different possibilties for scanning a matrix of switches

With the diodes and proper scanning you can't get ghosting. Without the diodes you can get ghosting, the electrical paths are there for some key combinations.

TODAY you posted to Mike in reply #30 .. keypad multiple key press - General Electronics - Arduino Forum

One suggestion. In the playground it is stated that the library does not need diodes or resistors. That can lead newbies like me to ignore issues like jamming and phamptom keys.

And he does not correct you at all because as you stated Without the diodes you can get ghosting, the electrical paths are there for some key combinations.

What does the musiclabs link you give show? Diodes and proper scanning.

I read in the Wikipedia link I posted that some keyboards don't use all the necessary diodes to make jamming and ghostting impossible, but they rather use a only a few to make it very unlikely.

Now my question is: is there a way to take one of those cheap sticker keypads one can buy on eBay, that have no diodes, and make jamming and ghostting unlikely by adding external diodes?

I find those keypads very convinient for many applications.

If you can work out how capacitive touch grids work you wouldn't need buttons. A single read takes usecs.