How to Interface 16X2 LCD with STM32F103C8T6?

In this project, sometimes known as the Blue Pill, we will learn how to interface a 162 LCD with an STMF103C8T6. I’ll demonstrate how to connect a 16×2 character LCD to an STM32, as well as provide some background knowledge on the LCD module and a software to print text on the LCD.

Interfacing 16X2 LCD with STM32 Blue Pill


Displaying crucial information on a display unit is crucial in any embedded project since it gives the user a simple method to interact with the system. Consider your energy metres, weather forecasters, heart rate monitors, and other devices. In the end, each of these projects will include a display unit.

It’s not necessary to refer to an elaborate, colorful, graphical display when discussing displays. For displaying crucial information like sensor readings, the ADC’s value, the status of a relay, etc., a straightforward character display is more than adequate.

So, we shall follow suit in this project. A 16X2 LCD will be connected to the STM32F103C8T6 Blue Pill board. We shall display some sample text to see the output since this is a demonstration of how to interface with the LCD module.

We can apply this understanding of the 16X2 LCD with STM32F103C8T6 in other projects when we interface various sensors, in order to display some significant data.

A Brief note of 16X2 LCD

The 16X2 LCD display has already been utilized with a variety of microcontrollers, including the 8051, ATmega, Arduino, and LPC2148 (ARM7). But first, let’s quickly go through a fast introduction to the same as a refresher.

A typical 16X2 Alphanumeric Character LCD Display may be seen in the image below. The phrase 16X2 denotes the presence of 16 columns and 2 rows. A 16×2 LCD panel can display a maximum of 32 characters at once since each column in a row is used to display a character.

16X2 LCD Pins

Although there are numerous variations of these displays, including 8X1, 8X2, 16X1, 16X2, 20X4, etc., the 16X2 and 20X4 modules are the most widely utilized.

Internally, each column or character block consists of 5 by 8 pixels (5 vertical and 8 horizontal). This effectively converts it to a dot matrix display, and to control the pixels, Hitachi’s HD44780 LCD Controller IC is utilized.

In regards to the 16*2 LCD display pins, there are 16 of them, and the following table provides a brief description of each pin.

Pin NumberPin NameDescription
3VOAdjust contrast of LCD
4RSRegister Select (Command / Data)
5R/WRead / Write operations
6ENEnable (must be HIGH for R / W)
7 – 14D0 – D7Data Pins
15LED+ (A)LED Backlight Positive Supply (+5V)
16LED- (K)LED Backlight Negative Supply (GND)

Interfacing 16X2 LCD with STM32F103C8T6

As was already indicated, the goal of this project is to learn how to connect an STM32 Blue Pill to a 16X2 LCD. The Arduino IDE will be used to create the code and upload it to the MCU (using a USB to Serial Converter).

Only 4 data pins will be utilised to transfer the data that will be displayed on the LCD because the LCD module will be set up in 4-Bit mode.

Circuit Diagram

The circuit diagram for integrating a 16X2 LCD with an STM32F103C8T6 MCU is displayed in the following Fritzing image.

Interfacing 16X2 LCD with STM32F103C8T6 Circuit

Components Required

  • STM32F103C8T6 MCU based board Blue Pill
  • USB to Serial Converter (like FTDI Programmer)
  • 16X2 Character LCD Module
  • Connecting Wires


We’ve already covered the connections between the STM32 Blue Pill board and the USB to Serial Converter in the lesson “Getting Started with STM32F103C8T6.” The STM32 Blue Pill board’s A9 and A10 pins are used to link the TX and RX of the FTDI Programmer.

With regards to the LCD Module, GND and +5V are connected to pins 1 and 2, or VSS and VDD, respectively. LED+ and LED-, which are attached to pins 15 and 16 respectively, are similarly connected to +5V and GND.

to change the LCD Display’s contrast. The 10K POT’s other two terminals are connected to +5V and GND, and its VO pin (Pin 3) is connected to the POT’s center terminal. Pins 4, 5, and 6 are the control pins, and they are connected to B11, GND, and B10, respectively.

The data pins are the next. Only 4 data ports, D4 to D7 (Pins 11 to 14), will be used because we will be using the LCD in 4-bit mode. These pins should be connected to B0, A7, A6, and A5, accordingly. You can omit using the other four data pins, D0 to D3.

Programming STM32F103C8T6 for LCD Display

  • installing Arduino IDE packages for STM32 boards.
  • choosing the appropriate STM32 board with the necessary configurations.
  • Obtaining a programming tool that can upload code to our Blue Pill board using the Arduino IDE.
  • Changing between “Programming Mode” and “Operational Mode” using the BOOT Selection pins.

You are ready to proceed once you have finished this fundamental setup and successfully submitted a test application (Blinky).

NOTE: By just flipping the BOOT0 pins HIGH and LOW, you can change between the Programming Mode and Operational Mode. Every time you switch between the modes while the power is ON, you must hit the Reset button.

By first putting the BOOT0 pin to HIGH, you can put the Blue Pill in programming mode. In order to display some text on the LCD display, I have now created a straightforward piece of code utilising the Arduino layout. Below is a list of the code.


* LCD VSS pin to GND
* LCD VDD pin to 5V
* LCD VO pin to POT
* LCD RS pin to digital pin PB11
* LCD RW pin to GND
* LCD EN pin to digital pin PB10
* LCD D0 to D3 pins not used
* LCD D4 pin to digital pin PB0
* LCD D5 pin to digital pin PA7
* LCD D6 pin to digital pin PA6
* LCD D7 pin to digital pin PA5
* LCD BL+ pin to 5V
* LCD BL- pin to GND
#include <LiquidCrystal.h>
const int rs = PB11, en = PB10, d4 = PB0, d5 = PA7, d6 = PA6, d7 = PA5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(“Interfacing LCD”);
lcd.setCursor(0, 1);
lcd.print(“Electronics Hub”);
void loop() {
lcd.setCursor(0, 0);
lcd.print(“STM32–Blue Pill”);
lcd.setCursor(0, 1);
16x2 LCD with STM32 Code

The STM32 MCU will begin displaying the text provided in the code once it has been compiled and uploaded. By setting BOOT0 LOW and pushing the reset switch, you can return to operational mode.


Hope this blog helps you to understand How to Interface 16X2 LCD with STM32F103C8T6? We, MATHA ELECTRONICS will come back with more informative blogs.

Leave a Reply

Your email address will not be published.