Install the Matrix Keypad

Cow Pi mk1f: Arduino Nano form factor, I2C communication

Observe that the matrix keypad has sixteen buttons has eight pins in its female connector. As shown in Fig. 56(a), when the keypad is face-up and oriented for reading, the four pins on the left are the row pins, and the four pins on the right are the column pins. From left-to-right, we will name these pins row1, row4, row7, row*, column1, column2, column3, columnA. Fig. 56(b) shows the membrane contacts and which Arduino Nano pin will be connected to each keypad pin.

../../../_images/blank.png

Fig. 56 The numeric keypad’s header has four row pins and four column pins

a

b

../../../_images/keypad-annotated.jpg ../../../_images/keypad-matrix.png

Front of matrix keypad.

Keypad’s underlying contact matrix.

Fig. 57 shows a diagram of the wiring for the matrix keypad.

Diagram of wiring associated with matrix keyboard input.

Fig. 57 Diagram of wiring associated with matrix keyboard input.

Important

Before proceeding further, disconnect the USB cable from the Arduino Nano.

:[   ]:

If your 8-pin male-male header strip is not already inserted into the keypad’s female connectors, insert it into the female connectors now. If your male-male header strip has more than eight pins, position the excess pins to the right of the column pins.

:[   ]:

Connect your keypad to your breadboard such that row1 is in contact point j19, and columnA is in contact point j26 (and any unused pins on the male-male header are in contact points j27, j28, etc.).

Tip

If you used 20cm wires to connect your slide-switches and/or pushbuttons to the Arduino Nano, then you can use the matrix keypad’s ribbon cable to pull these wires away from the circuit, reducing clutter near the controls.

../../../_images/keypad-pullingwires.jpg
:[   ]:

Peel off two 4-conductor cables from the male-to-male rainbow cable. While you can use individual wires, having these 4-conductor cables will simplify keeping track of the wires.

Tip

Taping the each ends’ four leads together may make it easier to manage the 4-conductor cables. (It is not necessary that you do so.) Ordinary household adhesive tape will suffice.

../../../_images/keypad-cables.jpg
:[   ]:

Insert one end of one of the 4-conductor cables in contact points h19-h22, in the same breadboard rows as the keypad’s row pins.

:[   ]:

Insert the other end of the cable in contact points j9-j6.

You want the Arduino Nano’s D4 pin to connect to the keypad’s row1 pin, D5 to row4, D6 to row7, and D7 to row*; you can use the wires’ colors to make sure that you do so.

:[   ]:

Insert one end of another 4-conductor cable in contact points h23-h26, in the same breadboard rows as the keypad’s column pins.

:[   ]:

Insert the other end in contact points a4-a7 (electrically connected to the Arduino Nano’s D14/A0-D17/A3 pins).

You want the Arduino Nano’s D14/A0 to connect to the keypad’s column1 pin, D15/A1 to column2, D16/A2 to column3, and D17/A3 to columnA; you can use the wires’ colors to make sure that you do so.

../../../_images/blank.png

Fig. 58 The matrix keypad, wired to the Arduino Nano

a

b

../../../_images/keypad-rows-mk1f.jpg ../../../_images/keypad-columns-mk1f.jpg

Wiring the rows.

Wiring the columns.

When you have finished setting up the keypad wiring, there should be the electrical paths described in Table 33.

Table 33 Electrical Paths for Matrix Keypad.

Keypad pin

Arduino Nano pin

row1

D4

row4

D5

row7

D6

row*

D7

column1

D14/A0

column2

D15/A1

column3

D16/A2

columnA

D17/A3

Attention

CHECKPOINT 7 | Before proceeding further, have a TA, a classmate, or a friend verify that you have correctly inserted and wired the matrix keypad. Update your checkpoints.txt file to indicate who checked your work and when they did so.

Warning

Do not press more than one key on the matrix keypad at a time. There are certain combinations of keys that could result in a short-circuit from power to ground, possibly damaging your Arduino Nano. Your Arduino Nano has some safety measures to prevent damage in that situation, but it would be better for you not to test those safety measures.

Connect your Arduino Nano to the computer. In the IDE’s Serial Monitor, notice that there is normally no character after Keypad:, and that Column pins is normally 1111. Press the 5 key on the matrix keypad. Notice that the first line of the message from the Arduino Nano is now

Keypad:      5        Column pins:  1011

In general, when you press a key on the keypad, the corresponding character will be displayed after Keypad:. When you press 1, 4, 7, or *, Column pins becomes 0111; similarly, pressing a key in the 2^{nd} column causes Column pins to become 1011; in the 3^{rd} column, 1101; and in the A^{th} column, 1110. Be sure to test all 16 keys.