Programming Raspberry Pi Pico with Arduino IDE (Pico W compatible)

Learn how to program the Raspberry Pi Pico using Arduino IDE software. The Raspberry Pi Pico is a low-cost microcontroller board developed around the RP2040 chip by the Raspberry Pi Foundation and it can be programmed using MicroPython or C/C++ like the Arduino. In this tutorial, you’ll learn how to set up Arduino IDE to start programming your Raspberry Pico and Pico W boards with C/C++ programming language.

Programming Raspberry Pi Pico with Arduino IDE

New to the Raspberry Pi Pico? Read our Raspberry Pi Pico Getting Started Guide.

Don’t have a Raspberry Pi Pico yet? Check it out here.

Table of Contents

Installing Arduino IDE

Before proceeding you need to install Arduino IDE on your computer. Currently, there are two versions of Arduino IDE you can install: version 1 or version 2.

You can download and install Arduino IDE by clicking on the following link:

If you want to install version 1, scroll down the page until you find the legacy 1.8.X version.

Adding the Raspberry Pi Pico to the Boards Manager

1. In the Arduino IDE, go to File > Preferences.

Arduino IDE Preferences

2. Enter the following URL into the “Additional Boards Manager URLs” field:

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

Then, click the “OK” button:

Raspberry Pi Pico Additional Boards Manager

Note: if you already have the ESP32 and/or ESP8266 boards URL,s you can separate the three URLs with a comma as follows:

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json, https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json

3. Open the Boards Manager. Go to Tools > Board > Boards Manager…

4. Search for “pico” and install the Raspberry Pi Pico/RP2040 boards.

Install Raspberry Pi Pico boards

5. That’s it. It will install after a few seconds.

6. Now, if you go to Tools > Board, there should be a selection of Raspberry Pi Pico boards.

Raspberry Pi Pico Boards Arduino IDE

Programming the Raspberry Pi Pico Using Arduino IDE

Now you have everything prepared to start programming your Raspberry Pi Pico board using Arduino IDE.

1. Selecting your Pico Board

Go to Tools > Board and select the Raspberry Pi Pico model you’re using—Pico or Pico W (wireless support).

2. Loading the Blink LED Sketch

As an example, we’ll upload the classic Blink LED sketch. Go to File > Examples > 1. Basic > Blink.

The following example should load.

Programming the Raspberry Pi Pico Using Arduino IDE Blink LED sketch

Or you can copy the following code:

