Using PlatformIO with ESP32

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
g'day so I'm gonna go over using platform IO in this video I sort of got here because I wanted to upgrade the audio I'm using for my remote ham receiver I have been having trouble with using uh Bumble on a Raspberry Pi so I think this might work better if I just have dedicated streaming audio going from a esp32 microcontroller to do that I need to sort of change it around my whole tool chain so I'm going to be using platform IO to do that that's going to run on Visual Studio code uh and then I'll be coding in C C plus plus and deploying that to the esp32 so I have a quick look at setting it up some examples of how to use it maybe a quick look at how I plan to code for the streaming audio and then leave the rest for a follow-up video after that here's a quick look at how to get platform i o installed there's some good instructions out on the platform IO site so first you install Visual Studio code open the extensions and visual studio code then you search for platform i o IDE and then you can just click on install and wait it takes a while to do the first install so there's good instructions for installing visual studio and the visual studio page so here's a quick look at it getting a platformer i o installed so like I said once you've got Visual Studio code installed then you can go into the extensions search for platform i o there it is hit install this first bit takes about five minutes to install everything just sit tight Let It Go through wait till it finishes and do a Reload when it tells you at the end so basically we've got to install the I'll just show you how to get the first uh project going as well uh the first project will take a long time next time you install project using the same framework it'll go really fast so uh so go into platform IO home and I click on new project when you do this it's going to ask you details about the new project so give it a name for my ones I'm just going to start them off with p i o to identify them as platform IO projects this first one is Pio demo then you select the board you're going to use and you can use a Doritos blue pearls esp32s Pi Picos all sorts of things so just search for the one you want to use I'm just going to use kind of a generic esp32 for this first project and by selecting this this is going to download the the board and the libraries it needs for that board so that's why this first project always takes a long time to get set up first time so let me select this one here that just the espresso Dev module select the framework I'm going to use Arduino so again that's going to be part of the libraries that get downloaded it takes a while and then thing I do differently from kind of the defaulters I put all my projects and I see projects directory so I'm going to continue to do that so I'm going to set that as the initial directory for this project I'm making as well and Let It Go so let this run like I said the first time you do this can take a while to load all the libraries especially if you don't have Arduino and loaded so this one took me about 12 minutes after that it's a lot faster then when it's finished you just say you trust that folder if you haven't said it before and there we see the new project so let's have a look at what uh platform i o gives you as the basic project structure when you start a new project uh so it has an include folder and the nice thing is they have readme Files about what each of these folders are used for so it includes to add your own location for your own custom headers lib files for where you've created files of libraries just for your project and they give you the suggests uh structure for the use of those folders as well in the readme our source is where your C plus sources and because I selected Arduino as my my framework it set me up with these two routines which are the common Arduino ones in my main CPP folder so I put what I want to happen initially at first inside the setup uh function here and then anything that I want to happen repeatedly afterwards in the loop function so that's just like uh Arduino IDE the only thing they do include is that Arduino header you won't see that in the Arduino IDE but it's included in here there's a folder for in a unit tests you put together uh the good ignore is there for basic things that you want to ignore for forget and this platform and he's uh something that you'll probably use a lot so when you do select the the board and the framework uh that's put into an environment setting in the platformin io and the platform any sorry platform any is used to configure anything specific about your project for a particular platform and see because I S selected a fairly generic esp32 board it select the platform has just been here expressive 32 boards esp32 Dev and framework as Arduino because I selected Arduino framework what you do find is if you want to add to this additional boards to this project you can um go in and add those in and there'll be another environment in here so this can actually compile for multiple environments from the same set of source so you could have the same program being say used on esp32 on a Pico uh Pi Pico Arduino uh uh stm32 blue pill uh as long as the code's compatible then by targeting the different platforms it'll bring the specific libraries and things in for that board and you can compile either for all those at once so if you're trying to build for a lot of boards at the same time you can do that or if you just want to be able to swap between the different environments or different boards you can just select compile and builds for those specific built boards when you do it so let's have a look at the adding a blinking LED program for my esp32 and this is kind of the hello world of the embedded controller World um so wow best way I found on getting started on this is go to Docs go into Frameworks I'm using Arduino framework run down see there's examples there and I'm going to choose a set of examples Arduino for expressive 32 I think that's what I'm working with and here the nice thing is it gives a whole bunch of uh example code that's out in uh GitHub for you to use and I'm going to try this one here Arduino blink and there's quite a lot of examples out there so if I go to source blink CPP so this shows me what I should be putting in my case into the main folder so let me just uh let's get a copy of that I'll bring up my project and I'm just going to replace all this code with what I just copied and this should all work the only thing to look out for is uh the built-in LED uh may not have the correct i o for my particular board but we'll try it out if if not then we'll dig into why it's not uh some of the nice things about using platform I O with visual Studios is you can do things like Let Me Show an example here so I want to set up the serial serial uh port so code complete for me and let me set it to 9600 board it'll show me errors where I'm in this case missing something like a semicolon and also down here from this loophole again use cereal use code complete like so when I enter a full stop but ask me what I want to do so I want to do a print line and just put a comment here now until I put the semicolon in there so it's nice code completion automatic uh visual error detection is all good so let me save that code and uh I have an esp32 plugged in at the moment to my computer uh so one of the nice things it does is automatically detects if you have the board attached and knows that's your target so let's do a compile first hopefully this goes through without errors uh the first compile usually on a new build uh can take a while well it brings in libraries and things this one didn't take too long a lot of the library's already compiled I've done this a few times so six seconds and uh looks like I don't have any errors there so I'm going to use this to upload it to the the board so hopefully this will go out to the esp32 and start it blinking so that's automatically connecting uploading and we see it blinking which is good now let's see if that my serial statements work as well so it should be printing out this blink word every time it goes through a blink cycle and the way you start up the serial monitor is this icon here and there we see it's calling the Uplink so that's connecting to the serial port at 9600 board at the moment you can increase that higher rate but if you do you need to change the platform IO any file to set the serial monitor to the the new rate because by default it's in 9600 as well so that's another use for the platformer IO any file is to set up things like that another nice integration that is useful for me is the source control so if I go to Source control at the moment I haven't got uh git set up for for this uh so I can either just initialize the repository which will make the local git repository or I can set that up and publish to my GitHub uh repository at the same time so let's call this poi demo one uh so it already knows about my GitHub repository because I'm signed in uh I'll just do this as a private repository just to demonstrate looks good hit that and that should be it so let me bring up my browser and you see how out in GitHub now uh platform IO and that whole project is now up as a GitHub repository and now I can make sure I've got Source control working on anything I'm doing in this project so let's have a look at another way of uh using the examples uh so I'm going to go to the platform i o home I clicked on the home icon and in this case I'm going to use the project examples instead so I'm going to select an example I'm going to use express if for example this case I'm going to do a Wi-Fi scan and I can do a import which will bring that whole project in I trust the author and we should be ready to go so the difference with this project you see here is the platform any has actually been set up to support multiple boards and I can do a compile and it'll actually compile for all these different boards but if I just want to focus on one board the one I've got connected at the moment I'm going to go with this one here which is kind of the generic version should be ready to go so let's do a bit build okay I'll show you one more thing in the platform any here you'll see there's another use of for the platform many is to set the monitor speed so you remember in the last example is 9600 board now put it up to a higher speed and that's because in the source it's using the higher speed for the serial interface so what this should do is fire up and then scan for Wi-Fi connections that are nearby so let's do the deploy this time connecting to the my device that's on com6 which you'd automatically recognized it was there foreign should be deployed let me bring up the terminal and we'll see if it's working so starting the scan and found all these Wi-Fi networks which are around my house here uh just a note because of an esp32 it's only finding uh the 2.4 gig uh Wi-Fi networks so it's much shorter less than probably really is here right looks like that's working successfully so that's another way of using examples okay I just wanted to go over why I'm using C plus plus instead of normally I'm using micro python on microcontrollers and it's mainly because I'm doing a sound application and I really need the precise timing uh that the C plus gives you a micro python can have things happening in the background that you're not expecting like garbage collections uh also the because it's a higher level language it's usually calling functions to do a lot of what it does so it's not so close to the metal so you're never quite sure you know what the timing for those functions are so that's why I swapped over to C plus plus for this particular application where I want to start streaming audio from my ham radio so I'm going to start with my blink application here and just show you how I can cut it down and get some some square waves out of the esp32 so first I'm going to clear out some of the stuff I don't need so instead of using the LED as the output I'm gonna Define sound as pin 13. I'm not going to use cereal but going to initialize the pin 13 for output uh don't need this serial out there and same thing I'm gonna quickly uh flip from low to high to get the square wave but to do that at increased speed I'm going to use delay micro seconds let's do about five see how that goes same here on the other side good okay no errors let's compile that first and let's deploy it and for this particular here's p32 I need to hit the boot Button there it goes it's uh downloading the program and we can see on the oscilloscope here that we're getting a square wave output let me see if I can change the the time base for that so that's a better view of the square wave coming out and you see it's actually running at 84 kilohertz so that's pretty fast and uh it's probably a bit faster than this little oscilloscope can uh keep track of but you can see how we get uh commanded sound with C plus plus pretty well um so that's about it for this video um so I've got platform IO going so I've really got my C plus plus tool chain to an esp32 all set up uh so uh next video that's where I'm going to get into some of the C plus plus coding for doing audio basically I want to do like a wireless um microphone type type thing there's some good examples out there of put a link to a one good YouTube video about you putting out esp32 walkie-talkie together which will be part of the basis for this there's also some esp32 sound libraries that are probably going to be useful as well so I'm going to dig into that for a while learn a bit more C plus plus coding in the next video I should be able to wrap up and get some audio streaming going to and from my USB 32.
Info
Channel: LupinCorp
Views: 2,869
Rating: undefined out of 5
Keywords: Lupincorp, esp32, PlatformIO, C++
Id: vIOptOBHdR8
Channel Id: undefined
Length: 20min 3sec (1203 seconds)
Published: Wed Jan 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.