Creating a new C/C++ Raspberry Pi Pico Project on Windows

Everything in this file comes from the Getting started with Raspberry Pi Pico for C/C++ development guide and Prof. Hunter Adams's project page. This file contains all of the same content, just organized into an enumerated list.



Creating a new project

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"

const uint LED_PIN = 25;

int main(){
    stdio_init_all();

    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);

    while(1){
        gpio_put(LED_PIN, 0);
        sleep_ms(250);
        gpio_put(LED_PIN, 1);
        puts("Hello world\n");
        sleep_ms(1000);
    }
}
cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)

project(test_project)

pico_sdk_init()

add_executable(test test.c)

pico_enable_stdio_usb(test 1)
pico_enable_stdio_uart(test 0)

pico_add_extra_outputs(test)

target_link_libraries(test pico_stdlib)

Building the project

  1. In the Developer PowerShell for Visual Studio, navigate to your test project repository.

  2. Build by running the following:

     mkdir build
     cd build
     cmake -G "NMake Makefiles" ..
     nmake
  3. Note: If, on the second build, you get errors thrown due to syntax in makefiles, run nmake clean before again running nmake.

  4. Within the build directory, you will now find a hello_world directory. You will find directories for each of the other example projects too. These folders will contain the ELF, bin, and uf2 target files for each project. The uf2 target file can be dragged-and-dropped directly onto an RP2040 board attached to your PC via USB, as explained here.