Getting Started with PlatformIO

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today in the workshop we'll be using platform i o an alternate ide for the arduino and many other microcontrollers i'll show you how to install a news platform i o under visual studio code we'll also build a servo motor controller with an lcd display we're exploring new environments today so welcome to the workshop well hello and welcome to the workshop and today we're going to be programming microcontrollers which of course is something we do quite often over here except instead of using the arduino ide like we normally do we're going to be using a different programming environment something called platform io now platform io itself is not an ide in fact it is a plugin for other ides it can also even be run at the command line and we're going to be running it as a plug-in for a very common ide something called visual studio code now from the name you can probably guess that visual studio code is a microsoft product but this is an open source product from microsoft yes microsoft does indeed make open source products and this is available not only for windows but for linux and mac os x as well so it's pretty well available anywhere that the arduino ide would be available now why would we want to move from the arduino ide after all it's a very familiar environment and it pretty well does the job it has a code editor it has a compiler it has a serial monitor it has a method of managing our different boards and it also has a method of managing libraries well platform io does have all of those features plus a number of other features that can help us write better code that can help us find errors in our code as we are writing them and can even help us solve those errors and as you get more advanced with your coding and write longer code or code that encompasses more than one file you will really see a lot of advantages with platform io over the arduino ide so let's get started and take a look at some of the features of platform io as well as the difference between it and the arduino ide platform io is a cross-platform tool for c plus plus development on embedded devices like microcontrollers it runs as a plug-in in visual studio code and in a number of other ides as well platform io is also available as a command line utility for those who don't require a graphical user interface because it runs under vs code the ide has advanced features and includes debugger platform io is much more capable than the arduino ide but it does have a steeper learning curve today we're going to make several comparisons between the arduino ide and platform io but before we do it's a good idea to review exactly what an ide is we'll begin by reviewing the process of taking data from a computer and loading it onto a microcontroller we start by using some sort of an editor to write some code this is human readable code and we're usually using a simple text editor to create this after this our code needs to be sent to a device called a compiler the compiler takes a text file and produces machine readable code and this code is sent to the target microcontroller an integrated development environment or ide can have several features it requires some form of a code editor to enter code many ides have syntax highlighters to make the code easier to read another nice feature is autocomplete this lets you start typing in code and having the editor complete it for you a debugger is a very handy device to use when your code doesn't work the way that you think it should this is a more advanced feature and not all ides contain a debugger a compiler is an essential part of the ide as we just saw the compiler takes the text file you've written and turns it into machine readable code when working with microcontrollers it is essential that our ide has an uploader this component takes the compiled code and transfers it to the target device a library manager is a very handy feature it allows you to manage code libraries additional pieces of code for working with specific devices version control is also a very advanced feature this allows you to maintain records of different versions of your code and revert to them if necessary when working with microcontrollers a serial monitor is a very handy feature to have another handy feature when working with microcontrollers is a board manager this allows you to work with several different types of microcontrollers instead of just one now the arduino ide has many of these functions built in platform io has all of these functions we're going to be running platform io as a visual studio code plugin which is the most common method of running it microsoft visual studio code or vs code is an open source product it's available for all major platforms linux windows and mac os x we'll also require python 3.5 or higher to use platform io in order to get started our first step would be to install visual studio code on our operating system and then install the platform i o plugin so let's move on and do exactly that so the first step in getting platform i o is to install visual studio code you're also going to need a python environment that is at least python 3.5 in order to run platform io so what we're going to do right now is we're going to install visual studio code and python under linux under mac os x and under windows and after that i will show you how you can install the platform i o extension under visual studio code so let's get started there are a couple of different methods you can employ in order to install visual studio code under linux one of the methods was one that i illustrated a couple of weeks ago in the video that i did on building a linux workstation and you'll find it at the 52 minute and two second point of that video with that method i used the snapstore and installed a snap package since that runs in a virtual environment i also had to install a python virtual environment another method that doesn't require the virtual environment is to install it directly from the installation files available on the visual studio code website you will need to find out first though if your version of python is at least version 3.5 so go to your command prompt on the terminal and type in python 3 space slash version if the version that comes back is over 3.5 then you can just go ahead and use the installation file from the website download the appropriate installation file for your build of linux if it's ubuntu or debian you want to install the deb file once the file has been downloaded you can open it and this will invoke the installer if you're using ubuntu just click the install button and authenticate with your password and that's basically it the installation program will install visual studio on your linux machine once the installation is complete you can open visual studio code the installation of visual studio code on mac os x is extremely simple you begin by going to the visual studio web page and downloading the latest version of visual studio for the mac once it's been downloaded you can go into your downloads folder and you should see the visual studio code file you can actually run it directly from there although it's probably smarter to drag it into your applications folder the first time you run it you're going to have to allow it to run as it's a file that's been downloaded from the internet and that completes the installation of visual studio code however in order to install platform i o we are also going to need to upgrade our version of python in order to install python we'll need to go to the python web page at python.org and download the latest version of python for the mac os x once we've downloaded that we can go and open the package that we've downloaded you'll have to hit continue a number of times on the installation screen and you'll need to accept the license agreement you'll also need to provide your password before you install the software once python has been installed you can close the installation utility you also have the option to move the install files to the trash and i recommend you do that in order to verify your installation open the terminal and use the same command we used in linux python3 space dash dash version as long as the version is higher than 3.5 then you're ready to install platform i o under visual studio the installation of visual studio code under microsoft windows is also quite simple to begin you'll need to go to the visual studio code website and download the latest version of vs code for windows once it's been downloaded go into your download directory and click on the file to start the installation process you will need to accept the license agreement accept or change the path for the installation and accept or change the start menu folder item it's very important to make certain that add to path has been checked off on the select additional tasks menu you can also select some of the other tasks as well if you wish now you're ready to install and the installation will proceed once the installation is done you can click the finish button to launch visual studio code but we're not done yet you're also going to need to install a version of python for windows go to the python.org website and download the latest version of python for windows you might note that on some computers you will need to use a 32 as opposed to a 64-bit version of python and that's fine that'll work with platform i o just as well make certain to check add python to path at the bottom this is very important then click install now and allow changes your to your device to be made the installation will then proceed once python has been installed you can open up visual studio code and we can begin to install platform io once you've installed visual studio you'll need to install platform i o and the procedure is the same no matter what your operating system is i'm showing it here for windows but you'll do the exact same thing for linux or osx go to the extensions button and open it up and then start searching for platform io you'll see the platform io ide click the install button to begin the installation the installation of platform i o can take a bit of time as it has to download several components be patient and don't do anything else in visual studio code while platform io is being you can observe the progress of your platform i o installation in the bottom corner of the screen once platform i o has been installed you will need to restart visual studio code so close vs code and open it up again every time you open visual studio code it needs to activate its extensions and it will check to make certain that you have the latest version of platform i o once it's completed that you will notice the platform i o icon on the left hand side you can click on this to open platform i o you can also use the little home button at the bottom to do the same thing and this completes the installation of platform i o under visual studio code okay so now that we've got platform i o set up let's start to work with it and instead of just using an arduino for our experiments i'm going to use three different microcontrollers to show you how we can move easily from board to board with platform io so i'll be using an arduino uno an esp32 and a c duino shall for our basic demonstrations of the use of platform io so we're on the visual studio code home screen and we're going to begin using platform io and we can call it platform io with this little home button right at the bottom of the screen and this brings up main page for platform io the home page now we'll take a look at this in a moment but first of all let's take a look at some of these icons down the side here now projects will indicate all the projects that we've worked on since we're just getting started we have no projects in here everything we build with platform io is called a project inspect allows us to inspect the individual projects determine what environment they're running in inspect the amount of memory they're running and also check the code in them libraries of course is a method of managing the different libraries in platform io and we'll be talking about libraries a little later on in this video boards indicates all the different boards that platform io is capable of supporting and there are over 900 of these boards right now so there are an extensive number of microcontrollers we can use with this platforms is something that probably will not be relevant to us it allows us to work with different platforms including the atmel avr which is the main one that we're going to be working with right now and work with them on different versions of platform io running under different ides devices indicates the devices that are attached to our computer and you can see i have one here right now because i have an arduino uno attached to one of my usb ports and it's already determined this so i don't need to manually put that in that's a very nice feature let's go back to the home page right now and let's start a new project and we're going to give our project a name and i called it arduino blank test so you can sort of guess what i'm going to do here now we can select the board that we've got attached to here now there's 937 available and we could scroll through the list but it's much easier just to start typing and then arduino uno has been found over here the framework is the arduino framework and we'll hit finish now this can take a few moments when you're first starting platform io because it needs to load a number of files the first time and it has now loaded it you'll notice over here we now have arduino blink test on the side including a number of different directories now we want to go to the src or source directory and we'll see a file called main.cpp and this is one way that platform io differs from the arduino ide in the arduino ide our files have a dot ino extension and platform io we use the dot cpp extension and that is for c plus plus the language we are programming in and our and our primary file is always by default named main.cpp so let's click on it to open it in the editor and here's our file in the editor now one thing you'll notice is that we have a blank file the same that we do when we start off an arduino blank file with one major difference and it's this include statement at the top we need to include the arduino library and this is true for all arduino code that we are going to write and so let's paste in some code that we can use over here and here is basically our blink sketch and the blink sketch of course really doesn't need much of an introduction in the setup we just set our pin as an output and we're going to be using the built-in led so we use the constant led built-in which will work with an arduino uno but not all boards and then in the loop we set the led high and we delay for a second then we set it low and delay for a second i'm sure you're familiar with the blink sketch now when we want to compile this we can hit this little check box at the at the bottom over here and the compilation happens and it says it's successful the code is good and right next to it we have an arrow and we can use that to load that to our arduino and success it has been loaded to the arduino and if we look at our arduino we can see indeed that the built-in led is flashing which is really quite phenomenal of course now let's go and repeat this experiment but let's use a different board so i've replaced the arduino uno with an esp32 board and i'm back in platform io on the home screen and you can always get to the home screen again with that button at the bottom over here now you'll notice that in my recent projects you'll see the arduino uno and you'll also see it on the explorer pane on the side of the screen so i can still jump back to that project and i still have the editor for that open up over here as well so you can work on more than one project simultaneously with platform io now i'm going to start a new project for my esp32 so i'll click new project and we'll give it a name and we'll need to find the board and of course i'm looking for an esp32 board and there are a number of them to choose from now there's one down here expressive esp32 dev module that'll work for many esp32 boards and i'm assuming it's going to work for mine i'll hit finish and it needs to build up the project first and then i've got my esp32 board down over here so i can go into source and open the main cpp and this is the main file for the esp32 board now you'll notice it starts off the same and you'll also notice that despite being an esp32 it includes the arduino library because we're still using the arduino framework in order to build our project so i'm going to paste our project into here and it's the exact same blink sketch and so now i'm going to go and hit the build button down over here to compile it and you'll notice that it failed i got an error and if you can see that i'm sorry the text is rather small it tells me that led built-in was not declared in this scope and that is correct because led built-in is not a constant that is used on the esp-32 board also it is not on pin 13 so i'll unremark this statement over here and i'll change it to another pin number and we'll give that another try and that was successful so now let's upload that to our esp32 and again you'll notice that i didn't have to tell it what port number that the device was on and it was successful and if you look you can see my esp32 is blinking away and the blink sketch has worked so now i've replaced my processor with another one this time i see duino shao and we're going to go and basically do the same thing with the xiao but we'll spruce it up a little bit because the blank test is getting a bit boring but first of all i don't see my platform i o main menu so what am i going to do well over here in the side you will see an icon for platform io and if i click this i get quick access you'll notice it down over here and if i click on open i can get to that same main screen so i'll click new project i'll give it a name and i'll select the board i'm going to type in shao and i have to see duino shall over here and again it's using the arduino framework so i'm going to hit finish now when you first do this you'll probably have to wait a moment while it loads some libraries because my editor has seen the show before it's already done that so i can see my c duino shall blink test down over here i can hit the src and open main.cpp and here's main.cpp and again it's using the arduino framework so that needs to be here and i'll paste my blank code into it now let's spruce up this code a little bit because blinking an led is getting to be kind of boring so what we're going to do is we're going to add the serial monitor in so first i need to do that in setup i'm going to start typing and you'll notice that it started suggesting things and here is serial so serial dot and it also suggests begin and i know i need a bracket over here and it's telling me what i need in it so this is a wonderful feature of platform io it'll actually show you what it needs and it helps you write better code and it stops you from making very common errors i'll give it a baud rate and i know i need a semicolon at the end and so now let's actually print something so we'll go after we set the led high it's knows i need serial dot and i can go down and find print and i want to do a print lin because i want it to also have a carriage return at the end and then i know i need a bracket and it knows i need something to print and i'm going to do double quotes and you'll notice it put two double quotes there and it put my cursor in the middle which is again very handy and i'm just going to print out the status of it which is high incidentally on the c duino shell high turns the led off and low turns it on it's backwards from the other ones and i'll take that line and i'll just copy that and i'll paste it down over here and change the text on that to that there okay so now that should print out to the serial monitor so first of all let's do a build make sure i'm okay and it's successful and so let's load that up to our arduino to our excuse me i see we know and you'll notice that the show is indeed blinking its led which is what we would hope it would do however i also used a serial monitor and i'm not seeing that well if you go to the bottom taskbar you will see a little icon that looks like a plug and that's the serial monitor and it'll change your terminal to a serial monitor and so here we are low high low high we are seeing the output of the serial monitor down here so this illustrates both the auto complete and the suggest in platform io as well as the use of the serial monitor and so you've probably noticed that we're no longer in platform io we are back in the arduino ide and the reason for this is i want to show you a couple of differences between the arduino ide and platform io and the way that they process code and i've created another sketch now this is sort of a better blink i'm calling it blink with function and what i've done is i've moved the blink utility into its own function so the sketch is pretty simple we define our led and we're going to call it led pin and of course it's on pin 13 because it's the built-in one and then in the setup we're going to initialize that as an output all of that pretty straightforward now before we look at the loop let's go and take a look at the function i've created and i've called my function blink led and it has two input parameters both of them integers one of them is the led that we're actually going to be blinking so in other words the pin number and the other one is the delay time in milliseconds and so in the function you can see everything's pretty simple it's really the blink sketch all over again we're going to do a digital write to the led and we're going to send it high and we're going to delay it by the delay time we specify up here and then we're going to go through and do the same thing by setting it low and going through the delay time so now back into our loop and we're going to make this a little more interesting because it's getting a bit boring just watching an led flash at a steady rate so we're going to first of all blink it six times for half second intervals so i put in a for loop over here and within the for loop i've got my function blink led i send it the parameter of the led which i've defined as led pin and 500 which is 500 milliseconds or half a second and then after i finish doing that i'm going to do the same thing but we're going to do it three times for a two second interval so again i have another for loop over here and i call my function blink led and this time i pass it 2000 because that'll be 2000 milliseconds or two seconds so again it's a pretty simple sketch let's go and upload it to the arduino and make certain that it works and we're done uploading and there we go blinking quickly and then a slow two second blink and then the loop repeats itself so this works properly now what i'm going to do is i'm going to clear that out of the arduino and this is easy way to do it just open a new file a blank file and upload that to your arduino and you'll notice it stopped blinking because it basically cleared out the code so now we can try this out on platform io and see if we get the same results and we're back in platform io and i've created a new project for my blink with function sketch and it is identical to the one i used in the arduino ide with the exception of the one include up here for the arduino library which is required in platform io so it should simply be a matter of building this and then uploading it so let's just go and do a build and it failed something was wrong with this build over here now what could the problem have been and the problem is over here is that it says blink led was not defined in this scope in other words my function blink led has not been defined it ran across it over here and it said what's blink led i don't know what that is well we can see obviously that i've created a function called blink led but the problem here is the sequence i've created it in i put it after the loop and in platform io you need to define all of your functions before you actually use them in the code now in defense of platform io this is pretty common for just about every ide the arduino ide is a bit of an exception and that will allow you to define functions after you've used it and it'll figure out what you want to do but in platform io you have to be a little stricter with the way you write code so this is actually forcing me to write better code so i'm just going to go here and cut that and i'm going to put that right before my setup over here and now let's see if that will compile and that's successful and i can upload that successfully to the arduino and as you can see the arduino is now doing its fancy blink function it's fast one and now it's slow one and so that's something to be learned is that you need to define all of your functions in platform io before you actually use them now one of the most important things that we need to be able to do when we're coding for microcontrollers is to manage libraries libraries are additional pieces of code that are used when we're using different io devices so for example if we get a special sensor we can find a library to use to add additional functions to our code to work with that sensor now both the arduino ide and platform io have a library manager and both of them have access to thousands and thousands of libraries but the way that we handle libraries and platform io is a bit different than the way it's done in the arduino ide and as you'll see it does have a few advantages over the method we used with the arduino ide so let's go and take a look at how we do that and then we'll build a little project that is going to require a couple of libraries and we'll see how we use it with platform io the platform io registry has over 10 000 libraries to choose from it includes libraries from sources like git hd and svn subversion it has a very advanced library search feature that allows you to search by the library name by the file name or the name of the component that the library supports most of the libraries are very well documented and they include example code when using the arduino framework you have access to all of the arduino built-in libraries platform io libraries work a bit differently than libraries in the arduino ide here we have the arduino ide and four sketches we'll import a library into one of our sketches that library then becomes available to every one of our sketches if we update our library to a newer version all four sketches will obtain the newer version this can sometimes cause problems with sketches that were dependent upon the older version it also creates issues if you import a library that has the same name as the current library and this is a situation that sometimes occurs now with platform io you do have the option of importing libraries in the same way the arduino does allowing them to be available for all of your projects however you can also import libraries just for specific projects in this case we have a library being imported for project number one and project number three now we've updated the library for project number one and we've also added that library to project number four note the project number three we haven't chosen to update and it remains at the old version of the library by having libraries on a per-project basis you have a lot more flexibility and control with platform io the parameters for your platform io project including the libraries that it depends upon are stored in a file called platformio.ini and we'll be taking a look at that file in a few moments so now we'll build a project to illustrate how to use platform io libraries now for our library demonstration project you're going to require an arduino uno a pca 9685 16 channel servo motor controller a liquid crystal display with an i2c backpack on it a 5 to 6 volt power supply capable of powering a couple of servo motors two potentiometers i used a couple of 10k linear taper pots and a couple of servo motors i used two sg90s we'll begin by connecting the five volt output of the arduino to one side of each of the pots the arduino's ground output is connected to the other side of the potentiometers we'll connect analog pin a0 to the wiper of one of the pots and analog pin a1 to the wiper of the second one we'll connect the ground to the ground connection on the i2c backpack for the lcd display we'll connect 5 volts to the vcc connection on the same display analog pin a4 is connected to the sda connection on the i2c backpack on the display and analog pin a5 is connected to the scl connection we'll also connect analog pin a4 to the sda connection on the pca 9685 and pin a5 will be connected to the scl connection we'll connect 5 volts to the vcc connection on the pca 9685 notice that we're using the vcc connection and not the v plus connection which is a connection for power to the servo motors and the ground will be connected to the ground connection on the servo module we'll connect the 5 to 6 volt dc power supply to the servo power input on the pca 9685 please note the polarity here and finally we'll plug our two servo motors in to ports number zero and one on the pca 9685 and this completes the wiring of our test circuit now let's go and take a look at the code so i'm back in platform io and i've already created a new project that i am calling servo motor demo and i've got the main.cpp file and i've entered my code into it and i want to show you a few things about using the code editor now there's a feature on the side here which is actually a feature of visual studio code and this is a minified version of my code now my code is fairly long but i can skip the different parts of the code just by going up and down this so this makes it a little easier to navigate now you'll notice i've got a couple of red lines up over here and the red lines are the equivalent of these squiggly lines you see under these two statements and these are the statements that call up my libraries and if i highlight these you'll see what the problem it is it says i cannot open source file liquid crystal and that is because i haven't installed the library and the same is true for this adafruit pwm library over here you'll notice that the include on the arduino library doesn't have a squiggle because it's there nor is there an include on the wire library because that is a built-in library of the arduino and so that is included in every platform io program that uses the arduino avr so what i need to do is i need to install this library let's go and install this one first this liquid crystal one i'm going to copy its name right now and then go into the platform io home and go into libraries and i'm going to paste the name into the search box and i'll hit the search button and there's my library down over here and i'm going to click on it and you'll notice what i get with the library i get all of this example code over here that shows me how to use the library i also get installation instructions over here i get the headers for the library and i get any change logs that happen to show all the different releases of the library so let's go and add this library into our project i'll click the add to project button i'll select the project and i'm going to use the servo motor demo which happens to be the first one on the list because it's my most recent project i'll click the add button and it congratulates me i've added the library to my project now i have a second library and that was the adafruit pwm servo driver rather than copy its name i'm just going to do it free form adafruit pwm servo should be enough and there it is over here and again i can add that one to my project as well select the project and add the library and again i'm congratulated because it's there now if i go into main.cpp you'll see the squiggly lines are gone and the red lines are gone on my minified because i've got them there now if we go into platform io you'll notice that when you highlight specific things you will get information so for example over here if i highlight it tells you exactly what this is a class that stores a statement functions for interacting with the pca 9685 pwm kit it also memorizes all the variables and constants that you've made so for example over here in this statement i'm using two constants i defined min pulse width and max pulse width if i highlight them it'll tell me what the values are 650 for this one and 23.50 for this particular one if i go down into something like this one over here set pwm frequency it tells me exactly what it is that's the pwm frequency for the entire chip up to 1.6 kilohertz and if i highlight frequency i'll see i'm setting it to 50 hertz and so you can go through this for pretty well everything in your code and learn what your code does and this is fantastic if you're taking some code you haven't written yourself and you want to modify it and you want to know what these things do or if you have a long code and you just like to know what the value of a particular variable is now another feature and i'm going to go down over here is when you have things like if or other loops and things inside your code you'll notice there's a line here you may have some problems seeing it but this shows me what the extent of this if statement is it goes from here to here and if i've got nested statements with other if statements or four next statements within it i'll see lines for those as well and you can tell where everything stops and starts you can also highlight the opening bracket and that'll highlight all of this and it highlights the close bracket now mind you highlighting the opening and close bracket is also a feature in the arduino ide now let's go up to the top and just quickly see what this code actually does now we've included all of these libraries at the top and we're going to define the i2c address for our display which we do over here now there's another common address hexadecimal 2 7 that some of these displays use so you may need to change that for yours and then we define an lcd object over here at that address we define a couple of parameters to the pwm object we define the pwm object over here and then we have a couple of things that define what our inputs are these are two integers over here control zero and control one for the parts on a0 and a1 respectively we have integers that represent our two motors motors zero and one and then a couple of integers that represent the degree that the motor is needed to be positioned at so i have degree for motor zero and degree for motor one over here i also define the previous reading of degrees and the reason i do that will become apparent in a few moments and that's also lines in with this boolean i defined to say whether i should update my display or not then i create two functions the first function doesn't have any output so it's just a void in this move motor degree and i have two parameters i put in the amount of degrees i want to move my motor to and the motor that i want to move and then down over here i've defined another function which is get degree and this one actually produces an integer output it's not a void so i input the name of the control that i'm using either a0 or a1 and it'll output the number of degrees and it's just using a map statement over here in order to convert it to 0 to 180. then i go into my setup and this setup i initialized the pulse with modulator controller and i set it at the correct frequency i also set the lcd display up and i set it for a 16 by two display which is what i have i turn on its backlight over here to full intensity i clear the display and i print on the display just to start with and then i set up my serial monitor and note the baud rate that i'm using for this serial monitor 19.2 then i'll go into my loop and the loop is now very simple remember i've defined my functions before the loop or else i will get an error in platform io here i define the position of servo motor 0. so i get the desired position by doing get degree the function i wrote earlier that reads the control and that's the number of degrees i want to move the motor to now i'm only going to move the motor if it's position has changed since the last time the reason i'm doing this is i want to prevent flickering on my lcd display so i don't want to update the display unless i actually have to and so if the motor degree is not equal to the previous one then i'm going to move the motor using my move motor deg function that i wrote earlier i'll update my display so i'll set that parameter to a one instead of a zero that's the boolean i defined earlier and i can highlight that to tell me what that is and then i'll update the previous position to the to this position so the next time i run around i i know the previous position i do the same thing for motor number one and then i go through and update the display only if it's required if update display has indeed have a value of one then i'll clear the display and i'm going to print on the display the values of the motor positions over here and then at the end i'm just going to print out to my serial monitor which prints out the positions of both of the motors and then i'm going to reset that update display variable to zero before i run through the loop again and i'm adding a very short delay to this just to keep the motors from chattering and so that's my sketch what i'm going to do is compile it right now or build it and it builds successfully and i'll update that to my arduino and we will watch it work and so here's my test setup over here as you can see i've got my liquid crystal display and the i2c backpack now i've mounted the backpack on the front of my display which is actually backwards it should really be on the back of the display but i keep it over here because this is just my little experimenter's display and i find it a lot easier if i can get at the backpack on the top now here of course in my two servo motors and here's the pca 9685 i'm using to drive it on this little sawdust breadboard you'll also see the two potentiometers that i'm using in order to control the motors now for my power for the motors i'm just using these four double a cells over here so i've got a six volt battery over here to power it and that's a good power source for servos and of course you can see my arduino uno over here now i've loaded the code so all we need to do is watch it work and i'll twist it and i can move the servos and you see the two servos move and it's written on the display so this is pretty well exactly what we're hoping that it would do so now let's go back in the platform io because as you'll recall i'm also using my serial monitor so let's go down over here and put on the serial monitor and see what we get and what we get is a bunch of gobbledygook at the bottom and the reason of course for getting all of this gobbly is because we have set the serial to 19200 and the serial monitor is still trying to work at 9 600. so we need to be able to correct that and in order to do that it's time to take a look at the platform io dot ini file now as i mentioned in the explainer earlier the platform io.ini file contains all of the parameters specific to the project now before we do that this is getting a bit annoying at the bottom so let's stop the serial monitor which you can do with a control c and then if you hit enter you'll be back into the terminal mode now let's go and take a look at platform io.ini so we'll open up the file over here and this is the configuration file for our particular project and you'll notice a few things about it first of all it tells you what the environment is over here it's the uno the platform is the atmel avr the board is the uno the framework is arduino then it goes and shows you the two library dependencies that we've got so here's the liquid crystal library we added and here's the adafruit library now you can actually put these in manually rather than going through the library installer like i showed you earlier but i find the installer a bit easier now the next thing we need to do is actually tell it that we want to use 19.2 instead of 600 so we do it like this monitor speed and then equals 19200 and then i'm going to do a control s to save everything and we'll go back into main.cpp and let's pull our serial monitor up again and now as you can see the serial monitor is showing what we want and if i move my controls i'll get the readings the same as i had on the liquid crystal and so we've now set it on this particular project to work at 19200 using the platform io dot ini file all right well that brings us to the end of this video about platform io but it's certainly not the last time you're going to see platform i o here in the dronebot workshop going forward i'm going to be using a mixture of both platform i o and the arduino ide for our simpler projects you'll see the arduino ide but for the more advanced ones are the ones that use new microcontrollers i'll be using platform io because as you've seen platform io has a lot of advantages over the arduino ide in terms of writing code now if you want some more information about platform io you can check out the article on the dronebotworkshop.com website and you'll find a link below the video to that article and in that article you'll also find links out to all sorts of resources for both platform io and for visual studio code now if you want to discuss the contents of this video you can certainly leave some comments in the youtube video i love seeing your comments but i don't always have time to answer them and a great place to get a dialogue going is on the dronebot workshop forum and i want to talk to you about a new section that i've just added to the forum this week and that section is a section to discuss all of my videos this was something that was recommended by a forum member and i thought it was a great idea so i've broken them down year by year and there is a post for every single video and you can go into there and discuss this video or a video i did two years ago and that discussion will come right up to the top and other people can get in on it and you can of course add code samples talk about problems you might be having with projects based upon those videos and do a lot more than you could list in the comments for youtube now if you're not a member of the forum it's free to join just follow the link below and get the details for doing that another thing that is free is my newsletter and my newsletter is not a sales letter by any means it's just a way of letting you know what's going on here in the workshop and you'll find the link to the newsletter right below this video and finally if you haven't subscribed yet to the channel please do about 70 of the people who watch these videos are still not subscribers and i'd really love to have you as a subscriber so all you need to do is hit that subscribe button and then hit the bell notification so that you'll be notified every time i make a new video now some folks have told me they've hit the bell and they're still not notified and in that case that is probably because in your settings for youtube you've blocked notifications so make sure you haven't done that so until the next time that we meet take good care of yourselves stay safe and we will see you soon here in the dronebot workshop goodbye for now [Music] you
Info
Channel: DroneBot Workshop
Views: 150,419
Rating: 4.9485817 out of 5
Keywords: platformio, platformio arduino libraries, platformio esp32, platformio serial monitor, platformio vscode, platformio vs arduino ide
Id: JmvMvIphMnY
Channel Id: undefined
Length: 51min 54sec (3114 seconds)
Published: Sat Jan 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.