Raspberry Pi Pico Software tools in Windows 10
Jed Margolin 9 July 2024
I probably spent at least 100 hours (most of it wasted) trying to get the Raspberry Pi Pico tools for Windows 10 to work so I can do my own software. None of the instructions online from various sources worked for me. Some guides tell you to use Powershell (or a Command Prompt) and do a bunch of typing. I suspect that those authors live in the Linux alternate universe. Other instructions probably worked until Microsoft “upgraded” Visual Studio 2019 to Visual Studio Code 2022. Supposedly the Linux tools are easier to get working if you have a Linux machine like the standard Raspberry Pi system. When I started working on this in 2023 they weren’t making them that year.
I have more or less succeeded in getting the Windows tools to work.
I suggest that you get the software tools working before you spend money buying parts. Your pain threshold might not be as high as mine.
Bear in mind that the Raspberry Pi Pico tools use software from several sources. One or more of the software toolmakers (especially Microsoft) could update their tools at any time and break everything. After all, this is Windows.
At first the only way I could do my own software was by hijacking various examples. When I tried to create a new project, not only did it not work it would break something and I had to re-install the raspberry-pi-pico-windows-installer to get anything working again.
The Windows tools are at: https://www.raspberrypi.com/news/raspberry-pi-pico-windows-installer/ When I started, the tools were Version v1.50 . At some point they updated to v1.51 . This new version broke some things that were easy to fix. I forget exactly what I had to do.
This is what I learned. Warning: it might or might not work for you. And it could change at any time. After all, this is Windows.
A. It appears that your computer needs to have Microsoft .NET installed. https://dotnet.microsoft.com/en-us/
B. When you create new folders and files you can use Windows Explorer and Wordpad (or anything that will create an ASCII text file).
1. Some guides tell you to use Powershell (or a Command Prompt) and do a bunch of typing which is why I think the authors live in the Linux alternate universe.
2. Some tell you to create new folders and files using Visual Studio Code. That doesn’t work for me. I cannot get it to create a folder above the folder I am in. That may be because Visual Studio 2019 has a button for creating a new project but they took that button out for Visual Studio Code 2022. Why did they do that?
C. When you install the SDK it will ask you where to install it. I accept its suggestion (wherever that is). Later it will ask if you want to install the Examples (Yes!) and where to install them. I tell it c:\raspberry-pi-pico because it is shorter than the default name.
When I installed SDK v1.5.0 it installed the libraries (pico-sdk) in that folder:
c:\raspberry-pi-pico
pico-examples
pico-extras
pico-playground
pico-sdk
That probably explained why, in Settings, you had to set:
PICO_SDK_PATH ../../pico-sdk
In Windows “..\“ means go up one directory from where you are and “..\..\“ means go up 2 directories from where you are and “..\..\pico-sdk“ means go up 2 directories from where you are and look for pico-sdk which is where it was. That is clumsy and requires that “include” instructions in the programs are also clumsy. (You may have noticed that sometime it is a forward slash (‘/’) and sometimes it is a backslash (‘\’). For reasons that go back to when dinosaurs still walked the land Microsoft uses ‘\’ and Linux/Unix uses ‘/’. That might be part of the problem here.)
Normally, something like:
#include <stdio.h>
means look for it in the Systems path, and
#include "pico/stdlib.h"
means look for it starting with the directory where this source file is.
The setting (PICO_SDK_PATH ../../pico-sdk) was supposed to make that kludge work. However, the result was that many times, most of the time, or all of the time the program would refuse to compile, saying that it couldn’t find the libraries. All it took to cause this error was to look at it wrong.
They fixed this in SDK v1.5.1 . Now the directory is:
c:\raspberry-pi-pico
pico-examples
pico-extras
pico-playground
sdk-pico is presumably somewhere with the system files.
The statement in Settings still says (PICO_SDK_PATH ../../pico-sdk). That might be an artifact from SDK 1.5.0. I don’t know. I am not going to change it and risk breaking everything.
D. If you look at the directory c:\raspberry-pi-pico\pico-examples it will contain more directories. Here are just three of them.
gpio
hello_world
i2c
I call them Project Groups. Each of these directories will contain more directories. These are where the actual projects are located. For example:
c:\raspberry-pi-pico
pico-examples
gpio (Project Group)
dht_sensor (Project)
hello_7segment (Project)
hello_gpio_irq (Project)
Because I had so many problems getting anything to work at all I followed the way the examples were done and added my own programs to it.
c:\raspberry-pi-pico
pico-examples
myprogs (Project Group)
adc-clock (Project)
flash-demo (Project)
lcd_2x16 (Project)
pico-bme280 (Project)
pico-rx-test (Project)
pico-tx-test (Project)
E. Now the dreaded CMakeLists.txt
Contrary to many instructions on the ‘Net, it is done in layers here.
1. The top one is in
c:\raspberry-pi-pico
pico-examples
CMakeLists.txt
This one contains a lot of stuff including the subdirectories of the project groups such as:
# Hardware-specific examples in subdirectories:
add_subdirectory(adc)
add_subdirectory(clocks)
add_subdirectory(cmake)
add_subdirectory(divider)
add_subdirectory(dma)
add_subdirectory(flash)
add_subdirectory(gpio)
.
.
.
To this I added my own project group (myprogs):
# Hardware-specific examples in subdirectories:
add_subdirectory(myprogs)
add_subdirectory(adc)
add_subdirectory(clocks)
add_subdirectory(cmake)
add_subdirectory(divider)
add_subdirectory(dma)
add_subdirectory(flash)
add_subdirectory(gpio)
.
.
.
2. My directory myprogs has its own CMakeLists.txt
if (NOT PICO_NO_HARDWARE)
add_subdirectory(adc-clock)
add_subdirectory(flash-demo)
add_subdirectory(lcd_2x16)
add_subdirectory(pico-bme280)
add_subdirectory(pico-rx-test)
add_subdirectory(pico-tx-test)
endif ()
3. Each project directory also has its own CMakeLists.txt .
For example, this is the CMakeLists.txt for adc-clock:
add_executable(adc-clock adc-clock.c lcd.c clock.c)
# pull in common dependencies and additional i2c hardware support
target_link_libraries(adc-clock pico_stdlib hardware_i2c hardware_adc hardware_spi hardware_uart)
# create map/bin/hex file etc.
pico_add_extra_outputs(adc-clock)
# add url via pico_set_program_url
example_auto_set_url(adc-clock)
You have to put the libraries in it:
target_link_libraries(adc-clock pico_stdlib hardware_i2c hardware_adc hardware_spi hardware_uart)
To unwrap it:
adc-clock Project Name
pico_stdlib Library
hardware_i2c Library
hardware_adc Library
hardware_spi Library
hardware_uart Library
This is what they look like in the source file adc-clock.c:
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "hardware/adc.h"
#include "hardware/spi.h"
#include "hardware/uart.h"
#include <string.h>
#include "main.h"
a. Notice that:
The file main.h is not a library. It is my file, a local file called in adc-clock.c which is why it is enclosed in quotes.
I don’t know why <stdio.h> is included as a system file while other libraries like “hardware/adc.h” are in quotes like a local file even though they aren’t. I also don’t know why <stdio.h> and <string.h> are in the source file but not in CMakeLists.txt.
b. The format is different. For example #include "hardware/adc.h" becomes hardware_adc in CMakeLists.txt.
I don’t know why that is. And I don’t care, as long as it works.
F. Building things.
I am an Old School EE. I thought Building a program was the same as Making a program where you compile, link, and produce an executable program. Not here. Here Building a program means only creating the Make files. Then you Make the program.
G. These tools are set up so that all of the Make (CMake) files are in a separate directory tree starting in
c:\raspberry-pi-pico
pico-examples
build
Project Groups
Projects
a. Making (CMaking) a project produces several files. One is project.uf2 . This is the file you download to the Pico module through its USB port after you hold down BOOT pushbutton and do a Reset. You can do a Reset by unplugging the USB connector and plugging it in again. I find that awkward so all of my boards have their own Reset Pushbutton. Another file is project.bin. This is the size of the executable binary code in the Pico. In other words, that is the size of your executable binary program.
b. The files in each build directory project directory are somewhat large, several MBytes. If you Make all of the example projects the result will be about 800 MBytes. Even if you have a huge hard drive it take time to copy that much data and that many files, as you would do in making a copy to back-up your own projects. Best practice is to always keep a copy of the last working version of your programs, preferably going several versions back. That way you can always go back to it when you change something and all of a sudden your program doesn’t work right or might not work at all.
Because I don’t need the executable example projects, but want to keep the source code for them, I comment out their Project Groups in the top CMakeLists.txt . You do that with a ‘#’ so it looks like:
# Hardware-specific examples in subdirectories:
add_subdirectory(myprogs)
#add_subdirectory(adc)
#add_subdirectory(clocks)
#add_subdirectory(cmake)
#add_subdirectory(divider)
#add_subdirectory(dma)
#add_subdirectory(flash)
#add_subdirectory(gpio)
#add_subdirectory(i2c)
#add_subdirectory(interp)
#add_subdirectory(multicore)
#add_subdirectory(picoboard)
#add_subdirectory(pico_w)
#add_subdirectory(pio)
#add_subdirectory(pwm)
#add_subdirectory(reset)
#add_subdirectory(rtc)
#add_subdirectory(spi)
#add_subdirectory(system)
#add_subdirectory(timer)
#add_subdirectory(uart)
#add_subdirectory(usb)
#add_subdirectory(watchdog)
And that is how I got the Raspberry Pi Pico SDK to work in Windows 10 so I can use the amazing Raspberry Pi Pico.
JM
.end