Illuminating Displays: Using an I2C LCD With STM32 Black Pill Using STM32CubeIDE

by Tushar_Garg in Circuits > Microcontrollers

77 Views, 1 Favorites, 0 Comments

Illuminating Displays: Using an I2C LCD With STM32 Black Pill Using STM32CubeIDE

3.png

Welcome to the fascinating world where pixels dance, and code weaves intricate patterns. Today, we embark on a journey that bridges hardware and software, unveiling the magic of display interfacing. Our spotlight shines on the STM32 Black Pill microcontroller, and our guide is none other than STM32CubeIDE—a trusted companion for this adventure.

Whether you’re a seasoned developer or a curious explorer, this article promises insights aplenty. We’ll unravel the mysteries of connecting an I2C LCD to the STM32 Black Pill, painting vivid visuals with lines of code. Imagine a canvas waiting for your strokes—a canvas where bits transform into vibrant displays.

So, tighten your seatbelt, grab your STM32 Black Pill, and let’s dive into the heart of embedded systems. The journey promises creativity, challenges, and a touch of magic

Supplies

  1. STM32 Black Pill
  2. LCD with I2C
  3. Female to Female Jumpers
  4. STMCubeIDE
  5. STMCubeProgrammer
  6. USB C Cable

Downloading

In the realm of embedded systems, establishing efficient communication between microcontrollers and peripherals is of paramount importance. Enter the liquidcrystal_i2c.h library—a powerful ally when connecting I2C LCDs to microcontrollers like the STM32 Blue Pill. By abstracting low-level I2C protocol details, this library streamlines development, allowing developers to focus on functionality and user experience. It’s the secret sauce for dependable and efficient LCD control, making sophisticated user interfaces a reality.

Download the file:-

https://github.com/eziya/STM32_HAL_I2C_HD44780/blob/master/Src/liquidcrystal_i2c.h

Setting Up STM32CubeIDE

2.png

Select the Target Microcontroller In the Board Selector tab, search for your specific development board or microcontroller. For example, if you are using the STM32 Black Pill board, select the appropriate option and click Next.

Mode Selection

4.png

Set the pins B6 and B7 for SCL and SDA

I2C Configuration

5.png

Configure the I2C mode in Pinout and Configuration menu.

Configuring the Clock

6.png

If you want to change the clock speed of your STM32 microcontroller, go to the Clock Configuration tab. Select the clock source based on your requirements. You can also enable the PLL engine to configure the clock to a higher frequency 

Adding the Code

#include "main.h"

#include "liquidcrystal_i2c.h"


I2C_HandleTypeDef hi2c1;


void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_I2C1_Init(void);


int main(void)

{

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_I2C1_Init();


HD44780_Init(2);

HD44780_Clear();

HD44780_SetCursor(0,0);

HD44780_PrintStr("TUSHAR");

HD44780_SetCursor(0,1);

HD44780_PrintStr("GARG");

HAL_Delay(2000);

}

Debugging and Building Binary File

7.png

Click on debug (On top left corner) to debug and generate binary file.

Opening the .elf File Created in System Explorer

8.png

Now obtain the path of your project.

Upload the Code to STM32 Black Pill

9.png

Click on Open File and Paste the Copied Path

10.png

Go to Download Options

11.png

Change Download Options and Click on "Start Automatic Mode"

12.png

Congrats

WhatsApp Image 2024-05-06 at 18.04.20_564c35d9.jpg