#include "pico/stdlib.h" causes errors

I’ve just started trying to use the raspberry Pi Pico and the first example I tried used pico/stdlib.h but unfortunately I get the error "cannot open source file “pico/stdio.h” ". I’ve googled for hours now and I can’t understand how the solutions work when using platformIO. Some mention adding include(pico_sdk_import.cmake) or/and target_link_libraries(014__Comparator-Test pico_stdlib) to the CMakeLists.txt but I don’t really know how to do that with platformIO. I have added the board and it downloaded the relevant things. The weirdest part is that the code completion finds the correct file but the n it says it’s wrong. Can anyone help with this?

1 Like

Please post your full platformio.ini as a start.

[env:pico]
platform = raspberrypi
board = pico
framework = arduino
lib_deps =
adafruit/DHT sensor library@^1.4.2
adafruit/Adafruit Unified Sensor@^1.1.4

Do you want to work with the Arduino core for the Pico or use the raw Pico SDK? When using the Arduino framework you can’t #include <pico/stdio.h>, even in the Arduino IDE, due to a missing dependency. One is supposed to use Arduino.h and its functions, not the raw SDK.

If you want to just use the Pico SDK, use https://github.com/Wiz-IO/wizio-pico instead. Carefully read through the documentation.

Example project

[env:raspberry-pi-pico]
platform = https://github.com/Wiz-IO/wizio-pico.git
board = raspberry-pi-pico
framework = baremetal
build_flags = 
    -D LIB_PICO_STDIO_USB           ; for printf() via USB serial, not UART
    -D PICO_USB                     ; activate tinyusb

Thank you, that is very helpful. I understand more now about the differences between the Arduino core and the Pico SDK. My only problem now is that the documentation for the Pico uses the Pico SDK while I would like to use Arduino core. Most multicore examples I had prepared before hand to get started with used the raw Pico SDK. It seems it’s not as easy as I thought to get both cores working. Some sources seem to suggest I have to pick the raw SDK if I want multicore but I’m still searching.

I think the source of some of my confusion was from this website. I clearly didn’t understand what I was reading when I thought I did.
Using the Raspberry Pi Pico SDK (PICO-SDK) — Arduino-Pico 1.0.0 documentation

1 Like

Careful - that’s a different Arduino core.

On the PlatformIO side there are currently 3 platforms that support programming the Pico. A platform is basically a set of board definitions and Python logic to build particular frameworks or enable specific features:

Since you seem to be wanting to work with Earle Philhower’s Arduino core (which incidentally also supports programming against the raw Pico SDK), you should take a look at the example project GitHub - maxgerhardt/pio-pico-core-earlephilhower-test: Test firmware that uses the earlephilhower Arduino core.. The standard Multicore.ino code works just fine with it.

Thank you for your help. I’ve hit a roadblock at the moment. The initial ini file in your example gave several errors to do with some debugging tool, I didn’t quite understand. This post was going to be longer and a bit more detailed but after a power loss at my home I lost all the detail and I can’t remember all the things I did/wrote :frowning: . When I upload with this ini file…

