Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Development Boards & SBCs

STM32F103 Blue Pill Tutorial: GPIO, Timer and UART Guide

STM32F103 Blue Pill Tutorial: GPIO, Timer and UART Guide

March 11, 2026 /Posted byJayesh Jain / 0

The STM32F103 Blue Pill tutorial UART GPIO guide you’ve been looking for — the Blue Pill is arguably the most capable sub-₹200 development board available in India, packing a 72 MHz Cortex-M3 with rich peripherals. This tutorial covers GPIO control, UART communication, and timer configuration with working code.

Table of Contents

  • Setting Up Blue Pill Development
  • GPIO Configuration and Control
  • UART Serial Communication
  • Timers and PWM
  • I2C Peripheral Interface
  • Blue Pill Tips for Indian Makers
  • Frequently Asked Questions

Setting Up Blue Pill Development

The STM32F103C8T6 Blue Pill board uses an ST-Link V2 programmer for flashing. In India, ST-Link clones are available for ₹150–300. Install STM32CubeIDE (free from ST) or use Arduino IDE with the STM32duino board package. For professional work, STM32CubeIDE with HAL libraries is recommended.

Key specs: 72 MHz Cortex-M3, 64 KB flash, 20 KB SRAM, 37 GPIO pins, USB FS, CAN, 3× USART, 2× I2C, 2× SPI, 7× timers, 10× 12-bit ADC channels. Operating voltage 3.3V — use a logic level converter when interfacing with 5V Arduino modules.

Recommended: Arduino UNO R3 Development Board ATMEGA16U2 ATMEGA328P (DIP) — Arduino UNO R3 — if you prefer a simpler 5V platform with the same ATmega328P AVR architecture and broader library support for Indian beginners.

GPIO Configuration and Control

STM32 GPIO modes differ from Arduino’s simple pinMode. Each pin can be configured as Input (floating/pull-up/pull-down), Output (push-pull/open-drain), Alternate Function, or Analog. Speed settings (2/10/50 MHz) control slew rate.

// STM32 HAL GPIO blink example
#include "stm32f1xx_hal.h"

void SystemClock_Config(void);
static void MX_GPIO_Init(void);

int main(void) {
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  
  while (1) {
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); // Built-in LED
    HAL_Delay(500);
  }
}

static void MX_GPIO_Init(void) {
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  __HAL_RCC_GPIOC_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}
Recommended: ESP32-WROOM-32E Development Board Module for Arduino — ESP32-WROOM-32E — for projects requiring WiFi alongside GPIO control, the ESP32 complements STM32 projects well as a connectivity module.

UART Serial Communication

STM32F103 has three USART peripherals. USART1 is on PA9 (TX) and PA10 (RX). Configure UART with HAL for reliable serial communication with sensors, GSM modules (SIM800L, very common in India), and GPS modules.

// UART transmit with HAL
UART_HandleTypeDef huart1;

void MX_USART1_UART_Init(void) {
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 9600;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  HAL_UART_Init(&huart1);
}

// Send a string
char msg[] = "Hello from STM32!
";
HAL_UART_Transmit(&huart1, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);

Timers and PWM

STM32F103 has seven timers. Timer 2 on PA0 can generate PWM for motor speed control, LED dimming, or servo control. Configure the prescaler and auto-reload register for desired frequency.

// PWM on TIM2 Channel 1 (PA0) at 50Hz for servo
TIM_HandleTypeDef htim2;
TIM_OC_InitTypeDef sConfigOC = {0};

htim2.Instance = TIM2;
htim2.Init.Prescaler = 71;       // 72MHz / 72 = 1MHz timer clock
htim2.Init.Period = 19999;        // 1MHz / 20000 = 50Hz
HAL_TIM_PWM_Init(&htim2);

sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 1500;           // 1.5ms = centre position
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
Recommended: Waveshare RP2350-Plus Development Board — Waveshare RP2350-Plus — if you prefer MicroPython for rapid prototyping with a powerful modern ARM Cortex-M33 microcontroller.

I2C Peripheral Interface

