Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

 This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill using the Arduino IDE and a DSD TECH SH-U09C5 USB to TTL converter. The STM32 Blue Pill is a powerful yet affordable microcontroller board based on the STM32F103C8T6 ARM Cortex-M3 processor. Known for its robustness and versatility, the Blue Pill is an excellent choice for hobbyists, makers, and professionals alike who are looking to harness the power of 32-bit ARM architecture in their projects.

Why the STM32 Blue Pill?

The STM32 Blue Pill offers an impressive set of features at a fraction of the cost of similar microcontrollers. With a 72 MHz clock speed, 20 KB of RAM, and 64 KB of flash memory, it outperforms many 8-bit microcontrollers, making it suitable for more demanding applications such as real-time data processing, motor control, and advanced sensor integration. Its wide range of peripherals, including SPI, I2C, USART, and ADC, allows for seamless interfacing with various components, sensors, and modules.

Additionally, the STM32 Blue Pill is well-supported by the open-source community, with a variety of development environments available, including the Arduino IDE. This makes it accessible even to those who are familiar with Arduino but want to step up to more advanced hardware.

Why Use a USB to TTL Converter?

Unlike many Arduino boards, the STM32 Blue Pill does not come with a built-in USB-to-serial converter, which is typically used for uploading code and debugging. Instead, the board is equipped with UART (Universal Asynchronous Receiver-Transmitter) pins that require an external converter to communicate with your computer. The DSD TECH SH-U09C5 USB to TTL converter acts as a bridge between your computer’s USB port and the UART pins on the Blue Pill, allowing you to upload code, monitor serial output, and debug your programs. This converter is an essential tool in working with the STM32 Blue Pill, enabling seamless communication between the board and your development environment.

Get Started with a Pre-Soldered Board

For those looking to dive straight into development without the hassle of soldering, you can purchase pre-soldered STM32 Blue Pill boards at Shillehtek. These boards come ready to use, so you can focus on building your projects right away.

— — -

Before we delve into the topic, we invite you to support our ongoing efforts and explore our various platforms dedicated to enhancing your IoT projects:

  • Subscribe to our YouTube Channel: Stay updated with our latest tutorials and project insights by subscribing to our channel at YouTube — Shilleh.
  • Support Us: Your support is invaluable. Consider buying me a coffee at Buy Me A Coffee to help us continue creating quality content.
  • Hire Expert IoT Services: For personalized assistance with your IoT projects, hire me on UpWork.

ShillehTek Website (Exclusive Discounts):

https://shillehtek.com/collections/all

ShillehTekAmazon Store:

ShillehTek Amazon Store — US

ShillehTek Amazon Store — Canada

ShillehTek Amazon Store — Japan

Step 1: Connect the STM32 Blue Pill to the USB to TTL Converter

To start, you’ll need to connect your STM32 Blue Pill to your computer using the DSD TECH SH-U09C5 USB to TTL converter. This converter will allow your computer to communicate with the STM32 Blue Pill via its UART interface.

Wiring Setup:

  1. RXD (SH-U09C5) -> PA9 (RX on Blue Pill)
  2. TXD (SH-U09C5) -> PA10 (TX on Blue Pill)
  3. GND (SH-U09C5) -> GND (Blue Pill)
  4. VCC (SH-U09C5) -> 3.3V (Blue Pill)

Set the BOOT0 Jumper:

  1. Set the BOOT0 jumper on the Blue Pill to the 1 position (this puts the Blue Pill into UART bootloader mode). See diagram below for bootloader mode.

Make sure to plug the TTL converter into power, you can simply plug it into your computer if it has a USB port!

Step 2: Install STM32 Support in Arduino IDE

Before you can program the STM32 Blue Pill in the Arduino IDE, you need to install support for STM32 boards.

Step 1: Open Arduino IDE Preferences

  1. Open the Arduino IDE.
  2. Go to File > Preferences.

Step 2: Add STM32 Board Manager URL

In the “Additional Boards Manager URLs” field, add the following URL:

https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

Click OK.

Step 3: Install STM32 Boards

  1. Go to Tools > Board > Boards Manager.
  2. Search for STM32 and click Install next to the “STM32 MCU based boards” package.

Step 3: Select the STM32 Blue Pill Board in Arduino IDE

After installing STM32 support, you’ll need to configure the Arduino IDE to use the correct settings for your STM32 Blue Pill.

Step 1: Select the Board

  1. Go to Tools > Board > STM32 Boards and select Generic STM32F1 series.