/*
  Blink -  Turns an LED on for one second, then off for one second, repeatedly.
  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: https://www.arduino.cc/en/Main/Products
  modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi modified 8 Sep 2016 by Colby Newman  This example code is in the public domain. https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
  
  Programming Raspberry Pi Pico with Arduino IDE: https://RandomNerdTutorials.com/programming-raspberry-pi-pico-w-arduino-ide/
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

View raw code

3. Connecting the Raspberry Pi Pico in BOOTLOADER mode

For you to be able to upload code to the Raspberry Pi Pico, it needs to be in bootloader mode.

If the Raspberry Pi is currently running MicroPython firmware, you need to manually put it into bootloader mode. For that, connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time.

Raspberry Pi Pico Bootloader mode

For future uploads using Arduino IDE, the board should go automatically into bootloader mode without the need to press the BOOTSEL button.

Now, select your COM port in Tools > Port. It may be the case that the COM port is grayed out. If that’s the case, don’t worry. It will automatically find the port once you hit the upload button.

Raspberry Pi Pico - COM port not found Arduino IDE

Upload the code.

Arduino 2.0 Upload Button

You should get a success message.

Done uploading sketch to Raspberry Pi Pico W board using Arduino IDE

Demonstration

If everything went as expected, the Raspberry Pi Pico onboard LED should be blinking every second.

And that’s it. You successfully programmed your Raspberry Pi Pico using Arduino IDE.

Wrapping Up

In this tutorial, you learned how to set up the Arduino IDE to program the Raspberry Pi Pico using C/C++ programming language, similar to what you use to program the Arduino, ESP32, and ESP8266.

The Raspberry Pi Pico can also be programmed using MicroPython firmware. If you’re interested in programming the Pico using MicroPython, check this tutorial.

You can check all our Raspberry Pi Pico projects and tutorials on the following link:

You may also like:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

17 thoughts on “Programming Raspberry Pi Pico with Arduino IDE (Pico W compatible)”

  1. Very useful and easy.
    I had purchased a Pico W some time ago, thinking to learn to use it some day (I currently make my projects with ESP32).
    It has been seeing this and have the Pico W working in minutes.
    Thank you, regards from Spain.

    Reply
    • That’s great!
      We’ll start publishing new tutorials about the Raspberry Pi Pico. So, stay tuned.
      Regards,
      Sara

      Reply
  2. Thanks for another great tutorial.
    It looks like an immense amount of program memory and variable space is used (27% !!), just to make an LED blink !
    This does not happen with Arduinos, the programs are a lot smaller, like a thousand times smaller.
    Is there another way to program the Pico, so that the code is not so bloated ?
    Ovid

    Reply
    • There are tons of way of programming pico:

      micropython is more bloated than Arduino (ships almost each and everything one can need; is easy; is slower than Arduino and SDK)
      SDK http://www.raspberrypi.com/documentation/microcontrollers/rp2040.html is the official way; is not easy; is not bloated; if one chooses other 2040 boards, is very complicated; if one is accustomed with Arduino libraries, it is very complicated, too
      picolua blog.adafruit.com/2021/04/14/lua-for-the-raspberry-pi-pico/ is not very devlopped
      tinygo tinygo.org/docs/reference/microcontrollers/pico/ is likely to be somewhat bloated…
      basic hackaday.com/2023/06/28/a-basic-interpreter-for-the-raspberry-pi-pico/ … is very … basic (no I2C/SPI support, say)
      … Unix shell mini interpreter http://www.raspberrypi.com/news/how-to-get-started-with-fuzix-on-raspberry-pi-pico/

      And I bet I missed another ton…

      Conservative, popular ways remain SDK, micropython and Arduino.

      Reply
      • Thanks DBrion for clarifying this. I did not look into it too much, but I did not come across any accessible way to generate compact code. Having worked in assembly language on a Z80 (and loved it) many years ago, this makes me cringe.

        Reply
        • There are -at least – two ways of having assembly code in ArduinoIDE:
          gcc/g++ can cope with in line assembly : https://gcc.gnu.org/onlinedocs/gcc/extensions-to-the-c-language-family/how-to-use-inline-assembly-language-in-c-code.html .
          If you have a C (c++) function called main -it is a reserved word for arduino- which countains “only” assembly, one can -theoretically : I bet nobody dared it – program Arduino in assembly : Arduino wonot generate a main -it usually does- , and, if there are no libraries (#include <ttt.h> , tt being a library which makes things easier), your code wonot be bloated at all… but it might take a long time to have something working : just selecting a clock is very difficult in an ARM -system clock is selectable, frequency is tunable…) ; USB software is complicated, too; Z80 did not have these issues).

          Other soulution is having a file called whatItsName.S ; .S extension is real assembly arm-gas (comes with binutils, parts of Arduino) file; Things can be more terrible than the 1rst option…

          You should ask youself what “bloated” means:
          * you can have a lot of sleeping code (some libraries are linked, and are useless to … blink a LED); but flash memory is huge w/r Z80 standards. Even if there are tons of unusuded libraries, time to fill the flash with one’s code and constants w=cannot be neglected.

          you can hav a very short code and …. unused flash…

          Did you know that picopi have automata -called PIO- , which can be programmed in -a kind of- assembly. Number of that “assembly” -used to bit bang on a dedicated automata/tiny extra processor- SPI/I2C, if needed, say- lines is small (< 30 IIRC).

          It can be used from micropython
          digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-micropython-part-3-pio/3079f9f9522743d09bb65997642e0831
          and from the SDK
          digikey.co.uk/en/maker/projects/raspberry-pi-pico-and-rp2040-cc-part-3-how-to-use-pio/123ff7700bc547c79a504858c1bd8110 +official documentation

          EarlePhilower pico port, which is shown in this nice blob, seems to support PIOs, too github.com/earlephilhower/arduino-pico/blob/master/cores/rp2040/pio_uart.pio

          Reply
  3. Other than the GP pin out numbers, can the esp32 software from the ESP32 be pasted into the program for the pico and down loaded?

    I have trouble keeping the ESP32 on line with WIFI, and I have followed your notes as to help fix this in the ESP32, I still have a lot of problems. I don’t have a fixed IP in the software for each, but have an IP address manager on the initial boot that allows via a web browser attach to the ESP and pick my router ssid and the MAC address is in the router table. On power outage I delay via a mechanical time delay relay the power to the ESP for 10 min to get the router up and running. If not the ESP32’s starts up and the IP manager times out and defaults to the factory IP.

    Is the WIFI better/stronger in the pico?

    I am running 24 ESP32’s on bee hives monitoring weights, temperatures and humidity ever 5min via of a raspberry pi 4 into spreadsheets and will using Node RED and Influx.

    Reply
    • Hi.
      I haven’t tried Wi-Fi on the Pico yet.
      I’m still testing the GPIOs.
      From what I can tell most code from the ESP32/ESP8266 is compatible with the Pico apart from some different in the pinout.
      I think it uses the same Wi-Fi library methods as the ESP32, but I haven’t experimented yet.
      Regards,
      Sara

      Reply
  4. Well, something puzzles me in this tutorial:
    there are two arduino ways of programming a pico, EarlPhilower one (this is very well described in this blog and worked for me last year) and “official” mbed one.
    Though I did not use the “official” way, I was advised to choose it because EarlPhilower is a man’s(great) work. That is very puzzling.
    Zei gesint

    Reply
  5. Thanks a lot for the tutorial. After scratching my head for 3 days with the official board Mbed OS, I was finally able to run arduino c++ on my Pico W! Well done!

    Reply
  6. I’m looking forward to articles on the Pico. I hope you include more advanced techniques beyond the standard fare. My interests are in interrupts and handling, dual core, maybe some effective PIO, reliably reading optical encoders, etc, beyond blinking LEDs and pushing buttons.

    I like the ease-of-use of using mbed on the Arduino interface, but I like the improved capabilities of the Philhower port C/C++ on VSCode, too.

    Reply
    • Hi.
      We’ll start by covering the most basic subjects, and then, we’ll start covering also MQTT and other IoT subjects.
      Regards,
      Sara

      Reply
  7. Excellent job and excellent site with clear tutorials. Many thanks to you.
    Between each upload My Pico2040 needs plug-unplug USB (sort of power on/off).
    Hereafter how I work around the problem.
    -Do not plug USB
    -Press and hold Bootloader button
    -Plug USB
    -Release Bootloader button
    -(a window appears with: INDEX.HTM and INFO_UF2.TXT)
    -Upload the program (Arduino 1.8.19, usual Blink)

    -It works !

    If somebody has the solution to avoid plug-unplug USB, please let me know.

    I am using MATE-64bits on top of RPi-4.
    Again many thanks for this excellent work
    Eric

    Reply
    • Hi.
      Usually, I only need to do that on the first upload if the board was not previously running an Arduino program.
      After running a program with ARduino IDE, usually I don’t need to do that afterwards.
      Regards,
      Sara

      Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.