Easy & Powerful Arduino Alternative? STM32 Beginner's Guide

**Programming with the STM32 Blue Pill**

The STM32 Blue Pill is a development board that offers an alternative to traditional Arduino programming. With its vast range of features and functions, it provides more memory, more precise timers, and more ADC channels than any other microcontroller on the market. One of the most notable features of the STM32 Blue Pill is its ability to offer integrated pull-up resistors, as well as pulldown resistors, which set it apart from traditional Arduino boards.

Another awesome feature of the STM32 Blue Pill is that it offers inputs with integrated pull-up and pulldown resistors. This means that users can take advantage of these features without having to add external components to their circuit. Additionally, this allows for more precise control over the input signals, which can be crucial in certain applications. The STM32 Blue Pill also supports PWM, which is an important feature for many projects. However, unlike traditional Arduino boards, the STM32 Blue Pill offers a 16-bit resolution, which provides a much higher degree of precision.

The main difference between using PWM on the STM32 Blue Pill and traditional Arduino programming is that users must declare the utilized pin as PWM and use the PWM write function. This means that they cannot simply use the analog write function, which would only offer an 8-bit resolution. The PWM write function offers a much higher degree of precision, with a resolution of 65535 steps. In comparison to traditional Arduino programming, this provides a significant advantage in many applications.

**Configuring PWM**

To configure PWM on the STM32 Blue Pill, users must use the PWM write function. This means that they must declare the utilized pin as PWM and then use the PWM write function to set the desired value. The leaf labs documentation provides detailed instructions for configuring PWM on the STM32 Blue Pill, which makes it easy for beginners to get started with this feature. With practice, users can achieve precise control over their PWM signals.

**PWM Signal Frequency**

The frequency of the PWM signal is determined by the pre-scalar value. To increase the frequency of the PWM signal, users must set the pre-scalar value to 1. This means that they must modify the timer register to count up to a smaller value. In this case, we set the pre-scalar value to 1 and uploaded the code with the changes. However, even after making these adjustments, the frequency of the PWM signal was only around 549 Hertz.

**Increasing the Frequency of the PWM Signal**

The solution to increasing the frequency of the PWM signal lay in the timer register's overflow value. To achieve a higher frequency, users must set the 16-bit timer's overflow value to something less than its maximum capacity. This is because the clock frequency of 72 megahertz represents one second, so dividing this by the original overflow value would result in a much lower frequency.

By setting the 16-bit timer's overflow value to an 8-bit value and adjusting the PWM write value accordingly, we were able to increase the frequency of the PWM signal. We then uploaded the code with these changes and observed the resulting PWM signal. The new frequency was significantly higher than before, with a maximum frequency of 36 megahertz.

**Creating Timer Interrupts**

Another feature that sets the STM32 Blue Pill apart from traditional Arduino programming is its ability to create timer interrupts. To implement precise one-second compare interrupts, users must use a different approach than traditional Arduino programming. The leaf labs documentation provides detailed instructions for creating timer interrupts on the STM32 Blue Pill, which makes it easy for beginners to get started with this feature.

**Connecting to the Serial Monitor**

In addition to its advanced features, the STM32 Blue Pill also supports connection to the serial monitor, just like traditional Arduino boards. This allows users to output data from their project directly to the serial monitor, making it easier to debug and test their code. To connect to the serial monitor, users simply need to upload their code and then open the serial monitor on their computer.

**Connecting a Potentiometer**

To demonstrate one of the STM32 Blue Pill's capabilities, we connected a potentiometer to one of its analog input pins and created a simple sketch that outputs the converted analog value to the serial monitor. The declaration of the pin is similar to traditional Arduino programming, but other than that, the rest of the code remains the same. We then uploaded the code and observed the resulting output on the serial monitor.

**Measuring Voltage Steps**

When we connected the potentiometer, we were able to adjust it to output values through the serial monitor between 0 and 4095. This range represents a 12-bit resolution, which means that users can achieve voltage steps of 0.8 millivolts instead of the usual 3.2 milliVolts offered by traditional Arduino boards with their 10-bit resolution.

