Wireless Debugging for Micromouse Using Bluetooth HC-05 and HC-06 : Importance , Overview, Connection, Using printf() , Pairing Process, Applications, Maze Algorithm Debugging

Wireless Debugging for Micromouse Using Bluetooth HC-05 and HC-06 : Importance , Overview, Connection, Using printf() , Pairing Process, Applications, Maze Algorithm Debugging

Bluetooth UART debugging is one of the most useful techniques in Micromouse development. It allows developers to monitor sensor values, motor control data, PID tuning results, encoder feedback, and maze-solving status wirelessly without connecting a USB cable every time. When developing a Micromouse, tethering it to a PC with a physical USB cable for debugging is highly impractical. A cable adds drag, alters the weight distribution, and disrupts the precise PID tuning required for maze navigation.

A common configuration is:

  • HC-06 module connected to the Micromouse robot
  • HC-05 module connected to the PC
  • UART communication through the STM32 microcontroller

This setup creates a wireless serial communication bridge that works similarly to a USB serial monitor.


Why Bluetooth Debugging is Important in Micromouse

During Micromouse development, many parameters must be monitored in real time:

  • Wall sensor ADC values
  • Gyroscope angle data
  • Encoder counts
  • Motor PWM outputs
  • PD or PID controller response
  • Maze coordinates
  • Flood-fill map information
  • Speed profiles

Using Bluetooth debugging provides several advantages:

  • Wireless monitoring during movement
  • No USB cable limitation
  • Real-time parameter tuning
  • Safer testing at high speed
  • Easy data logging on PC

This method is especially useful when the robot runs inside a maze where USB cables are impractical. A wireless Bluetooth UART bridge solves this entirely. This comprehensive guide details how to configure an HC-05 module (on the PC side) to pair automatically with an HC-06 module (on the Micromouse) to stream real-time debugging data from an STM32 microcontroller.


HC-06 and HC-05 Overview

  HC-06

  The HC-06 module is commonly used as a Bluetooth slave device.

  Features

  • Bluetooth 2.0 + EDR
  • UART communication
  • Simple AT commands
  • Works as slave only
  • Low cost
  • Easy STM32 interfacing
  • 4 Pins
  In this project:

  • HC-06 is mounted by 4 pin-header on the Micromouse
  • STM32 sends debug data to HC-06

  HC-05

  The HC-05 module can operate as both master and slave.

  Features

  • Master/slave mode
  • UART interface
  • AT command support
  • Stable wireless serial communication
  • Widely available
  • 6 Pins
  In this setup:
  • HC-05 is connected to the PC
  • HC-05 operates as master
  • It connects automatically to HC-06

  System Architecture

+---------------------+
|      STM32F411      |
|                     |
| UART TX/RX          |
+----------+----------+
           |
           |
     +-----+-----+
     |   HC-06   |
     +-----------+
           )))
      Bluetooth Link
           )))
     +-----------+
     |   HC-05   |
     +-----+-----+
           |
      USB-UART
           |
+----------+----------+
|         PC          |
| Serial Monitor Tool |
+---------------------+

  Required Components

Component Purpose
STM32F411CEU6 Main controller board
HC-06 Robot Bluetooth module
HC-05 PC-side Bluetooth module
USB-to-UART Adapter Connect HC-05 to PC
Micromouse PCB Robot system
Serial terminal software Debug monitor

HC-06 Connection to STM32 Micromouse

  Basic UART 4 Pin Wiring 

HC-06 Pin STM32 Connection
VCC 5V or 3.3V
GND GND
TXD STM32 RX
RXD STM32 TX

  UART Configuration

   Typical UART settings:

   Parameter Value
   Baud rate 9600 or 115200
   Data bits 8
   Stop bits 1
   Parity None

   For fast debugging, 115200 baud is recommended.

  STM32 UART Initialization

   Using STM32 HAL library:

  UART_HandleTypeDef huart1;

  void MX_USART1_UART_Init(void)
  {
    huart1.Instance = USART1;
    huart1.Init.BaudRate = 115200;
    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);
  }

  Sending Debug Messages

    Simple UART Transmission as follow

   char msg[] = "Micromouse Start\r\n";

   HAL_UART_Transmit(&huart1,
                  (uint8_t*)msg,
                  strlen(msg),
                  100);

  Using printf() for Bluetooth Debugging

   One of the best methods is redirecting printf() to UART. This is more useful.

   Retarget printf() : Modified as follow in core\src\syscalls.c

__attribute__((weak)) int _write(int file, char *ptr, int len)

{

// modified for serial communication

HAL_StatusTypeDef hstatus;


hstatus = HAL_UART_Transmit(&huart1, (uint8_t *) ptr, len, HAL_MAX_DELAY);

if (hstatus == HAL_OK) return len;


return EIO;

}

    Now debugging becomes simple:

   printf("Encoder Left : %d\r\n", encoder_left);
   printf("Gyro Angle   : %.2f\r\n", gyro_angle);
   printf("PWM Output   : %d\r\n", pwm_value);

HC-05 Connection to PC

The HC-05 module can be connected to a PC using a USB-to-UART converter.

HC-05 Pin PC Serial Adaptor Notes
VCC 5V or 3.3V Check your specific module breakout board requirements.
GND GND Common ground is essential.
TXD RX Connect TX to RX.
RXD TX Connect RX to TX
EN / KEY External pin-head / High Used to enter AT command mode during configuration.

Recommended Serial Monitor Software

Useful PC tools include:

  • PuTTY 
  • Arduino IDE Serial Monitor

These programs display UART messages in real time.