STM32F103 has two I2C peripherals. I2C1 uses PB6 (SCL) and PB7 (SDA). Common I2C devices available in India include OLED displays (SSD1306), temperature sensors (BMP280, DS18B20 via 1-wire), and the MPU6050 IMU.

// I2C read from MPU6050
I2C_HandleTypeDef hi2c1;
uint8_t data[6];
uint8_t reg = 0x3B; // ACCEL_XOUT_H

// Request 6 bytes starting at register 0x3B
HAL_I2C_Master_Transmit(&hi2c1, 0x68<<1, &reg, 1, HAL_MAX_DELAY);
HAL_I2C_Master_Receive(&hi2c1, 0x68<<1, data, 6, HAL_MAX_DELAY);

int16_t ax = (data[0]<<8) | data[1]; // Raw accelerometer X

Blue Pill Tips for Indian Makers

  • Blue Pill boards from Robu/Amazon vary in quality — check if the USB resistor (R10) is 1.5kΩ (correct) or 10kΩ (wrong) for USB to work
  • The onboard 3.3V LDO can only supply ~100 mA — power external sensors from a separate supply
  • Always use a 3.3V logic level converter when connecting to 5V modules like HC-05 Bluetooth
  • STM32CubeMX generates peripheral init code automatically — highly recommended for beginners
  • Back up your BOOT0 jumper setting — accidentally setting it to 1 boots into bootloader mode

Frequently Asked Questions

Can Blue Pill be programmed with Arduino IDE?

Yes. Install the STM32duino board package (by STMicroelectronics) in Arduino IDE. Select “Generic STM32F1 series” board and upload via ST-Link or serial bootloader.

What is the maximum GPIO current on Blue Pill?

Each GPIO pin can source/sink up to 25 mA, with a total chip limit of 150 mA. Always use current-limiting resistors for LEDs and transistors for relay/motor control.

Is Blue Pill 5V tolerant?

Some pins are 5V tolerant (marked “FT” in the datasheet), but the supply voltage is 3.3V. Check the datasheet carefully before connecting 5V logic directly.

Which is better for motor control — Blue Pill or Arduino?

Blue Pill with STM32’s hardware timers is significantly better for motor control (multiple PWM channels, encoder interface, dead-time insertion for complementary outputs). Arduino’s timers are simpler but less capable.

Shop Development Boards & SBCs at Zbotic →

Tags: ARM microcontroller, Blue Pill, embedded c++, STM32 India, STM32 tutorial, STM32F103, UART GPIO
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
STEM Kit Comparison: Makeblock...
blog stem kit comparison makeblock vs arduino vs lego mindstorms 598924
blog commuter e bike vs performance e bike which to build india 598933
Commuter E-Bike vs Performance...

Related posts

Svg%3E
Read more

Battery Charger Module TP4056: LiPo and 18650 Charging Guide

April 1, 2026 0
The TP4056 battery charger module is one of the most essential components for any battery-powered electronics project. Costing under ₹30,... Continue reading
Svg%3E
Read more

Buck Converter vs Boost Converter: Voltage Regulation Guide

April 1, 2026 0
Understanding buck converters vs boost converters is essential for every electronics project involving power management. Whether you are stepping down... Continue reading
Svg%3E
Read more

Google Coral TPU: Accelerating AI Projects on Raspberry Pi

April 1, 2026 0
The Google Coral TPU (Tensor Processing Unit) transforms a Raspberry Pi from a sluggish AI hobbyist tool into a real-time... Continue reading
Svg%3E
Read more

NVIDIA Jetson Nano Projects India: Getting Started Guide

April 1, 2026 0
The NVIDIA Jetson Nano is the most accessible GPU-accelerated AI computer for developers in India. With 128 CUDA cores, a... Continue reading
Svg%3E
Read more

ATtiny85 Projects: Tiny Microcontroller for Space-Constrained Builds

April 1, 2026 0
The ATtiny85 is the Swiss Army knife of tiny microcontrollers — just 8 pins, 8 KB of flash, and a... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now