7 years, 3 months ago.

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,

Board: http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260001

LCD Shield: http://www.dfrobot.com/index.php?route=product/product&product_id=51&search=lcd+shield+16x2&description=true&page=2

Question relating to:

2 Answers

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
#define selectVoltage adcSupply
// no button unused, in here for reference only
#define noButton 5.0

AnalogIn LCDButtons(A0);
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.

Accepted Answer
7 years, 3 months ago.

The analog inputs are typically not 5V tolerant. I would modify the board a bit before connecting it to mbed. There should be 3V3 present on pin5 of J4 and pin5 of J7. You should cut the wire between R2 and Vcc (5V) and somehow rewire R2 to 3V3. Depending on board layout it may be easier to just remove R2 and replace it with a new resistor that is connected to 3V3. Your software should just read analogIn and decode the key by checking in with interval the analog value is.