Step 2: Configure Board Settings

  1. Under Tools > Board Part Number, select BluePill F103C8 (or BluePill F103CB if you have the 128KB flash version).
  2. Set the Upload Method to STM32CubeProgrammer (Serial).
  3. Set the Port to the port associated with the device.

Step 4: Install STM32CubeProgrammer

STM32CubeProgrammer is required for uploading code to the STM32 Blue Pill via the serial interface.

Step 1: Download and Install STM32CubeProgrammer

  1. Download STM32CubeProgrammer from STMicroelectronics.
  2. Make sure you create a free account if you have not.
  3. Install it on your system following the on-screen instructions. It has downloads for different operating systems.

Step 2: Set the Environment Variable

Open a terminal and add the STM32CubeProgrammer path to the STM32_PRG_PATH environment variable.

For macOS, add the following line to your ~/.zshrc or ~/.bash_profile file:

  • export STM32_PRG_PATH=/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin

Apply the changes by running:

  • source ~/.zshrc

or

  • source ~/.bash_profile

For Windows:

  1. Open the Start Menu and search for “Environment Variables.”
  2. Select “Edit the system environment variables” from the search results.
  3. In the System Properties window, click on the “Environment Variables” button.
  4. Under “System variables” (or “User variables” if you prefer), click on “New.”
  • Variable Name: STM32_PRG_PATH
  • Variable Value: The path to the STM32CubeProgrammer bin directory, such as:
  • C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin

Click “OK” to save the new environment variable.

Close the Environment Variables and System Properties windows.

Step 5: Upload Your First Program

Now that everything is set up, you’re ready to upload your first program to the STM32 Blue Pill.

Step 1: Write the Code

  1. Open a new sketch in Arduino IDE and write a simple program. Here’s an example that prints a message to the Serial Monitor:
void setup() {
// Start the Serial communication at 9600 baud
Serial.begin(9600);

// Wait for the serial port to connect (necessary for some boards)
while (!Serial) {
; // Wait
}
}

void loop() {
// Print a message to the Serial Monitor
Serial.println("Hello, Blue Pill!");

// Wait for 1 second
delay(1000);
}

Step 2: Reset the Blue Pill

  1. Before clicking the upload button in Arduino IDE, press the Reset button on the Blue Pill board. This ensures that the board is ready to receive the program.

Step 3: Upload the Code

  1. Click the Upload button in Arduino IDE.
  2. After the upload completes you will see the onboard LED blink on intervals. If you want to upload another script you can hit the reset button and modify the script and upload again!

Troubleshooting

  • If you encounter issues with uploading:
  • Ensure the correct port is selected.
  • Check your wiring and jumper settings.
  • Verify that the STM32_PRG_PATH environment variable is correctly set.
  • Ensure your board is authentic, like the board from STM32 ShillehTek Amazon Store. The board comes pre-soldered as well.

Conclusion

Congratulations! You’ve successfully set up and programmed your STM32 Blue Pill using the Arduino IDE and the DSD TECH SH-U09C5 USB to TTL converter. This powerful microcontroller opens up a world of possibilities for your projects, offering the performance of a 32-bit ARM Cortex-M3 processor at an affordable price. Whether you’re a beginner or an experienced developer, the STM32 Blue Pill is a versatile tool that can help you bring your ideas to life.

If you found this tutorial helpful, be sure to check out more content on my YouTube channel, where I regularly share tips, tutorials, and project ideas to help you get the most out of your development boards and microcontrollers. Don’t forget to subscribe at MM Shilleh on YouTube to stay updated with the latest videos. Good luck with your projects!

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

Learn how to set up the HCSR501 PIR sensor with a Raspberry Pi Pico to detect motion and trigger...

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Learn how to power your Raspberry Pi Pico W projects easily and flexibly with the MB102 Power Supply Module...

How to Use L298N Motor Driver with Pico W

How to Use L298N Motor Driver with Pico W

Learn how to use the L298N motor driver to control DC motors with the Raspberry Pi Pico W in MicroPython.

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Discover how to set up, code, and activate the LED based on detected sound with the Raspberry Pi...

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

In this tutorial, I’ll guide you through setting up the KY-037 sound sensor with a Raspberry Pi using...

How to Post to Reddit Using Python

How to Post to Reddit Using Python

Post to reddit automatically using a Python script.

How to Create a Time-Lapse Video with a Raspberry Pi Camera

How to Create a Time-Lapse Video with a Raspberry Pi Camera

Learn how to make a timelapse with your Raspberry Pi in Python.

How to Integrate the MPU6050 with the STM32 Blue Pill

How to Integrate the MPU6050 with the STM32 Blue Pill

Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.