## how can I make use of the analog buttons of LCD Shield on the Nucleoboard?

Hello,

I've been using a Nucleo board microcontroller with the STM32L053R8. On this I have placed a 16x2 LCD Shield of DFRobot.

My question is how can I use the analog buttons on the board?!

These are all connected to A0 and distinguishable by resistors and the voltage drop. However, all the instructions I could find are for the Arduino platform and the Arduino µC. I've read that the Nucleo boards analog inputs (like A0) can only be used to 3V3. If no button is pressed, A0 gets 5V. (Arduino boards can probably deal with it).Is that right?

Is there any way to still use this buttons?

A very simple code would be quite sufficient. Depending on which button is pressed some text should be shown on the display.

Is there anyone using a Nucleo board and has worked at random projects with an LCD Shield for Arduino and possibly has a solution or a code for me?

Thank you very much,

#### Question relating to:

##### 7 years, 3 months ago.

Looking at the schematic for the board the buttons are used to set the values in one half of a voltage divider.

The voltages on A0 will be: No Button : 5V Select : 3.62V Left : 2.47V Down: 1.61V Up : 0.78V Right: 0V

Since we can read up to 3.3V select looks like no button is pressed.

So if we want to use detection thresholds mid point between the nominal levels the code would look something like this:

```#define adcSupply 3.3

#define rightVoltage 0.0
#define upVoltage 0.78
#define downVoltage 1.61
#define leftVoltage 2.47
// select should be 3.6 but we can only measure up to the supply voltage
// no button unused, in here for reference only
#define noButton 5.0

Serial pc(USBTX,USBRX);

main() {

while (true)
float buttonValue = LCDButtons;
if (buttonValue < ((upVoltage + rightVoltage ) / 2) / adcSupply ) ) {
pc.printf("Right\n");
} else if (buttonValue < ((upVoltage + downVoltage ) / 2) / adcSupply ) )
pc.printf("Up\n");
} else if (buttonValue < ((leftVoltage + downVoltage ) / 2) / adcSupply ) )
pc.printf("Down\n");
} else if (buttonValue < ((leftVoltage + selectVoltage ) / 2) / adcSupply ) )
pc.printf("Left\n");
} else {
pc.printf("Select or no button\n");
}

wait (1.0);
}
}
```

As it is you're hitting the input with 5V all the time which may not be a great plan but there is a 2k series resistor so it shouldn't do any harm. If you could add a pull down resistor of 3k9 between A0 and ground then you could divide all the voltages given above by 1.5 and read all the buttons.