{"id":3535,"date":"2022-09-02T12:34:33","date_gmt":"2022-09-02T11:34:33","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=3535"},"modified":"2026-06-17T09:15:25","modified_gmt":"2026-06-17T08:15:25","slug":"setting-up-visual-studio-code-2","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/microcontrollers\/programming-in-c-c\/compilers-and-ides-programming-in-c-c\/visual-studio-code\/setting-up-visual-studio-code-2","title":{"rendered":"Creating a Visual Studio Code project"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Create a new project<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><em>As you follow these steps for the first time after install, Visual Studio may prompt you to do various setup things &#8211; when it does just click the default option it is asking you.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click top left &#8220;Explorer&#8221; button &gt; Open Folder<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a folder somewhere you want to store your project and open it<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Create main.c<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Menu &gt; File &gt; New File <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Menu &gt; File &gt; Save As &gt; &#8220;main.c&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Paste this code into the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"pico\/stdlib.h\"\n\n\n#ifndef PICO_DEFAULT_LED_PIN\n\t#warning This example requires a board with a default LED\n#endif\n\n\/\/***********************************\n\/\/***********************************\n\/\/********** MAIN FUNCTION **********\n\/\/***********************************\n\/\/***********************************\nint main()\n{\n\t\/\/----- SETUP PINS -----\n\tconst uint IO_LED = PICO_DEFAULT_LED_PIN;\n\tgpio_init(IO_LED);\n\tgpio_set_dir(IO_LED, GPIO_OUT);\n\n\n\t\/\/---------------------\n\t\/\/---------------------\n\t\/\/----- MAIN LOOP -----\n\t\/\/---------------------\n\t\/\/---------------------\n\twhile (true)\n\t{\n\t\tgpio_put(IO_LED, 1);\n\t\tsleep_ms(200);\n\t\tgpio_put(IO_LED, 0);\n\t\tsleep_ms(200);\n\t}\n\n}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Create CMakeLists.txt<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The C\/C++ SDK of Raspberry Pi Pico uses the CMake build automation tool which needs us to create &#8220;CMakeLists.txt&#8221;, containing the instructions describing the project sources files and targets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Menu &gt; File &gt; New File <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Menu &gt; File &gt; Save As &gt; &#8220;CMakeLists.txt&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Paste this code into the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Set minimum required version of CMake\ncmake_minimum_required(VERSION 3.12)\n#include build functions from Pico SDK\ninclude($ENV{PICO_SDK_PATH}\/external\/pico_sdk_import.cmake)\n# Set name of project (as PROJECT_NAME) and C\/C++ Standards\nproject(blink-led C CXX ASM)\nset(CMAKE_C_STANDARD 11)\nset(CMAKE_CXX_STANDARD 17)\n# Creates a pico-sdk subdirectory in our project for the libraries\npico_sdk_init()\n# point out the CMake, where to find the executable source file\nadd_executable(${PROJECT_NAME}\n        main.c\n)\n# create map\/bin\/hex\/uf2 files.\npico_add_extra_outputs(${PROJECT_NAME})\n# Pull in our pico_stdlib which pulls in commonly used features (gpio, timer-delay etc)\ntarget_link_libraries(${PROJECT_NAME}\n            pico_stdlib\n)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Close and re-open Visual Studio, Explorer &gt; Open Folder &gt; Open your project folder<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Build the project<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Press the &#8220;Build&#8221; button in the bottom blue toolbar<br>If prompted, select the \u201cGCC x.x.x arm-none-eabi\u201d build toolchain (you should then see this in the bottom blue toolbar &#8211; if another build tool is selected click the wrench+screwdriver button in the blue toolbar and select it instead).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The project should build successfully<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Running the project<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The Raspberry Pi Pico does not need a programmer, you instead drag and drop the binary file onto the Pico in Windows explorer. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Plug the pico USB into your PC while holding down the BOOTSEL button on it (until the Windows system detects it). Then release the BOOTSEL button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will have put the Pico into its Bootloader Mass-storage system mode and it should have appeared as  a new drive in Windows Explorer named RPI-RP2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To run your program, drag the &#8220;.uf2&#8221; file from your projects &#8220;\\build&#8221; directory into the &#8220;RPI-RP2&#8221; folder. You should then see the LED start flashing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create a new project As you follow these steps for the first time after install, Visual Studio may prompt you to do various setup things &#8211; when it does just click the default option it is asking you. Click top left &#8220;Explorer&#8221; button &gt; Open Folder Create a folder somewhere you want to store your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178],"tags":[],"class_list":["post-3535","post","type-post","status-publish","format-standard","hentry","category-visual-studio-code"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=3535"}],"version-history":[{"count":3,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3535\/revisions"}],"predecessor-version":[{"id":3540,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3535\/revisions\/3540"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=3535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=3535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=3535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}