Turn a Raspberry Pi Zero into an Arduino-programmable microcontroller

Set up PiZZa so a spare Raspberry Pi Zero W or Zero 2 W runs Arduino sketches, with fast clock speed, 512 MB of RAM and microSD storage.

Julian ReedElectronics restorer and tinkerer
5 min read

A Raspberry Pi Zero 2 W connected to a laptop by a single micro-USB cable on a workbench.
Photo by Alessandro Oliverio / Pexels
Skill
Beginner
Tools
Computer, Arduino IDE, microSD card
Boards
Pi Zero W or Zero 2 W
Pins
16 data pins, PWM on D15 and D16

If you have a Raspberry Pi Zero sitting unused in a drawer, you can turn it into a fast microcontroller that you program from the Arduino IDE, the same way you would program an Arduino, an ESP32 or a Raspberry Pi Pico. The setup has two parts: you put an image on a microSD card, then you teach the Arduino IDE about the new board. Plan on an hour or so, depending on how familiar you are with the Arduino IDE.

What PiZZa actually does

PiZZa stands for "Pi Zero with Zephyr for Arduino." It is an open-source project by GitHub user jetpax that works on the Raspberry Pi Zero W and Zero 2 W. Instead of Linux, the Pi runs Zephyr, a small real-time operating system hosted by the Linux Foundation. Zephyr boots in milliseconds, or at most about a second. Linux or Windows take several seconds.

On top of Zephyr sits ArduinoCore-zephyr. Arduino maintains this core, and it is the same one used in its newest boards, such as the Arduino UNO R4. All the familiar commands work, including digitalWrite(), analogRead() and Serial.println().

When the Pi boots, three things happen in order:

  • Boot layer. The PINN bootloader loads from the microSD card. PINN is an enhanced version of the old NOOBS bootloader. Instead of Linux, it loads a Zephyr binary called zephyr.bin.
  • Zephyr loader. This layer receives compiled sketches from your computer over USB and stores them on the microSD card.
  • Arduino layer. This layer loads the Arduino Core, then runs your sketch.

Why bother

Compared with popular microcontrollers, the Zero boards have far more power and memory:

  • Processor: the Pi Zero 2 W has a quad-core Cortex-A53 and the Zero W a single-core ARM11, both at 1 GHz. The Pico W runs a dual-core Cortex-M0+ at 133 MHz, and the ESP32 a dual-core Xtensa LX6 at 240 MHz.
  • RAM: both Zero boards have 512 MB. The Pico W has 264 KB and the ESP32 has 520 KB.
  • Storage: the Zero boards use a microSD card, so you get gigabytes. The Pico W has 2 MB of flash, and the ESP32 typically has 4 MB.
  • Math: both Zero boards have a hardware floating-point unit. The Pico W has none, and the ESP32's is single-precision.

All four boards have WiFi. That makes PiZZa a good fit for projects that need a lot of memory, processing power or storage.

What you will need

  • A Raspberry Pi Zero W or Zero 2 W (the Zero 2 W is the more capable of the two)
  • A microSD card of 2 GB or larger. Most cards sold now are 16 GB or more, and your programs can use the extra space for storage.
  • A micro-USB data cable
  • A computer with the Arduino IDE installed
  • The PiZZa image file

Check the cable first

Many micro-USB cables carry power only. Use one that also carries data, or the Arduino IDE will never see the board.

Step by step

  1. Download the PiZZa image. Get the image for your board from the PiZZa project.
  2. Burn it to the microSD card. Write the image to the card, then put the card in the Pi Zero.
  3. Connect the data port. Plug the cable into the Pi's micro-USB data port, the one normally used for USB peripherals, and connect the other end to your computer. You do not need the PWR connector or a separate power supply. This one cable powers the board, carries your sketches and provides the serial monitor connection.
  4. Add the Boards Manager entry. In the Arduino IDE, add the PiZZa Boards Manager entry so the IDE knows how to compile and upload sketches for the Pi.
  5. Write a sketch using Arduino pin names. Refer to pins as D0, D1, D2 and so on, not by BCM GPIO numbers or physical header numbers.
  6. Upload and watch the serial monitor. The sketch travels over the same USB cable, and the loader stores it on the microSD card and runs it.

Pins to keep in mind

Sixteen data pins are available, and some of them are reserved for I2C, SPI and PWM. Keep a chart that maps the Arduino data pins to the Pi's GPIO pins, because you will check it every time you wire something up.

  • PWM works only on D15 and D16.
  • I2C is fixed to GPIO 2 and GPIO 3, which are physical pins 3 and 5 on the 40-pin header. These are the same I2C pins as on every Raspberry Pi.

Reading and writing files on the microSD card works a little differently with PiZZa than on the microcontrollers you may be used to. Expect some adjustment if you have written file-handling sketches before.

Limits to know before you start

Speed on USB power

When the Pi runs from your computer's USB port, it stays at its idle clock speed of about 600 MHz instead of 1 GHz. That is still several times faster than most microcontrollers.

  • No analog. The Pi has no analog-to-digital or digital-to-analog converter, so analogRead() has nothing to read. If you need analog inputs, add an external ADC on the I2C or SPI bus.
  • Limited PWM. Only D15 and D16 support it.
  • Board differences. The Zero W cannot do everything the Zero 2 W can.
  • Power draw. The Zero boards draw considerably more current than an ESP32 or a Pico, so PiZZa is a poor choice for battery-powered projects.
  • One core. PiZZa currently runs on a single CPU core.

Even with these limits, a board you already own becomes a fast microcontroller with plenty of RAM and storage.

Filed underTechnologyElectronicsBeginnerLearningQuick
Portrait of Julian Reed

Written by

Julian Reed

A vintage electronics restorer and hobbyist tinkerer who walks readers through soldering basics, retro console repairs, and fun weekend gadget builds.

Previous articleAdd strength training to your weight loss planNext articleFix common beginner photography mistakes before your next walk

You may also like

0 comments

    Join the conversation

    Be kind and be specific. Comments are moderated before they appear.