**Setting Up External Interrupts**

Finally, we set up an external interrupt on one of the STM32 Blue Pill's pins and implemented a routine to handle this interrupt. This allowed us to use one of the board's advanced features in our project. The leaf labs documentation provides detailed instructions for setting up external interrupts on the STM32 Blue Pill, which makes it easy for beginners to get started with this feature.

**Programming with the STM32 Blue Pill**

In conclusion, programming with the STM32 Blue Pill offers a wide range of advantages over traditional Arduino programming. With its advanced features and functions, users can achieve precise control over their project's inputs and outputs. The leaf labs documentation provides detailed instructions for using these features, making it easy for beginners to get started with this board.

WEBVTTKind: captionsLanguage: enas you might know I love using the Arduino Nano or Arduino Pro Mini in projects since their hearts the atmega328 P microcontroller offers a lot of useful features while being easily programmable through the Arduino IDE I even made a few videos about how to use them there is how much I enjoy working with them but sometimes at least for me you notice its limitations maybe the 10 bit resolution of the ADC will footage steps of around 4.9 milli volts at five Foods is not precise enough or the maximum 8-bit PWM frequency of 62 point 6 kilo hertz is not fast enough or you need more than two external interrupt pins for your project that is why in this video I will introduce you to this development board which is also known as the blue pill its heart is the stm32 were f103 c8 t6 32-bit arm microcontroller and it can be bought from China for only $2 and best of all can be programmed through the arduino ide so let's not waste any more time and find out what advantages and disadvantages this board offers in comparison to the traditional arduino nano / pro mini let's get started this video is sponsored by jl CPCB upload your java files for review and then order high quality PCBs for ridiculously low prices currently even were free shipping and turn your project into real products to program the microcontroller we need to firstly connect it through its micro USB port to power source and grab an USB it to serial converter breakout boards after selecting its 3.3 volt modes since the stm32 operates at 3.3 volts voltage levels we can connect its ground pin to ground its TX pin to the a 10 pin and it's rx pin to the a 9 pin and as soon as the converter is connected to a computer we can start the Arduino software at this link to the additional ports manager URLs and install the stm32 f1x exports library through the bots manager as a first example sketch I created the simplest code I could think of an LED blink sketch the only difference in comparison to the traditional Arduino programming so far is the pin name which are all named according to the silkscreen on the development boards and after I connected an LED with resistor between the selected pin and ground I changed the boot zero jumper to one and selected the here shown settings and the tools options in order to upload the sketch successfully as you can see the uploader code does work without a problem but what is important to note is that when the microcontroller resets its program gets erased unless of course you change the boot zero jumper back to zero before resetting or repowering the board for more demanding tests let's try out the digital reach and the serial output function which pretty much follow the same programming language we are used to and after uploading the codes and connecting the selected pin to 5 volts or ground we can see on the serial monitor that everything works fine but wait a minute I connected it to 5 volts even though this is a 3.3 volt system the reason is that a couple of pins are fifl tolerant while others are not and by the way this pin our diagram was a great supports when working with the board but anyway another awesome feature is that the inputs not only offer integrated pull-up resistors like the Arduino does but also integrated pulldown resistors and with the digital inputs out of the way let's try something a bit more complicated like PWM the difference this time is that we must declare the utilized pin as PWM and use the PWM write function the analog write function would still work but it would only offer an 8-bit resolution like the Arduino while the PWM write function offers a resolution of 16 bits that is a difference of two hundred and fifty five steps to 65535 steps which can often be quite useful and if you're wondering where got all this information from then look no further than the leaf labs documentation there pretty much every necessary feature and function of the blue pills programming is very comprehendible explains but getting back to topic after uploading the codes and connecting the pen to the oscilloscope we can observe the PWM signal but sadly its frequency was only around 549 Hertz the problem is the timer one who's responsible for the pin and thus the PWM signal in order to change its pre scalar to one and thus speed the PWM signal upper bits I added lines to the codes according to the leaf flaps documentation uploaded its and realized that this only improved the frequency bits the still remaining problem is that the timer register counts up to a value of 65535 while the clock frequency of 72 megahertz would represents one seconds thus by dividing 72 megahertz by 65535 we would get a frequency of 1098 Hertz which is basically what we measured before so the solution is to simply the 16-bit timer aka Overflow value to something like an 8-bit value and adjust the PWM write value accordingly after uploading we now got an eight bits PWM signal just like the Arduino but with an increased frequency of 281 kilo Hertz and by pushing the timer to the maximum we could even get a PWM signal with a frequency of 36 megahertz but speaking of timers how about creating timer interrupts well I have to say by once again utilizing the leaf flaps documentation it was even simpler to implement a precise one-second compare interrupts then with the traditional Arduino programming and as you can see it also works like a charm you only have to be careful when using the same time up on interrupts and the PWM signal that usually does not work out very well next let's add a potentiometer to one of the 10 analog in pins and create a simple sketch that outputs the converted analog value to the serial monitor once again the only difference is the Declaration of the pin the rest is the same as with traditional Arduino programming and after uploading we can adjust the potentiometer to output values through the serial monitor between zero and 4095 this range of values represents a 12 bit resolution so voltage steps of 0.8 milli volts instead of the usual ORD we know steps of 3.2 million due to its 10 bit resolution finally let's set up an external interrupts which once again due to the given documentation was super easy to implement and if you're wondering why exactly pin pa1 then there's no particular reason for that since all of the pins feature the external interrupt function which according to this table should give us a total of 15 external interrupt pins instead of only 2 of the arduino now of course the Adri also offers pin change interrupts on all of their opens but they are not as fast and easy to use and after uploading the new code to the stm32 the external interrupt routine seems to also work without a problem so let's come to a conclusion the blue pill offers more memory more eye opens more Peter Frampton's more timers more ADC channels more external interrupts pins and a couple more features were also providing an overall high resolution and speed programming is even simpler than traditional Arduino programming and you can work with variables with a length of up to 64 bits the only big disadvantage is that not all Arduino libraries are compatible or ported over yet but you can always look for advice on the stm32 do we know forum so for me this development board is an awesome Arduino alternative for more demanding projects I hope you enjoyed watching this video if so don't forget to Like share and subscribe stay creative and I will see you next timeas you might know I love using the Arduino Nano or Arduino Pro Mini in projects since their hearts the atmega328 P microcontroller offers a lot of useful features while being easily programmable through the Arduino IDE I even made a few videos about how to use them there is how much I enjoy working with them but sometimes at least for me you notice its limitations maybe the 10 bit resolution of the ADC will footage steps of around 4.9 milli volts at five Foods is not precise enough or the maximum 8-bit PWM frequency of 62 point 6 kilo hertz is not fast enough or you need more than two external interrupt pins for your project that is why in this video I will introduce you to this development board which is also known as the blue pill its heart is the stm32 were f103 c8 t6 32-bit arm microcontroller and it can be bought from China for only $2 and best of all can be programmed through the arduino ide so let's not waste any more time and find out what advantages and disadvantages this board offers in comparison to the traditional arduino nano / pro mini let's get started this video is sponsored by jl CPCB upload your java files for review and then order high quality PCBs for ridiculously low prices currently even were free shipping and turn your project into real products to program the microcontroller we need to firstly connect it through its micro USB port to power source and grab an USB it to serial converter breakout boards after selecting its 3.3 volt modes since the stm32 operates at 3.3 volts voltage levels we can connect its ground pin to ground its TX pin to the a 10 pin and it's rx pin to the a 9 pin and as soon as the converter is connected to a computer we can start the Arduino software at this link to the additional ports manager URLs and install the stm32 f1x exports library through the bots manager as a first example sketch I created the simplest code I could think of an LED blink sketch the only difference in comparison to the traditional Arduino programming so far is the pin name which are all named according to the silkscreen on the development boards and after I connected an LED with resistor between the selected pin and ground I changed the boot zero jumper to one and selected the here shown settings and the tools options in order to upload the sketch successfully as you can see the uploader code does work without a problem but what is important to note is that when the microcontroller resets its program gets erased unless of course you change the boot zero jumper back to zero before resetting or repowering the board for more demanding tests let's try out the digital reach and the serial output function which pretty much follow the same programming language we are used to and after uploading the codes and connecting the selected pin to 5 volts or ground we can see on the serial monitor that everything works fine but wait a minute I connected it to 5 volts even though this is a 3.3 volt system the reason is that a couple of pins are fifl tolerant while others are not and by the way this pin our diagram was a great supports when working with the board but anyway another awesome feature is that the inputs not only offer integrated pull-up resistors like the Arduino does but also integrated pulldown resistors and with the digital inputs out of the way let's try something a bit more complicated like PWM the difference this time is that we must declare the utilized pin as PWM and use the PWM write function the analog write function would still work but it would only offer an 8-bit resolution like the Arduino while the PWM write function offers a resolution of 16 bits that is a difference of two hundred and fifty five steps to 65535 steps which can often be quite useful and if you're wondering where got all this information from then look no further than the leaf labs documentation there pretty much every necessary feature and function of the blue pills programming is very comprehendible explains but getting back to topic after uploading the codes and connecting the pen to the oscilloscope we can observe the PWM signal but sadly its frequency was only around 549 Hertz the problem is the timer one who's responsible for the pin and thus the PWM signal in order to change its pre scalar to one and thus speed the PWM signal upper bits I added lines to the codes according to the leaf flaps documentation uploaded its and realized that this only improved the frequency bits the still remaining problem is that the timer register counts up to a value of 65535 while the clock frequency of 72 megahertz would represents one seconds thus by dividing 72 megahertz by 65535 we would get a frequency of 1098 Hertz which is basically what we measured before so the solution is to simply the 16-bit timer aka Overflow value to something like an 8-bit value and adjust the PWM write value accordingly after uploading we now got an eight bits PWM signal just like the Arduino but with an increased frequency of 281 kilo Hertz and by pushing the timer to the maximum we could even get a PWM signal with a frequency of 36 megahertz but speaking of timers how about creating timer interrupts well I have to say by once again utilizing the leaf flaps documentation it was even simpler to implement a precise one-second compare interrupts then with the traditional Arduino programming and as you can see it also works like a charm you only have to be careful when using the same time up on interrupts and the PWM signal that usually does not work out very well next let's add a potentiometer to one of the 10 analog in pins and create a simple sketch that outputs the converted analog value to the serial monitor once again the only difference is the Declaration of the pin the rest is the same as with traditional Arduino programming and after uploading we can adjust the potentiometer to output values through the serial monitor between zero and 4095 this range of values represents a 12 bit resolution so voltage steps of 0.8 milli volts instead of the usual ORD we know steps of 3.2 million due to its 10 bit resolution finally let's set up an external interrupts which once again due to the given documentation was super easy to implement and if you're wondering why exactly pin pa1 then there's no particular reason for that since all of the pins feature the external interrupt function which according to this table should give us a total of 15 external interrupt pins instead of only 2 of the arduino now of course the Adri also offers pin change interrupts on all of their opens but they are not as fast and easy to use and after uploading the new code to the stm32 the external interrupt routine seems to also work without a problem so let's come to a conclusion the blue pill offers more memory more eye opens more Peter Frampton's more timers more ADC channels more external interrupts pins and a couple more features were also providing an overall high resolution and speed programming is even simpler than traditional Arduino programming and you can work with variables with a length of up to 64 bits the only big disadvantage is that not all Arduino libraries are compatible or ported over yet but you can always look for advice on the stm32 do we know forum so for me this development board is an awesome Arduino alternative for more demanding projects I hope you enjoyed watching this video if so don't forget to Like share and subscribe stay creative and I will see you next time