#264 PlatformIO for Arduino, ESP8266, and ESP32 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
would you like to have a better tool to program your Arduino or ESP boards more productive more flexible but still compatible with all our Arduino sketches and libraries also easy to use let's have a look if platform IO is that tool great see you tubers here is the guy with the Swiss accent with a new episode and fresh ideas around sensors and microcontrollers most of us use the Arduino IDE for our project today we will have a look at platform IO because the new versions are much easier to use it is time for a closer look in this video we will install platform IO and Visual Studio code the open source editor from Microsoft create an Arduino sketch to check if it's more complicated than the Arduino IDE or not have a look at code completion a big time-saver see how real-time syntax check can help us to save time and avoid frustration see the small things which are different from the Arduino IDE use the same code and upload it to different boards like an Arduino Uno and an ESP 32 have a look at the flexible management of libraries and its advantages especially for larger projects discover that more and more projects on github use platform io in the end you should see if it's time to make the step to use platform io for your future projects in video number 240 I asked if it's time to say goodbye to the Arduino IDE and use micro Titan for most of the commenter's micro Payton was not the right choice mainly because it is an interpreted language they thought C++ is better to program microcontrollers but quite a few of them suggested leaving the Arduino IDE for platform IO which seems to be much more comfortable and still uses C++ platform io is a No and source project which deals with the creation of code for multiple platforms and ports it has no built-in editor and in the beginning they used atom this changed over time and now it seems that Visual Studio code also called VSC is widely accepted this is why I will use it for this video as usual I will use Windows 10 but the tools should also be available on Linux and OS X before we start we have to check if we installed the right version of the arduino ide i suggest you install the newest version you find it on the arduino home page do not install the app version it does not work with platform io maybe you take the opportunity to donate a little if you did not so already the installer will ask you if it should remove the old version and installs the new one it takes a while till the latest version is installed now we can go on and install BSC just search V s C install and you find this link click on the desired version and it downloads an installer as usual accept everything and VSC will start next we have to install platform io because it is very tightly integrated this step is straightforward go to this symbol on the left side in vs C and search for platform - IDE then hit install it will take a while till you see the PIO home screen it also recommends installing additional things of course we install the arduino framework support now we are ready to rumble and can start our first project I call it blink Arduino Uno and search for the Arduino Uno board here we choose Arduino because we will use the Arduino framework after pressing finish you will get this structure on the left side of your screen on top is the project name and below a few directories for the moment we open the SRC folder and find a file called main dot CPP this is the first difference between platform IO and the Arduino IDE the main file is always called main dot CPP the extension CPP stands for C++ the programming language of the arduino ide if we open the file we see our standard structure set up and loop nothing new except for the first line we always have to include Arduino dot H let's start now with our blink sketch I will add a few print statements to test serial monitor as soon as we begin to write serial dot begin the auto completion function kicks in all commands which fit the first letters are offered if we hit enter the complete command is already there we could also select another version using the up and down arrows as soon as we enter the opening parentheses it shows us the expected variables do you remember how often we had to Google this information for commands we do not often use with BSC this is a thing of the past cool if we look here we see that main dot CPP is colored red which means our code still has an error in this case it is the missing semicolon at the end of the line as soon as it is entered the file becomes white like that we never start to compile or upload code which has such trivial errors very nice with the Arduino IDE we always lost time until the compiler detected such errors if we continue typing we also see that correct there's like close parentheses are automatically entered very productive we continue with a loop section and set the green LED to low first when we start to write green the auto completion shows us weird things but not the obvious green LED variable we would expect not good why because we forgot to define it another common mistake which steals our time if we discover it too late as soon as we define green LED Auto completion works as expected another typical source of errors is gone and with it also misspelled variable names including small or large caps extremely rewarding after a few more lines the program is finished and we can upload it to our Arduino Uno this is done by these small icons at the bottom of the screen we first hit OK to compile our code the chance it compiles without errors is very high because we were able to correct all errors before the display shows similar things as in the Arduino IDE with verbose switched on it is well possible that our computer behaves a little different because platform io automatically downloads needed components when they are used the first time we could have uploaded the program directly to our uno by pressing the right arrow let's do it now after a few seconds our Arduino starts to blink but we do not see messages in serial we first have to select this clock symbol and we begin to see the messages by the way the comport was automatically selected writing this blink sketch was faster and more fun than with the Arduino IDE and for sure not more complicated let's have a look at what platform iodate in the background we go back to the home screen and see that it automatically installed the Atmel we are platform which is needed to program the you know now we go to an essential place in our directory the platform IO any file each project has its own file where it stores its settings another reason for the power of platform IO currently the file in our project folder does not contain a lot of information only the three lines for our Arduino Uno let's go back to our sketch file and change the serial speed to 19200 after compilation only get rich is displayed in the arduino ide we would have to change the speed of the serial monitor here we go back to platform io dot ini' and add the line monitor underscore speed equals 19,200 if we press control c and start the serial monitor again the terminal runs at 19 200 we can add many things to this any file fortunately there is documentation available what happens if we want to create a function let's put the serial print the digital right and the delay statements in a separate function like that the code is better readable as usual in the arduino ide we add a void function with all the needed parameters at the end of the code the function has the pin the delay and the LED status as input parameters now we can replace the code in the loop it looks much cleaner now but wait we had the excellent ctrl T function in the Arduino IDE to auto format or pretty print our code fortunately it exists here - just press alt shift F and your code looks nice let's upload the new code and check if it does the same thing as the one before unfortunately not the compiler complains and says that show LED was not declared this is clearly fake news as I can prove here I declared it here we have a second difference to the Arduino IDE we have to move all functions to a place before they are used in this case I move it in front of setup now it compiles without errors let's now create to the same project for an ESB 32 we name it blink ESP 32 and choose the expressive def module board which works for most of my devices if we hit finish we only have to wait till platform i/o installed the newest ESP 32 support no more adding of strange JSON files in the Preferences tab of the arduino ide platform io knows what to do we get now our second project folder again with an empty main CPP file we can copy the blink sketch from before into this new main dot CPP you see we still need the Arduino dot H file even if we work with an ESB 32 let's quickly go to platform IO dot any of this project it has a different platform and a different port we also add the monitor speed but since the ESP 32 is fast we use 115200 now let's hit the right arrow and watch what happens it compiles automatically detects the new port and uploads the file the serial monitor displays skittish until we change the speed in the sketch and it automatically dartz the serial monitor after uploading only the LED does not blink if we change green LED to pin 2 also this LED blinks we have now two completely separate projects on the same computer both projects know for which board they were made and we never again have to think about that very good in the days where we have arduino z' esp8266 and ESP 32 projects the same way we could create a project for an 80 tiny or an STM 32 blue pill let's continue with the library management arduino ide keeps all libraries in a central place and you have to install it before you compile your code sometimes we need a different library for the e SP 32 than for the arduino and sometimes libraries are even not backward compatible this is why i prefer to keep the library version which was tested with the project it also simplifies the distribution of software because the next using your code does not need to hassle with installing the libraries you also can copy the project to another computer without any problem platform io supports this concept let's look at an example file from d jason arduino library i created a project with a name uno jason example and try to compile it as expected it does not know the Chasen library and generates an error so we go back to the library manager and search for arduino jason we find a few and chose the common one we can install it here if we want and we get two options either global or with our project but we do not install it right now we go to the installation tab and see the definition string of our dot ini' file we copy it and recompile it now we get tons of errors this is because version six of the library is not backward-compatible we need a version below six to get that we add this small string and compile again now it works cool our project knows now which library it is based on if we go back to the library manager we see that platform io automatically installed the two versions of the library the library files can be distributed with a project if you download a platform or project from github it contains all libraries and you do not need to install them as mentioned before large projects like jaws Mota are more and more developed with platform io why because of the many dependencies they require what is a dependency it is a fundamental concept in modern software design I like this word a lot because it is very precise the TAS motor code depends on 27 different libraries most of us do not have all these libraries installed in our Arduino IDE you can imagine the nightmare without platform io you would have to install all 27 libraries one after the other and because each of these libraries gets updated from time to time our version would be different from the one used by the developers to prevent that the authors of Tata did a good job and fixed all libraries to a particular version they tested this project with these libraries a true quality improvement platform io has another fundamental feature which is not free of charge inline debugging maybe you will see once a video about that in the future for now let's summarize platform io together with Visual Studio code is an excellent alternative for the Arduino IDE automatic code completion as well as error checking before compilation is a productivity booster more and more of us do not develop only for one board platform io with its encapsulation concept is a perfect solution for that problem we can use all we have learned with the Arduino IDE we even can if we want import our projects and our valuable and trusted Arduino libraries also work the only two things we have to remember is to add include Arduino dot H at the beginning of all projects and to place the functions before they are cold because a lot is streamlined now the effort for the transition between Arduino IDE and platform IO is minimal it is also an advantage to no platform IO because many larger projects are already built using it it is well possible that I too will start to deliver some of my projects in this way one last thing if we look at the dot ini' file of the task motor project you see the possibilities today we only scratched at the surface of these options I hope this video was useful or at least interesting for you if true please consider supporting the channel to secure its future existence you find the links in the description thank you bye you
Info
Channel: Andreas Spiess
Views: 240,391
Rating: undefined out of 5
Keywords: arduino, arduino project, beginners, diy, do-it-yourself, eevblog, electronics, esp32, esp32 datasheet, esp32 project, esp32 tutorial, esp32 weather station, esp8266, esp8266 datasheet, esp8266 project, greatscott, guide, hack, hobby, how to, iot, lorawan, nodemcu, project, simple, smart home, ttgo, wemos, wifi, Platformio, platformio get started, platformio tutorial, arduino platformio, esp8266 platformio, tasmota platformio, esp32 platformio, platformio project, platformio, andreas spiess
Id: 0poh_2rBq7E
Channel Id: undefined
Length: 18min 46sec (1126 seconds)
Published: Sun Apr 14 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.