Home Code STM32 Nucleo board and an AD Keypad

STM32 Nucleo board and an AD Keypad

by shedboy71

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 ST Nucleo and read in the value and display it via the serial port.

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

A_D-Keypad-2

Here is the schematic of the module, hopefully you can see what I described earlier

AD-Keypad-Schematic

AD-Keypad-Schematic

You will have to wire Vcc of the module to 3.3v otherwise the readings will be incorrect, the A0 of the module is connected to A0 (Arduino)

Code

 

[codesyntax lang=”cpp”]

#include "mbed.h"

 
Serial pc(USBTX, USBRX);
AnalogIn input(A0);
 
int main()
{
 pc.printf("Hello World\n");
 while (1) 
 {

 float reading = input.read()*100.0f;
 if (reading < 92.00)
 {
 // print the percentage and 16 bit normalized values
 pc.printf("value: %3.2f%\n", input.read()*100.0f);
 wait(0.4f);
 }
 
 }
}

[/codesyntax]

Output

Pressing the keys from K0 to K16 outputted the following in a serial monitor such as TeraTerm

percentage: 0.00
percentage: 4.52
percentage: 10.70
percentage: 17.02
percentage: 23.25
percentage: 29.26
percentage: 35.41
percentage: 41.95
percentage: 47.94
percentage: 66.08
percentage: 60.51
percentage: 72.14
percentage: 78.61
percentage: 84.66
percentage: 90.72

So using a switch case you can use this module in your own examples, best practice would be to have a high and low value and check between the range. For example Key 1 is 4.52 so you could check for a range between 3 and 5

Links

AD Keypad 16 4×4 Accessory board matrix buttons controlled ADC

Share

You may also like