Blockquote
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; Redirecting...
[platformio]
; if debugging, select the environment here.
default_envs = pico_standard
[env]
monitor_speed = 115200
[env:pico_earlephilhower]
; switch to forked platform with new extensions :slight_smile:
platform = GitHub - maxgerhardt/platform-raspberrypi: Raspberry Pi: development platform for PlatformIO
board = pico
framework = arduino
; select new core
board_build.core = earlephilhower
; configure filesystem size. Default 0 Mbyte.
board_build.filesystem_size = 1M
lib_ldf_mode = chain+
; inject core package… not yet registered with PlatformIO
; registry, so pull working version directly from git / download page.
; note that download link for toolchain is specific for OS. see Releases · earlephilhower/pico-quick-toolchain · GitHub.
platform_packages =
maxgerhardt/framework-arduinopico@GitHub - maxgerhardt/arduino-pico: Raspberry Pi Pico Arduino core, for all RP2040 boards
maxgerhardt/toolchain-pico@https://github.com/earlephilhower/pico-quick-toolchain/releases/download/1.3.1-a/x86_64-w64-mingw32.arm-none-eabi-7855b0c.210706.zip
[env:pico_earlephilhower_picoprobe_debugging]
platform = GitHub - maxgerhardt/platform-raspberrypi: Raspberry Pi: development platform for PlatformIO
board = pico
framework = arduino
board_build.core = earlephilhower
board_build.filesystem_size = 1M
; inject core package… not yet registered with PlatformIO
; registry, so pull working version directly from git / download page.
; note that download link for toolchain is specific for OS. see Releases · earlephilhower/pico-quick-toolchain · GitHub.
; the OpenOCD package with Picoprobe support is precompiled and Windows-only. Remove it if you don’t want to debug with a picoprobe or
; are not on Windows.
platform_packages =
maxgerhardt/framework-arduinopico@GitHub - maxgerhardt/arduino-pico: Raspberry Pi Pico Arduino core, for all RP2040 boards
maxgerhardt/toolchain-pico@https://github.com/earlephilhower/pico-quick-toolchain/releases/download/1.3.1-a/x86_64-w64-mingw32.arm-none-eabi-7855b0c.210706.zip
platformio/tool-openocd-raspberrypi@GitHub - maxgerhardt/pio-openocd-picoprobe: PlatformIO package for a precompiled OpenOCD version with Picoprobe support on Windows.
; if uplaod via bootloader reset does not work, upload to the virtual USB drive
; by uncommenting this and adapting the drive.
; upload_port = K:
; upload_protocol = picotool
;upload_protocol = picodebug
; comment the next 3 lines to upload “normally” via the serial / USB disk.
upload_protocol = picoprobe
debug_tool = picoprobe
debug_init_break =
;tbreak setup
build_flags = -DNO_USB
build_type = debug
lib_ldf_mode = chain+
debug_build_flags = -Os -ggdb3
; previous mbed-os core
[env:pico_standard]
platform = GitHub - maxgerhardt/platform-raspberrypi: Raspberry Pi: development platform for PlatformIO
board = pico
framework = arduino
; comment the next 3 lines to upload “normally” via the serial / USB disk.
; upload_port = K
; upload_protocol = picotool
; debug_tool = picoprobe
platform_packages =
platformio/tool-openocd-raspberrypi@GitHub - maxgerhardt/pio-openocd-picoprobe: PlatformIO package for a precompiled OpenOCD version with Picoprobe support on Windows.

…it connects through COM4, puts it into BOOTSEL mode but fails to upload to COM4 and then I get this error:
image
Then I try again using K: as the upload port and I get another error telling me to specify the port/directory.

Unfortunately I’ll be away so I can’t work on this for the next 4 days. At this point I think I’m a bit over my head so I’m thinking it might be better for me to use the Arduino IDE with Earle Philhower’s Arduino core for now until multicore using Arduino on platformIO becomes easier for me. I greatly value your help on this issue and I’ll keep an eye on your work. :slight_smile:

This is an architectural issue with the very first flash and wrong loaded drivers (see here)-- and you’ve also possibly cloned the repo in a time window of approx. a few hours yesterday where there was a bug that prevented uploading (see here).

Please follow these steps:

  • open a CLI and execute pio platform update raspberrypi (makes sure this very important upload fix is included)
  • unplug the Pico, hold down the BOOTSEL button, plug it in
  • use https://zadig.akeo.ie/ to load libusb-win32 drivers for the RP2 Boot2 (Interface 1). (without that rp2040load can’t interact with the USB device)
  • for the first upload where a Pico has been programmed with some other firmware that does not have expose a USB-Serial port which has a reset-by-1200bps-open feature, you need to once manually push the UF2 file onto the Pico’s virtual USB disk in bootloader mode. After a build, the file for that will be in <project folder>/.pio/build/<environment name>/firmware.uf2. Since there seems to be a COM4 port already you might not need to do that.
  • after the first upload, uploading should not need manual interference anymore.