0% found this document useful (0 votes)
50 views

Getting Started With RPi Pico W Using C

This document provides a guide for getting started with the Raspberry Pi Pico W using C/C++ on Windows, detailing setup instructions, project creation, and example code. Key features of the Raspberry Pi Pico include a dual-core ARM processor, extensive GPIO options, and Wi-Fi capabilities. It also compares the Pico with Arduino, highlighting differences in architecture, clock speed, memory, and GPIO pins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Getting Started With RPi Pico W Using C

This document provides a guide for getting started with the Raspberry Pi Pico W using C/C++ on Windows, detailing setup instructions, project creation, and example code. Key features of the Raspberry Pi Pico include a dual-core ARM processor, extensive GPIO options, and Wi-Fi capabilities. It also compares the Pico with Arduino, highlighting differences in architecture, clock speed, memory, and GPIO pins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Getting started with RPi Pico W using C/C++ on

Windows
Everything same as for RPi Pico setup, only difference at Section 3(Start a new project).

The Raspberry Pi Pico series is a range of tiny, fast, and versatile boards built using RP2040,
the flagship microcontroller chip designed by Raspberry Pi in the UK.
• Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz
• 264kB of SRAM, and 2MB of on-board flash memory
• USB 1.1 with device and host support
• Low-power sleep and dormant modes
• Drag-and-drop programming using mass storage over USB
• 26 × multi-function GPIO(General Purpose input-output) pins
• 2 × SPI(Serial Peripheral Interface), 2 × I2C(inter integragted Circuits), 2 × UART(Universal
Asynchronous Receiver/Transmitter), 3 × 12-bit ADC, 16 × controllable PWM channels
• 8 × Programmable I/O (PIO) state machines for custom peripheral support

Difference between Arduino and Raspberrypi Pico :


Key features Arduino Raspberrypi Pico

Core Architecture 8-Bit RISC AVR 32-Bit Dual Core ARM


Cortex M0+
CPU Clock 16MHz Up to 133Mhz
RAM size 2 Kb 264kb
Flash Memory size 32Kb 2 MB
GPIO pins 22(14 Digital 26(all are digital )
8 – analog)

Overview
Pinout
Getting Started
RPi Pico C/C++ SDK Documentation
https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf

1. Setup
To start working with the microcontroller, we can use

Prepared by: Souhardhya Paul Last Update: 4/1/2024


One Click Installer (Setup Video step by Step)(Recommended)
OR
manually configure each component needed for this (refer section 4 of this document).

After the wizard has completed installation, it will prompt you whether it should display a
tutorial, and optionally clone, check both options and finish.

2. After done with the Setup


2.1. Starting Visual Studio Code
In your Start Menu, look for the *Pico - Visual Studio Code* shortcut. The shortcut sets up the
needed environment variables and then launches Visual Studio Code.
Note
If you have previously had Visual Studio Code installed, we often see problems due to random
settings inserted by other extensions, or by the user, in an existing installation. If this is the
case for you, please go to the Pico Installer Wiki for a checklist of known issues and solutions.

2.2. Opening the examples


The first time you launch Visual Studio Code using the Start Menu shortcut, it will open the
https://github.com/raspberrypi/pico-examples repository.

To re-open the examples repository later, you can open the copy installed at
(default)`C:\Users\<user>\Documents\Pico-<version>\pico-examples`.

2.3. Building an example


Visual Studio Code will ask if you want to configure the pico-examples project when it is first
opened; click *Yes* on that prompt to proceed.
(If you miss the prompt look for the 'bell' icon in the bottom right.)
You will then be prompted to select a kit -- select the *Pico ARM GCC - Pico SDK Toolchain with
GCC arm-none-eabi* entry. If the *Pico ARM GCC* entry is not present, select *Unspecified*
to have the SDK auto-detect the compiler.
To build one of the examples, click the *Build* button on the bottom panel.

Prepared by: Souhardhya Paul Last Update: 4/1/2024


3. Start a new project(only for pico-w, not pico)
• Make a project directory say “Blink”.
• Copy “pico_sdk_import.cmake” from C:\Program Files\Raspberry Pi\Pico SDK
v1.5.1\pico-sdk\external or PICO_SDK_PATH\external\ into “Blink” folder.
• Copy “.vscode” folder from C:\Users\<user>\Documents\Pico-<version>\pico-
examples into “Blink” folder.
• Create a file “CMakeLists.txt” into “Blink” and paste following content

# Set minimum required version of Cmake


cmake_minimum_required(VERSION 3.12)

#IMPORTANT!!! Use this only to set board Pico W, otherwise


#comment
set(PICO_BOARD pico_w)

#Include build functions for Pico SDK


include(pico_sdk_import.cmake)

#set name of project (as PROJECT NAME) and C/C++ standards


project(blink C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

#create a pico-sdk subdirectory in our project for the libraries


pico_sdk_init()

#Tell CMake where to find the executable source file


add_executable(blink
main.c
)

#Create map/bin/hex/uf2 files


pico_add_extra_outputs(blink)

#Link to pico_stdlib (gpio, time, etc, functions)


target_link_libraries(blink
pico_stdlib
pico_cyw43_arch_none # we need Wifi to access the GPIO,
#but we don't need anything else
)
• Create a file “Main.c” into “Blink” and paste following content
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"

int main() {
stdio_init_all();
if (cyw43_arch_init()) {
printf("Wi-Fi init failed");

Prepared by: Souhardhya Paul Last Update: 4/1/2024


return -1;
}
while (true) {
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
sleep_ms(250);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
sleep_ms(250);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
sleep_ms(500);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
sleep_ms(500);
}
}
• Open “Pico – VS Code” from Start Menu(not VSCode directly) and Goto->File->Open
Folder->(Your Project{Blink}) folder.
• If asked about selecting a kit, select “Pico ARM GCC”
• Press Ctrl+Shift+P to open command pallete in VSCode, Type CMake:Configure, let it
complete. It’ll generate a build directory.
• Press Ctrl+Shift+P to open command pallete in VSCode, Type CMake:Build, this will
generate map/bin/hex/uf2 files in build directory.
• The uf2 file generate is to be uploaded in Pico W to dump code. For that, press boot
switch of Pico W and insert power cable to PC. It’ll get detected as flash drive, we
need to paste blink.uf2 file there and Pico W will restart automatically and onboard
LED will blink.

4. Manual setup, configuring each component separately(not recommended)

Following are the component that needed to be configured separately, if One Click Installer is not
working.

• Arm GNU Toolchain


• CMake
• Ninja
• Python 3.9
• Git for Windows
• Visual Studio Code
• OpenOCD

For manually installing you can refer section 9.2.2(Alternative Manual Installation) of this or
follow this article.

5. Extra materials
1. https://github.com/raspberrypi/pico-examples
2. https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf
3. https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf

Prepared by: Souhardhya Paul Last Update: 4/1/2024


4. https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf
5. https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf
6. https://datasheets.raspberrypi.com/pico/pico-product-brief.pdf
7. https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf
8. https://datasheets.raspberrypi.com/picow/pico-w-product-brief.pdf

Prepared by: Souhardhya Paul Last Update: 4/1/2024

You might also like