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

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

Step 1: 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

Step 2: Setting Up STM32CubeIDE

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.

Step 3: Mode Selection

Set the pins B6 and B7 for SCL and SDA

Step 4: I2C Configuration

Configure the I2C mode in Pinout and Configuration menu.

Step 5: Configuring the Clock

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 

Step 6: 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);

}

Step 7: Debugging and Building Binary File

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

Step 8: Opening the .elf File Created in System Explorer

Now obtain the path of your project.

Step 9: Upload the Code to STM32 Black Pill

Step 10: Click on Open File and Paste the Copied Path

Step 11: Go to Download Options

Step 12: Change Download Options and Click on "Start Automatic Mode"

Step 13: Congrats