Selecting a perfect Microcontroller – Why STM32?

Hi tech enthusiast,

First of all, let me divide this article into two parts.

  1. Arduino Nano for micromouse design (Past experience)?

  2. Why we need STM32?

:warning: Spoiler Alert : If you are familiar with the Arduino Nano and its lack of capabilities in making micromouse kindly move to the second part of the article.

1. Arduino Nano for micromouse design (Past experience)?

According to my opinion, in any career, we need to surpass several stages in several areas to reach the pinnacle of that career. This same concept applies to anyone’s robotics journey (or career) too. In fact, in my robotics career, I have already surpassed 3 stages in the microcontroller area until now (and a lot to explore :grinning:).

For the first-ever competition in my robotics career (SLRC 2017) I and my team (CircuitBreakers) used the Arduino UNO which I think you all know well. Then I mastered the Arduino Mega thanks to the insights and guidance given by the seniors. Well, for my first stage those are the two microcontrollers I was able to learn and master. This is an image of the robot that we designed using Arduino UNO for SLRC 2017.

Mid of 2018, Our team started to design the micromouse for our second competition (SLIIT ROBOFEST 2018). Here, I was able to discover this tiny little Arduino Nano which packs the same architecture of Arduino UNO. At that point, we were super hyped and planned the robot from it. The main reason for choosing this microcontroller is its small form factor as we were limited to make the robot in the dimension of 12cm x 12cm. Though on the development process we had some issues with memory constraints, encoder accuracy, processing time, etc. we were able to complete the robot successfully.

On the competition day, after having discussions with the competitors and judges, finally, we were able to track the main cause of our above-mentioned issues. That is nothing but the brain of our micromouse – Arduino Nano. So, we started finding a new microcontroller aka the-brain. After researching for several months, we came up with a microcontroller class which addresses all the issues we encountered

image

previously (Third stage of my career). The image above is the robot we made for SLIIT ROBOFEST 2018 and you can watch this video about how we performed in that competition with Arduino Nano.

2. Why we need STM32?

To be used in a micromouse, several requirements need to be fulfilled by a microcontroller. It should be compact/small in size, should have enough flash memory to contain the code, RAM to hold the variables and sufficient I/O pins as well as communication buses. These basic requirements are fulfilled by microcontrollers like Arduino Nano, Arduino Pro Mini, etc.

In a typical micromouse, maze solving is one of the main crucial tasks and it consumes a lot of processing power too. To effectively carry on this task while traversing the maze is a key turning point of your micromouse. Due to lack of clock speed and the less amount of memory in Arduino based microcontrollers like Nano (16 MHz clock, 32 KB flash memory, and 2 KB SRAM), they cannot effectively perform this task while in the move.

Encoder count is one of the main key aspects in making turns and going straight specific distances in any robot. Lack of interrupt pins in a microcontroller will limit these features as we cannot use quadrature encoders.

Also, if you are planning to use IR sensors or Time of Flight (ToF) sensors to measure distances to the walls using Arduino Nano, complex tasks like maze solving may create bottlenecks for the micromouse performance.

Storing properties of every cell in the maze may exceed the available memory of microcontroller if our memory is limited to a small amount. This is one of the major drawbacks of using Arduino Nano as the basic libraries mostly fill up the available memory.

So, in conclusion, switching to the STM32 family will eradicate all the issues described above. As a starting point for your micromouse, begin your journey with STM32F103C8T6 aka Blue Pill which is depicted below.

This STM32 Development Board in the market with its 32-bit CPU and ARM Cortex M3 architecture can easily outperform Arduino Nano. The best thing about this microcontroller is, it can be programmed using Arduino IDE. You can find more insights from the datasheet.

Some of the highlighted key factors are,

  • CPU Frequency: 72 MHz

  • Number of GPIO pins: 37 (most of them 5V tolerant, and all can support external interrupts)

  • Number of PWM pins: 12

  • Analog Input Pins: 10 (12-bit)

  • I2C Peripherals: 2

  • SPI Peripherals: 2

  • Timers: 3(16-bit), 1 (PWM)

  • Flash Memory: 64KB

  • RAM: 20kB

You can find the pin diagram of Blue Pill in the below image.

Even you can program this device using an In-Circuit Serial Programmer (ICSP). The most popular one is the ST-Link/V2. This method is much faster than the Arduino IDE. The programming process using this method will be covered in another article.

You can find a speed comparison of Arduino Nano and STM32 in here.

:no_entry: Caution: Be careful when you are selecting I/O pins for your project. Even though the schematic depicts PB3, PB4, PA11, PA12, and PA15 as GPIO, they are specially designed for USB communication or debugging purposes and won’t work as regular I/O pins without a special reconfiguration.

As a conclusion, the STM32 family outperforms other basic microcontroller families in every aspect of designing a micromouse and can be used to achieve the desired objectives very easily. Once you set up the programmer and the board, it is no different from the familiar Arduino, but it is way more fun!!!
Enjoy.

Please add your suggestions and questions below to improve my future articles. Good luck with making your micromouse robot.
Thank You!

2 Likes