Bluetooth Pairing Process

  Step 1: Configuring the HC-06 (Slave)

  Before pairing, you must configure both modules using AT commands via a serial terminal (like Tera Term, PuTTY, or Arduino Serial Monitor). Connect your USB-to-TTL adapter with the HC-06 to your PC.

  1. Open your serial terminal at the default HC-06 baud rate (usually 9600 or 38400, with No line endings/NR or CR depending on firmware version).

  2. Send the following commands to configure the module:

    AT          --> Expect response: OK
    AT+NAMEHC06 --> Sets module name to "HC06"
    AT+PIN1234  --> Sets pairing password to "1234"
    AT+BAUD8    --> Sets baud rate to 115200 bps (Highly recommended for fast debugging)
  1. Crucial Step: Find the MAC address of the HC-06. You can do this by making it discoverable and scanning it with a smartphone Bluetooth scanner app. Note the address down (e.g., 98:D3:31:F4:12:3C).  Note: For AT configuration, replace colons with commas if required by your firmware version (e.g., 98d3,31,f4123c).

  Step 2: Configuring the HC-05 (Master)

   To put the HC-05 into AT command mode, hold down the small button on the module while powering it on (or pull the KEY/EN pin HIGH). The onboard LED will blink slowly (once every 2 seconds), indicating it is in configuration mode. Open your terminal at 38400 baud with Both NL & CR enabled.

   Execute the following sequence:

    AT                      --> Expect: OK
    AT+ORGL                 --> Restores factory default configurations
    AT+ROLE=1               --> Sets HC-05 to Master Mode
    AT+CMODE=0              --> Sets connection mode to fixed address (strict pairing)
    AT+BIND=98d3,31,f4123c  --> Binds to your HC-06 MAC address (Notice the comma notation)
    AT+UART=115200,0,0      --> Sets baud rate to 115200, 1 stop bit, no parity
    AT+RESET                --> Reboots the module into normal data mode 

  Once reset, power cycle both modules. The rapid flashing on both devices should change to a synchronized double-blink every few seconds, indicating they have successfully linked wirelessly.


Debugging Applications in Micromouse




  Sensor Calibration

  Bluetooth debugging allows real-time monitoring of:

  • IR sensor values
  • Wall thresholds
  • Ambient light effects

  Example:

  printf("L:%d F:%d R:%d\r\n", sensor_left, sensor_front, sensor_right);

  PD Controller Tuning

  PD control tuning becomes easier when viewing:

  • Error values
  • Derivative values
  • PWM response

  Example:

  printf("E:%f D:%f PWM:%d\r\n", error, derivative, pwm);

  This helps reduce oscillation and improve stability.

  Encoder Monitoring

  Wheel encoder debugging is essential for accurate movement.

  Example:

  printf("ENC L:%d R:%d\r\n", encoder_l, encoder_r);

  This helps verify:

  • Straight driving
  • Rotation accuracy
  • Distance calculation

  Maze Algorithm Debugging

  Flood-fill or DFS algorithm states can also be monitored. 

  For bidirectional communication with simulator and Micromouse ,

  Retarget scanf() : Modified as follow in core\src\syscalls.c

__attribute__((weak)) int _read(int file, char *ptr, int len)

{

// modified for serial communication

int DataIdx = 0;

uint8_t thechar;

thechar= ' ';

while(thechar!= '\n' && thechar != '\r' && DataIdx<len)

{

__HAL_UART_CLEAR_OREFLAG(&huart1);


HAL_UART_Receive(&huart1, (uint8_t *)&thechar, 1, 100);


if ( thechar >= 0xFF)

{

printf("\n\r !!! Please enter a valid ASCII character \n");

return 0xFF;

}

*ptr++ =thechar;

DataIdx+=1;

}

*ptr = '\0';

return DataIdx;

}

  Example:

  printf("CELL (%d,%d)\r\n", x, y);


char * Simulation::readline() {

static char buf[100];

scanf("%s", buf);

return (char *) &buf[0];

}

  Useful for:

  • Route verification
  • Mapping visualization
  • Logic debugging

  DMA-Based UART Debugging

  For high-speed Micromouse systems, DMA transmission is preferred.

  Benefits include:

  • Lower CPU usage
  • Faster transmission
  • Non-blocking communication
  • Better control loop timing

  Example:

  HAL_UART_Transmit_DMA(&huart2, tx_buffer, length);

Power Supply Considerations

Bluetooth modules can introduce electrical noise.

Recommended practices:

  • Use stable 3.3V regulator
  • Add bypass capacitors
  • Separate motor power and logic power
  • Keep UART traces short
  • Avoid routing near motor drivers


Advantages of Bluetooth UART Debugging

Advantage Description
Wireless debugging No USB cable needed
Real-time monitoring Observe robot behavior live
Easier tuning Faster PD/PID adjustment
Portable testing Useful in competition
Simple implementation UART is easy to use

Conclusion

Bluetooth UART debugging using HC-06 and HC-05 is an effective solution for Micromouse development. By connecting the STM32 microcontroller wirelessly to a PC, developers can monitor sensors, tune controllers, verify encoder data, and debug maze algorithms in real time.

The combination of STM32 UART communication and Bluetooth serial modules provides a simple, low-cost, and highly practical debugging system suitable for both beginner and advanced Micromouse projects.

Comments

Popular posts from this blog

How to Build a Micromouse Robot - Mechanical, Hardware, Software

Micromouse Competitions - Types, Overview, Comparison, Advantages, Worldwide

Complete Guide to Micromouse Maze - Dimensions, Structure and Components, Building