Easy & Powerful Arduino Alternative? STM32 Beginner's Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
as 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 [Music] 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
Info
Channel: GreatScott!
Views: 862,169
Rating: 4.9303002 out of 5
Keywords: STM32, µC, beginner, beginners, berginner's, guide, tutorial, how, to, diy, program, arduino, ide, nano, pro mini, comparison, programming, MCU, mcu, F103, C8T6, STM32F103C8T6, blue, pill, blue pill, timer, adc, ADC, speed, clock, frequency, pwm, PWM, external, interrupt, register, fast, advantage, disadvantage, compare, ftdi, breakout, converter, seriell, electronics, greatscott, greatscott!
Id: EaZuKRSvwdo
Channel Id: undefined
Length: 9min 49sec (589 seconds)
Published: Sun Jan 21 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.