Interfacing an AD keypad module to a Beaglebone

In this article we look at an AD keypad connected to a Beaglebone first of all lets look at the sensor.

I purchased this module as part of a microcontroller kit, its an interesting little module as it has 16 buttons but with only 1 I/O line is required, an analog input. You connect this to your Beaglebone and read in the value.

Now the Beaglebone only supports 1.8v input as a maximum on the ADC pins, this is not a problem in this case as we are using the 1.8v reference from VDD_ADC on P9_32 and we will use one of the AIN pins.

You can see this in the image below on the P9 header

The concept is straightforward  you use a resistor network as voltage dividers, and then let each button feed a different voltage to the analog pin. So by detecting the voltage you can tell which button has been pressed. You can only detect one button at a time

Parts Required


Name Link
Beaglebone BeagleBone Black TI AM3358 Cortex-A8 development BB-Black Rev.C
AD keypad AD Keypad 16 Push Buttons 4×4 Accessory Board Matrix Buttons
Connecting wire Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire


beaglebone and ad keypad
beaglebone and ad keypad

Code Example

This example needs the Adafruit IO python library installed –

[codesyntax lang=”python”]

import Adafruit_BBIO.ADC as ADC
import time
sensor_pin = 'P9_40'
while True:
    reading =
    volts = reading * 1.800
    print('%f\t%f' % (reading, volts))


Save this as, I used the Cloud 9 IDE

Now for a gotcha, if you click on the Run button you will see something like this

Traceback (most recent call last):
File “/var/lib/cloud9/iain/”, line 6, in <module>
RuntimeError: Unable to setup ADC system. Possible causes are:
– A cape with a conflicting pin mapping is loaded
– A device tree object is loaded that uses the same name for a fragment: helper

You need to run the python script using administrator privileges, open a terminal and enter the following

sudo python


After running you should see something like this.

debian@beaglebone:/var/lib/cloud9/iain$ sudo python
Reading Volts
0.000488 0.000879
0.000488 0.000879
0.000488 0.000879
0.000488 0.000879
0.000488 0.000879
0.982662 1.768791
0.997070 1.794725
0.998291 1.796923
0.998779 1.797802
0.000733 0.001319
0.937729 1.687912
0.937973 1.688352
0.937973 1.688352
0.000488 0.000879

The first bolded set of numbers was the K0 button pressed, the K1 button was the second set of bolded numbers. The 0.000488 is with no buttons pressed. In your code you would need to check for a range so 0.999 to 0.9799 could be K0.


Please enter your comment!
Please enter your name here