PlatformIO - A True Alternative to the Arduino, MBED, and STM32 IDEs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is gary sims and this is gary explains now microcontroller boards are great fun and really good for making projects and tinkering and learning i've got a few boards here that are kind of picked up over the years but one thing is these are all different it's all from different manufacturers they support different ecosystems they do different things and that sometimes can be a bit daunting because this is great diversity which is great in the terms of we have choice but when it comes to the tools to writing the software debugging the software deploying the software on these boards you're kind of a bit lost at sea you've got to choose between you know arduino and embed and stm32 cube and there's loads of different systems out there zephyr you know which one are you going to use which one's supported by my board well there is a system that kind of takes all of this pain away by adding a level of abstraction and allows you to kind of work with many many different types of boards and many many different types of ecosystem all from inside one tool and it's called platform io and today i want to take a look at platform io so if you want to find out more please let me explain so as i said when you pick a board you might pick a particular family of processor this is a arm cortex processor or it might be the esp32 processor and there are loads loads of different types of processors and then you say okay what framework am i going to use am i going to use arduino am i going to use uh embed am i going to use zephyr am i going to use free rtos what what am i going to do and then you're going to look at the the individual board one board might have a certain clock rate or certain amount of ram another one might include wi-fi might not include wi-fi and you've got to tweak and configure everything for the individual boards that you're using if you just go onto a website to try and buy one of these boards there's just so many of them available different types of capabilities and features and so on and price points of course now if you use a system like arduino then you have the advantage a lot of that is abstracted away as i was saying you just have got this board and it kind of works but there is a tool that adds even more great abstraction and does a lot of the hard work and heavy lifting for you so that not only you can use arduino you can use mbed you can use therefore rtos you can use uh stm32 cube all from inside one tool and when you try to use something new it will go away and download it all automatically for you configure it and then it kind of just works and that's called platform io so we just look at some of the numbers here that platform i o give out 43 different platforms 24 different frameworks that would include things like arduino and embed 966 different types of board 222 examples and over 10 000 libraries so the fact that it supports these frameworks platforms and boards all in one place makes it a really useful tool so this is going to be very much a hands-on approach what we're going to do is we're going to take three different types of boards so an official arduino board an esp32 board and an stm32 blue pill board which are really really cheap a couple of dollars you can pick them up for and we're going to get arduino code to run on all three of them using platform io so let's go over to the desktop and let's start so the first step is to install visual studio code so you go over to code.visualsudo.com and here it is download for windows there are of course other versions available i'm going to be showing how you do this on windows so we will download that now the installation is very straightforward you accept the license agreement you pick where you want to install it and then obviously you can pick here whether you want to create desktop icons and so on definitely want to make sure this is added to the path as is the default there and then that will just install so getting platform io is pretty simple if you just click on the get platform io now it's not going to give you a download what actually does is it tells you what to do for visual studio code so what you do is you open up the visual studio code extension manager and then you type in here search for platform i o so one down there two here clicking source let's go over and do that so here is the extension manager we click on there we type in here plot form io there it is the first one oh second one now that comes up here and now you just click install so it's installing inside of visual studio as a built-in extension so really really easy to install now it's worth mentioning the install can take quite a while so we'll just let it finish and then we'll come back in a moment now after you've installed platform i o you do need to restart a visual studio code which i have done now the thing is to look here here on the left you can see the icon for platform io that will give you a quick access to a whole bunch of things but where you really want to go is the pio home now you can get to there by clicking on open which brings up the pio home or if you look down here in the bottom left-hand corner there's a tiny little house okay so that's actually the pio home platform io home so you can click on that to get to exactly the same page now here is where you want to start doing your work on the left hand side home projects as existing projects we've already got boards now this is where interesting this is where you can search to see whether the board you've got is supported let's say i've got the mkr 1000 which is an official arduino board yes there it is it's supported and it supports the arduino framework but i've also got and we'll be looking at this soon i've also got a blue pill which of course is the stm 32 chips and look at this if you've got a blue pill it supports one two three four five six different frameworks so just here inside this one tool i can program the blue pill not only with arduino but also with a whole bunch of other stuff including stm32 which causes the libraries provided by uh st electronics themself now i've also got for example a micro bit i did a review of that a few years ago so here's a micro bit and again look at this it supports arduino embed and zephyr rtos so as you can see in all these cases there's a whole bunch of frameworks all supported by these boards so what i'm going to do is i'm going to write a very simple arduino program flash is an led on and off and then we're going to use it on different boards all from inside platform io okay so i'm going to start with the mkr 1000 which of course is an actual official arduino board and so what we're going to do now is you can go to home and you can say let's start a new project and we'll call this project just you know mega test and why not indeed and we're going to start as i said with the mkr 1000 so you can select that there and we want to run with arduino and so that will go ahead and create the project now one thing to note when you use a new framework or you use a new uh kind of system for example if you switch over from arduino to the stm32 chips this uh project creation can take a few minutes because it downloads all the support files so when you ju unfortunately doesn't give a progress that's the big thing but when it just says please wait just please wait i've made the mistake of being impatient before just wait and it will come up in a moment with everything that it needs and there we go that finished and over here on the left now we can see in the explorer mega test our project and the main code is under the source and main.cpp as you can see that looks like a fairly standard arduino project set up and loop so let's replace that with the classic blinky to blink the onboard led and then we will just compile that and load it onto our arduino board okay so here is the fairly standard uh blinky program for arduino the only difference in this and maybe a normal arduino program is we have this include arduino dot h at the top here which tells platform io which um which kind of libraries we want to use pin mode this is an arduino call uh set the uh led built in led to be an output digital right high wait one second digital right low basically on off on off with a second delay between each one so this is an arduino program written inside of platform io and connected to an arduino board now right down here at the bottom look at this there's this tick and this kind of upload thing tick we'll just do a compile upload we'll do a compile and then an upload if it's required so let's just hit the upload button to make sure that it actually compiles i haven't got any mistakes no that looks pretty good yep great and now we can do the upload which will upload it on to the board and there we go it's just building in release mode checking all that yes it's okay and then it should there we go the stuff going across it's been uploaded so now here on my board i have a flashing led okay next i want to move away from my official arduino board to an esp32 board these are very popular very cheap come with things like built-in wi-fi now they don't a feature not an official arduino board so there are some libraries that allow you to compile arduino now they're all built into platform io but here's the catch normally you'd have to update the firmware on this board so that it understands the download protocol for the arduino ide but in fact with platform io platform io allows you to use different systems to download the same program so it actually understands how to flash uh esp32 boards without you having to change the firmware so this board here is fresh out of the packet it's never been upgraded it's never been had anything changed it's actually out of the packet and i'm going to use it straight away now with platform io so let's see how you do that so if we go over now to here and we were to look for that we can go to boards and we can now look for the esp32 now there are a lot of them available the one i've got is this uh now if there is not enough if it's not if the list is too short here you can just change this to say show me a thousand and then we can scroll down very quickly now i have the do it esp dev kit version one now when you click on that you'll actually get a web page comes up on the platform io website and it tells you this little bit of information here look at this to use this board you need to add these options to the platform io.ini file so i'm just going to cut and paste that and now we're going to go back into visual studio and here on the left you can see there is a platform i o any file at the moment it's got the mkr 1000 in there so what we can now do is add in a second board so we've now added in the esp32 the only thing you need to add in extra is which framework we're using so we need three lines there platform board and framework and we can save that and now if we try to do a build what will actually happen is it will build two versions it will build one version for the mkr 1000 which we've already uh see building down there already and now look it's starting to build a version for the esp32 and again if it needed some extra files in this case it says well i need some platform files for the esp32 it goes ahead and downloads those for you so really really easy completely integrated every time you pick something new it says oh i know how to deal with that i'll go and get the files for it so we just let that download and it will have then built the code for the esp32 board okay so finally finishing there you can see we got the success we've built the kit the program for the mkr 1000 and now also for the esp32 both of them they're marked as success now if down here where it says default in the bottom line you can actually pick which project you want to do default is built for everything or you could just say actually i just want to concentrate on the the esp32 at the moment so it'll only just keep building that one when you click on the build okay so let's plug in the esp32 board and then let us um flash it over one thing to note is that depending on your esp board you might need to kind of press a boot button or have it pressed and holding it down while you are flashing it over each board is a bit different you need to just check the website for the or the instructions for that particular ball so that's been flashed over and as you can see now i have a blinking led on the esp32 board so good stuff okay so final example here i have an stm32 blue pill as they are called and i've actually got an st link debug module there so can i use this with platform i o will it understand an arduino program downloaded over st link sure it will now one thing to note this is actually a fake blooper i didn't realize that until after it actually arrived it's got the clone chip on it we will have to do is do one bit of configuration to make platform io understand the different type of chip but besides that it will work as it is so let's go over to platform io and and change the configuration so that we can talk to this board as well so just as we did before we go over now to boards and we're going to search for blue pill and that will give us the different variation exist the c6 variation the c8 the c8 with 128k of ram i've got this one well it would have been this one if it was an original and this will open up the web page with again the platform i o information that we need so i'm going to cut and paste that go back into platform io and inside my platform any file here we're going to add in again that and we just need to add in the fact that we're using the arduino uh the arduino framework okay again that should now work we will be able to go ahead and build that what i'm actually going to do is i'm going to change the default now just to be the blue pill so it doesn't rebuild and try to flash over uh the other two balls that we're already working on okay so i'm going ahead and building the version for the blue pill now if we try to flash that over we'll see it actually will fail and the reason is of course this is the fake blue pill board and they each have a hardware identification if you look up here it says it was expecting this code but in fact it got this code so what we need to do is tell platform io that that other code is actually the one to expect so you go over to your platform io um for any file there and you add these two lines at the end there set cpu t apid and then you use this new number the one that actually it did find and if you try to flash it over then it will work let's go ahead and do that and there we go we can see that it says success and now if we look at the board we can see that we have an led flashing just before we go i want to mention i do have an a monthly email called the gary explains newsletter which covers everything i'm doing over here on this channel over android authority and anything else that i found interesting from the tech and gadget industry just go over to gary explains.com and sign up there no spam just that newsletter okay so that's it so as i showed there just simply how you can use uh arduino and all these things of course you can use the other frameworks as well i've been using the stm32 cube framework via platform io to program the blue pill to do other stuff so it's really really diverse and yet it handles all of the stuff for you so really really clever talk highly recommended it's not a sponsored video by the way in any way whatsoever i this just wanted to tell you that you know about this tool okay that's it my name is gary sims this is gary explains i really hope you enjoyed this look at platform i o if you did please do give it a thumbs up don't rely on the youtube recommendation algorithm because it's broken instead it's best to just subscribe to the channel hit the bell notification icon and then you'll know every time i release a new video okay that's it i'll see in the next one [Music] you [Music]
Info
Channel: Gary Explains
Views: 43,347
Rating: 4.9578247 out of 5
Keywords: Gary Explains, Tech, Explanation, Tutorial, MBED, STM32Cube, Zephyr, CMSIS, PlatformIO, Arm Cortex, Arm Cortex-M0+, Arm Cortex-M3, microcontroller, Arduino, STM32, MBED OS, ESP32, ESP8266, ESP 32, ESP 8266, Espressif
Id: QMYhVqjBhKQ
Channel Id: undefined
Length: 16min 9sec (969 seconds)
Published: Thu Feb 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.