LCD1602A - STM32F4 Discovery

Learn how to set up and send data to the LCD1602A on an STM32F4 board.

LCD1602A Hello World STM32F4
LCD1602A - STM32F4

This tutorial is a step by step guide on setting up and sending data from the STM32F4 Discovery to the 16x2 '1602A' Liquid Crystal Display.

Here are the 4 steps:

1) Set up the hardware.

2) Configure the peripherals in CubeMX.

3) Download and import the LCD libraries.

4) Write the code.

1) Set up the hardware

Components required:

  • STM32F4 Discovery Board.

  • LCD 1602A (16x2).

  • 1000uF Capacitor.

  • 910 Ohm Resistor.

  • 1k resistor or variable resistor.

The STM32F4 board is available here:

The LCD display is available here:

All other components are generic and can be picked up at any hardware store.


To make the hardware setup as simple as possible for you, I have provided a schematic:

LCD1602A - STM32F4 Schematic
LCD1602A - STM32F4 Schematic

The LCD display is powered by 5V. You can use the 5V and GND output pins on the STM32F4 Discovery board to power it.

This tutorial is using LCD 4-bit mode, hence why data pins D0-D3 are not connected up. Should you want to use the LCD in 8-bit mode, simply connect D0-D3 to additional GPIO outputs on the discovery board.

Resistor R1 connected to pin 'V0' is a contrast adjustment setting. An 800 - 1k Resistor should do the job. Although, I recommend replacing R1 with a 1k variable resistor. This will allow you to adjust the contrast of the display to your liking.

2) Configuring the peripherals in CubeMX

Here is the pin layout for the LCD display in CubeMX:

Your LCD data lines will NOT work across different ports. Data transfer is very time critical they must all reference the same clock. Please ensure that all your LCD data pins are connected to the same port (port D in the case).

LCD1602A - CubeMX Setup
LCD1602A - CubeMX Setup

3) Download and import the LCD libraries.

The LCD libraries were written by Mohamed Yaqoob. Check the code description to learn more about how the library was written.

The two library files can be downloaded here:



You will need to add these files to your project directory and also specify the correct path in the development environment you are using.

4) Write the code.

The code to get started is very simple. Firstly, the LCD display must be initialized using the pins selected in CubeMX.

Note: If your pins are labelled differently to mine, please ensure you correct your code for the matching pin labels.

Code to initialize LCD display:

Lastly, print your data to the LCD Display:

That's it! You're all set with your LCD display. You can also create your own functions to use the LCD display however you want.

Check out the LCD datasheet for more information:

1,023 views0 comments