and error” approach to the problem.
Before I discuss my method and
the results I obtained, I need to mention
an important factor to keep in mind.
Standard 1/4 watt resistors have a 5%
tolerance rating which means that a
10K resistor can actually measure
anywhere between 9.5K and 10.5K.
This is why it’s important to be able
to produce a wide range of analog
voltages. If the ADC readings for two
adjacent keys were too close to each
other, variations in actual resistor values
could result in misidentifying the
specific key that has been pressed.
In order to make my trial and
error approach as painless as
possible, I set up a simple Excel
spreadsheet to compute the ADC
values that would result from a
specific combination of resistors and
then tried various combinations until
I found one that worked. When I
used the 256 levels provided by the
readadc command, some of the ADC
values for two adjacent keys were so
close (differences of 4 or 5) that I
was concerned that errors could
result. Switching to the 1024 levels
provided by the readadc10 command
greatly simplified the task.
The resistor values that I finally
chose are shown in Figure 4. Each of
the 16 “key” positions includes two
pieces of relevant data: the total
resistance that is connected in series
with the 10K base resistor when the
corresponding key is pressed; and (in
parentheses) the resulting value
produced by the readadc10 command.
If you would like to experiment
with different resistor values, the
formula you need is the basic voltage
divider rule. In English: The ADC
reading is to the maximum ADC value
(1023 for readadc10) as the base
resistance (10K) is to
the total resistance.
Figure 5 presents
the same thing
algebraically if you
prefer it that way.
If you double-check some of my
you’ll find that they are sometimes
off by a small amount. That’s
because I didn’t round anything up; I
truncated all my results because
that’s what the 08M and all
PICAXE processors do. Finally, I
need to emphasize that these are
theoretical results; your specific
ADC values will almost certainly
be somewhat different. We’ll
confront that issue in the next
section when we actually construct
and test our breadboard circuit.
AND TESTING THE
■ FIGURE 4.
The schematic for our
breadboard circuit is shown in Figure
6. As I mentioned earlier, the eight
connections to the keyboard that I’m
using are not logically ordered, but it
really doesn’t matter much. The
important thing is to make sure that
the connections for each resistor are
the same as the ones presented earlier
in Figure 2. If the pinout is different
for the keypad you intend to use,
simply rearrange the connections
appropriately. The parts list for our
breadboard circuit is too simple to
warrant a separate sidebar; just a matrix
keypad with a male header, the seven
resistors shown in the schematic, and
a PICAXE-08M processor are needed.
My breadboard layout is shown
in Figure 7. To save some space on the
breadboard, I’m using the AxMate-FT
programming adapter which is also
supplying power to the breadboard.
The small red printed circuit board
(PCB) attached to the AxMate-FT is the
5V version of
FTDI Basic Breakout board (DEV-09716)
which I have reconfigured to work
correctly with PICAXE processors (as
we discussed back in the June
Primer). I really like SparkFun’s new
board because they have moved the
six-pin female header underneath
which makes this the smallest FTDI-based board that I have found so far.
■ FIGURE 6. Schematic for ADC
matrix keypad circuit.
■ FIGURE 5. The
October 2010 69