How to Set Up a Project in Visual Studio Code for the Pi Pico - Blink LED

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so after you've set up your visual studio code environment as shown in my previous video linked in the cards above you're going to want to set up and create your own project this video will show you how to do just that and as an example we will write our own blink led code as usual the source files will be available from my website linked in the description as the prerequisite to this video it is really important that you set up the entire tool chain correctly as shown in the video i just mentioned otherwise this process won't work properly also if this video or any others have helped you please do consider liking the video and subscribing to get notified of more pico tutorials that i make so to begin with we need to create a folder for our project i'm going to make one next to our pico sdk installation folder and call it pico projects the first thing you need to do is navigate to the pico examples we downloaded previously and copy the pico sdk import cmake file into your new project folder now open a developer command prompt by using the windows search then open visual studio code using the code command with visual studio code now open navigate to your project folder and open it we now need to create two files firstly the configuration file for cmake which is a text file titled cmakelists.txt and we also need to create our c file which will contain our project code i will call this blink led in order for the compiler to know what to do with our files we need to write some commands in the cmakelists.txt file we created to start with we need to tell it what version of cmake it should expect which in our case is 3.12 we do this by using the command c make minimum version next we need to include the file we copied into our project directory simply do this with the include command now cmake wants to know what project this is for so i use the project command and enter pico projects now we initialize the pico sdk and then add our c file as the executable using the add execute executable command with the arguments blink led then blink led dot c in our c file we are going to use the standard pico library and so we need to include this here with the target linked libraries command to link the library that we want to use to the blink led file finally we need to tell the compiler to build the files which are suitable for programming the pico and we do this by using the pico add extra outputs command you can now save this file and close it if you wish we now need to initialize this configuration that we've just made and we do this simply by going to the terminal then configure tasks you should now see the gcc for arm compiler selected in the bottom left if you haven't if you don't see this now then you just simply press that button where i've highlighted in red and select it the output window is actually telling me i've made a typo but when corrected you should see that the configuration is complete we can now write some code in our c file this is going to be a very straightforward example program and you can write whatever you want in here but we will simply blink the green led on the pico on and off it's about half second intervals firstly let's include our pico standard library just as a note that if you want to make it if you want to include any of the other pico libraries you'll have to add them to the target in the cmake lists file moving on we need to initialize the pin which is connected to the onboard led this is pin number 25 using the gpio gpio inits function with the pin number as its argument next we set this pin to output mode using the gpio set direction function with its arguments being the pin number defined and then gpio out to keep the program running indefinitely we're going to use an infinite while loop then in this loop we're going to turn the leds on with the gpio put function to set the pin 25 to 1 which indicates a high voltage and then use the sleep ms function to implement a 500 millisecond delay to turn off the leds simply copy the code again and change the one to a zero in the gpio put function now we are ready to build the project press the build button on the bottom taskbar and you should see it build without errors if you open the build directory with windows explorer you'll see the blink led uf2 file that we will use to program the pico now let's check if the blink led works as intended connect your pico over usb whilst pressing its boot select button simply drag and drop the uf2 file over to the pico storage it should reboot and start blinking hopefully this video has helped you create your first visual studio code program for the pico if you have any comments please leave them down below thank you for watching and if this video has been helpful then please consider liking and subscribing
Info
Channel: Learn Embedded Systems
Views: 32,508
Rating: undefined out of 5
Keywords:
Id: Q1Kfg8k54jM
Channel Id: undefined
Length: 6min 31sec (391 seconds)
Published: Wed Jan 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.