Thursday, 25 January 2018

Is it possible to get input from a 10x10 grid of switches using an arduino board? (Uno, Mega, etc.)


I'm more of a software guy but I'm working on a prototype of a game that will use a pressure sensitive 10 by 10 grid. This will require 100 switches just for the grid. The closest I've found to off the shelf is an Arduino Mega 2560 r3 but it still comes up short by 30 pins. What is the best approach to this? Should I look into getting more gpio pins or is there a better, more efficient way of accomplishing the task of receiviving positional data from a 10x10 grid (think a1,b2,c3 and so on)?


While Googling a bit I came across a method using resistors and analog pins to get input from multiple buttons. The tutorials always seem to use 5 buttons, Is this a limitation of the tutorials or the method? Could the same method be used to string together 10 switches? link to multi button example



Answer



You could arrange the buttons in an X-Y layout, like in the figure below (which I extracted from this source). That will allow you to use 20 pins (10 for the rows, 10 for the columns) instead of 100.


X-Y keypad arrangement


The polling algorithm is as follows (from the same source):




Continuous Polling Operations


In this mode of operation, the MicroConverter continuously polls the keypad for a key press. This operation is used where the MicroConverter has completed a task and is now waiting for input before proceeding. In this mode, the keypad is connected to one port of the MicroConverter, Port 2 in this example. Figure 3 shows the connectivity. The output from the MicroConverter, following a key press, is viewed using HyperTerminal running on a PC. The MicroConverter is connected to the PC via the COM1 port. This is the reason for showing the RS-232 connection.


As can be seen in Figure 3, the four columns (X1 to X4) are pulled up to VDD and are also connected to four of the MicroConverter port pins (P2.4 to P2.7). The four ADuC8xx rows (Y1 to Y2) are connected to the other four port pins (P2.0 to P2.3). The MicroConverter outputs 0 or drives low the keypad rows (P2.0 to P2.3) one at a time and checks the columns (P2.4 to P2.7) for a low condition.


For example, the following is the sequence of events up to a switch press detection (Switch 5 in this case). The MicroConverter outputs a low on P2.0 (Y1) and checks for a low on P2.4 to P2.7. In this case, no low is found and so it returns P2.0 (Y1) to high and moves on to P2.1 (Y2). The MicroConverter now drives P2.1 (Y2) low and again checks P2.4 to P2.7 for a low condition. This time it finds that P2.5 (X2) is low, due to Switch 5 being pressed. The MicroConverter now knows that the interconnect of Y2 and X2 has been shorted, therefore, this is 5.



But you don't need to implement the algorithm yourself. Instead you can use the Arduino Keypad lib. The links are below:



See this answer if you need to lay down the buttons yourself. It explains how to layout 4 pin buttons on a single-sided board in a way that you don't need to use jumpers. I'm copying the X-Y layout from that question below:


X-Y keypad layout


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...