How to Program Raspberry Pi Pico With the Arduino IDE

Program Raspberry Pi Pico with Arduino IDE
(Image credit: Tom's Hardware)

Wiring code for your Raspberry Pi Pico can fall into two categories. The easy way for new users is to use a version of Python such as MicroPython or CircuitPython. A more advanced way is to write code in C / C++ which is for more confident users.

There is now a third way that we can write code for our Raspberry Pi Pico, and that is via the Arduino IDE, which uses “Arduino Language,” a derivative of C++. Because Arduino has been around for so many years, there’s a ton of pre-existing “sketches” (the Arduino term for programs) and tutorials for it. If you’ve worked with Arduino boards before, you may be very familiar with this powerful IDE and language.

Latest Videos FromTom's Hardware
Les Pounder
Associate Editor

Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".

  • softeky
    Just a heads-up. Following installation instructions for Linux I ran into a couple of snags.
    (1) I'm compiling on Raspberry (Linux rpi 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux). Not the most update but... "./pico_setup.sh" won't use cmake that comes with the OS. "apt-get" won't go above v3.7 which fails the script.

    I backtracked and found instructions to install cmake v3.13.4 here. It took a while but that worked.

    (2) returning to "./pico_setup.sh", I had to "rm -rf pico" to start over (not continuable from where it failed). Although the script tried to schedule installation of cmake v3.7 again, it was sophisticated enough to skip that (I think) as it did not fail again at the use of cmake when needed.

    (3) unfortunately the C++ compilation failed here:
    Building CXX object CMakeFiles/picoprobe.dir/home/pi/pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp.obj
    /home/pi/pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp:20:55: error: expected initializer before 'noexcept'
    void operator delete(void *p, __unused std::size_t n) noexcept { std::free(p); }
    ^
    /home/pi/pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp:24:33: error: expected initializer before 'noexcept'
    void operator delete(void *p) noexcept { std::free(p); }
    ^
    CMakeFiles/picoprobe.dir/build.make:585: recipe for target 'CMakeFiles/picoprobe.dir/home/pi/pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp.obj' failed
    make: *** Error 1
    make: *** Waiting for unfinished jobs....
    CMakeFiles/Makefile2:74: recipe for target 'CMakeFiles/picoprobe.dir/all' failed
    make: *** Error 2
    Makefile:83: recipe for target 'all' failed
    make: *** Error 2I figured I should post before trying to fix the code error and getting stuck in another rabbit hole.

    It's getting there - thanks for all the effort as I have a sneaky feeling the Arduino IDE guys won't be overly enthusiastic to come out with their own Raspberry Pico IDE as competition to their own pico hardware :)
    Reply
  • softeky
    softeky said:
    Just a heads-up. Following installation instructions for Linux I ran into a couple of snags.
    ...

    Replying to my own post (sorry). Just continuing the saga, trying to get Debian on Raspberry Pi to load the Linux package that gets the Arduino IDE to support Raspberry Pico development.

    ...continuing...

    The source issue is the compiler keyword "noexcept", which was introduced into C++ by gcc at version11. I got as far as getting gcc++ v10.1 compiled and installed in Debian on my Raspberry Pi but it won't run since gcc++ v10.1 requires GLIBC_2.28 in "/lib/arm-linux-gnueabihf/libc.so.6", which only goes as far as GLIBC_2.27 in Debian. Fixing that would risk even booting Debian and (subsequently discovered) gcc++ v10.1 would not support "noexcept", so that was a dead end path.

    Instead I checked what "noexcept" was meant to do. It's a compile time assert which should provide no features to the runtime result. Trouble is "fixing" the code by removing "noexcept" would be overwritten since the source is fetched, each time the "pico_setup.sh" script is run. "pico_setup,sh" is not reentrant, it complains at a "mkdir build" line that the directory exists. That directory is an artifact of the precious run. Even changing "mkdir build" to "mkdir -p build" fails further down as other directories exist and are not empty. I have to "rm -rf pico" between each attempt so my "fixes" don't survive (:-( ).

    To get past that, I copied the source that trips up the compile:
    pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cppto the same directory as the "pico_setup.sh", "fixed" the source by commenting out both "noexcept" references:
    void operator delete(void *p, __unused std::size_t n) noexcept { std::free(p); }

    void operator delete(void *p) { std::free(p); }

    void operator delete(void *p) noexcept { std::free(p); }
    became

    void operator delete(void *p, __unused std::size_t n) /* noexcept */ { std::free(p); }

    void operator delete(void *p) { std::free(p); }

    void operator delete(void *p) /* noexcept */ { std::free(p); }
    and added a re-copy back step just before the relevant "make" in "pico_setup.sh" i.e.
    cd build
    cmake ../
    make -j$JNUMbecame:
    cd build
    cmake ../
    cp ${HOME}/new_delete.cpp ${HOME}/pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp
    make -j$JNUM
    A bit of a kludge but that now compiles on Debian's gcc++ v6.3.

    The saga continues... the next snag is:
    Processing triggers for gnome-menus (3.13.3-9) ...
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package libegl-mesa0
    That appears to be something to do with a video driver given as a dependency.

    ONWARD!
    Reply
  • softeky
    softeky said:
    Replying to my own post again (sorry). Still continuing the saga, trying to get Debian on Raspberry Pi v3 to load the Linux package that gets the Arduino IDE to support Raspberry Pico development.

    ...continuing...

    Processing triggers for gnome-menus (3.13.3-9) ...
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package libegl-mesa0
    That appears to be something to do with a video driver given as a dependency.

    ONWARD!

    It Works!

    Last "fix" to the "pico_setup.sh" script for Raspberry Pico support to Arduino IDE hosted on a Raspberry Pi v3 (Linux rpi 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux).
    from:
    EXTRA_VSCODE_DEPS="libx11-xcb1 libxcb-dri3-0 libdrm2 libgbm1 libegl-mesa0"

    to:
    # was EXTRA_VSCODE_DEPS="libx11-xcb1 libxcb-dri3-0 libdrm2 libgbm1 libegl-mesa0"
    EXTRA_VSCODE_DEPS="libx11-xcb1 libxcb-dri3-0 libdrm2 libgbm1"
    I have one of my sketches ported from Arduino Mega to Raspberry Pico. Phew.

    TY hardworking Arduino IDE board-porting people.

    --Alen
    Reply
  • seamusdemora
    This is pretty awful! It's not been maintained, and is now full of outdated information. In my case, even blink won't work - this is the error message:
    Sketch uses 89816 bytes (4%) of program storage space. Maximum is 2097152 bytes.
    Global variables use 42824 bytes (15%) of dynamic memory, leaving 227512 bytes for local variables. Maximum is 270336 bytes.
    .....................
    Failed uploading: uploading error: exit status 1

    You guys should delete this - it's a waste of time & a source of frustration for all who follow it. Sheesh!
    Reply
  • ndabas
    The link to the Windows installer should now be: https://github.com/raspberrypi/pico-setup-windows/releases/latest/
    The link in the article points to my repo (https://github.com/ndabas/pico-setup-windows), which has now been adopted by Raspberry Pi as the official installer for the Pico SDK, and development is continued over there.
    Reply