Guiding Light: a Step-by-Step Tutorial on Blinking 3 LEDs Using STM32 Black Pill

by Tushar_Garg in Circuits > Microcontrollers

39 Views, 0 Favorites, 0 Comments

Guiding Light: a Step-by-Step Tutorial on Blinking 3 LEDs Using STM32 Black Pill

1.png

Welcome to our instructable blog, where we embark on an enlightening journey into the realm of microcontroller programming using the powerful STM32 Black Pill. In this tutorial, we’ll explore how to control not just one, but three LEDs in mesmerizing patterns.

By harnessing the capabilities of the STM32 Black Pill, we’ll delve into the intricacies of working with GPIO pins, creating dynamic lighting sequences, and mastering the art of LED manipulation. Whether you’re a seasoned enthusiast seeking to expand your knowledge or a curious beginner eager to explore embedded electronics, join us as we illuminate the darkness with the brilliance of three LEDs

Supplies

  1. STM32 Black Pill
  2. Bread Board
  3. M-M jumper connector cables
  4. LED (3 nos.)
  5. USB TYPE-C cable

Perform 1st to 6th Step of My Another Blog

Use Code in While(1) Loop

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,0);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,0);

HAL_Delay(500);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_14,1);

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_15,1);

HAL_Delay(500);



Let’s break down the provided code step by step:

  • LED Initialization:
  • The code initializes three LEDs connected to GPIO pins on the STM32 microcontroller.
  • These LEDs are controlled via the GPIOC port.
  • Blinking Patterns:
  • The code toggles the LEDs on and off in specific patterns.
  • Each pattern lasts for 400 milliseconds (0.4 seconds).
  • Pattern Breakdown: The following patterns repeat cyclically:
  • Pattern 1:Turn off all LEDs (pins 13, 14, and 15).
  • Pattern 2:Turn off LEDs 13 and 14. Turn on LED 15.
  • Pattern 3:Turn off LEDs 13 and 15. Turn on LED 14.
  • Pattern 4:Turn off LED 13. Turn on LEDs 14 and 15.
  • Pattern 5:Turn off LED 14. Turn on LEDs 13 and 15.
  • Pattern 6:Turn off LED 15. Turn on LEDs 13 and 14.
  • Pattern 7:Turn off LED 14. Turn on LED 15.
  • Pattern 8:Turn on all LEDs (pins 13, 14, and 15).
  • Delay: The HAL_Delay(500) function introduces a delay of 500 milliseconds between each pattern.

Overall, this code creates a visually dynamic LED display with alternating patterns. Feel free to modify the patterns or timings as needed for your specific project

Debug

7.png

Copy the Path of .elf File

To copy the path of your project's .ioc file in STM32CubeIDE:

1. Find the .ioc file:

  • Look for it in the Project Explorer window (left side) under your project name.

2. Right-click and copy:

  • Right-click the .ioc file and choose "Copy Path" (or similar).

This copies the entire file location for pasting elsewhere.

Open STMCubeProgrammer and Connect to STM Board Via USB

9.png

Click on Open File and Paste the Copied Path

10.png

Go to Download Options (Found in Toolbar on the Left)

11.png

Configure Download Settings and Activate Automatic Downloads

12.png

LED's Will Start Blinking

2.jpg