Getting started with PicoSystem and C++

This guide will show you how to get started programming your PicoSystem using our PicoSystem C++ API. PicoSystem is a pocket sized handheld games console, built around Raspberry Pi's RP2040 chip (that's the little fella that's the core of a Raspberry Pi Pico).

The PicoSystem C++ API is intentionally designed to be lightweight and get out of your way when you're developing games for PicoSystem. It has around 40 functions to provide access to the hardware and help with drawing, audio, and user input. It's separate from the rest of our Pico drivers/libraries, to keep it super slimline.

Once you're familiar with the process of building your project for PicoSystem you may find our PicoSystem API Cheatsheet a useful reference to keep handy.

Before we start

First of all we need to install the Pico SDK from Raspberry Pi. This provides all of the useful bits and pieces needed to make the most of the RP2040 processor.

We've found that setting up the Pico build chain is most straightforward on a Raspberry Pi or other Linux computer. If your setup is Linux based you should be able to follow the simple instructions below to get started. For more detailed instructions and how to build Pico/RP2040 projects using other platforms we'd suggest taking a look at the Raspberry Pi Getting Started Guide (or, for more technical info, the C/C++ SDK docs).

If you're building on a Pi, we'd recommend using a fresh image of Raspberry Pi OS and doing a sudo apt update before starting to make sure your package lists are up to date.

  1. Install the build tools:

    sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
    
  2. Install the Pico SDK:

    git clone https://github.com/raspberrypi/pico-sdk.git ~/pico-sdk
    
  3. Set the PICO_SDK_PATH environment variable on your system:

    echo 'export PICO_SDK_PATH="~/pico-sdk"' >> ~/.bashrc
    
  4. Log out, log in (or sudo reboot your Pi) and you're done!

Installing the PicoSystem SDK

Now we have everything ready we can download the PicoSystem SDK and build the example projects to prove that everything is working.

  1. Install our PicoSystem SDK:

    git clone https://github.com/pimoroni/picosystem.git ~/picosystem
    
  2. Create a build folder:

    mkdir ~/picosystem/build
    
  3. Build the examples (if you're using a Pi 4, you can make -j4 to use all the cores and make things go a little faster).

    cd ~/picosystem/build
    cmake .. -DPICOSYSTEM_DIR=/home/pi/picosystem
    make
    
  4. You will now have the example projects built in ~/picosystem/build/examples. You can copy the .uf2 files in this directory directly to your PicoSystem while it is in DFU (Device Firmware Update) mode.

Booting PicoSystem into DFU mode

If it's not plugged in already, connect your PicoSystem to your computer. Hold down the X action button and toggle the power. PicoSystem will boot into DFU mode and appear as a disk on your computer, called RPI-RP2.

If you're using a GUI, you should be able to drag a .uf2 file onto the PicoSystem disk and it will be uploaded and launch immediately.

If you're using a Raspberry Pi and are logged in via SSH you might find that your PicoSystem doesn't mount as a drive automatically - section 3.2.2 of the Getting Started guide will show you how to mount it manually.

Creating your first PicoSystem project

Examples are all well and good but the real fun starts with creating our own games and demos.

The most basic PicoSystem project consists of just two files:

  • CMakeLists.txt contains instructions to the compiler and linker about how to build the project.
  • ourproject.cpp contains the source code for our project.

We'll put these files in a new directory to keep things tidy:

mkdir ~/ourproject
cd ~/ourproject
touch CMakeLists.txt
touch ourproject.cpp

We now have a freshly baked directory containing two empty files.

Open up CMakeLists.txt in an editor (on a Pi, you can nano CMakeLists.txt.) In this file, add the following boilerplate code (this is the instructions how to build the project):

cmake_minimum_required(VERSION 3.12)

# Pull in PICO SDK (must be before project)
include(../picosystem/pico_sdk_import.cmake)

project(ourproject C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

find_package(PICOSYSTEM REQUIRED)

picosystem_executable(
  ourproject
  ourproject.cpp
)

pixel_double(ourproject)
disable_startup_logo(ourproject)

While the above may look a bit alien most projects will work just fine by replacing ourproject with your project name throughout.

One thing to note is that we've asked PicoSystem to build the project in pixel_double mode. This gives us a resolution of 120x120 pixels and will mean we get lovely retro-vibe graphics.

And put this code in ourproject.cpp (this file is where your actual program will go):

#include "picosystem.hpp"

using namespace picosystem;

void init() {

}

void update(uint32_t time_ms) {

}

void draw() {
  pen(0, 0, 0);
  clear();

  pen(15, 15, 15);
  text("Hello, world!", 0, 0);
}

Then, as we did with the example create a build directory for the compiler to output into and tell it to build our project.

mkdir ~/ourproject/build
cd ~/ourproject/build
cmake .. -DPICOSYSTEM_DIR=/home/pi/picosystem
make

Once completed there will be a file called ourproject.uf2 in your build directory. Put your PicoSystem into DFU mode and copy it over.

That's all folks!

Search above to find more great tutorials and guides.

Plasma 2040

Swathe everything in rainbows with this all-in-one, USB-C powered controller for WS2812/Neopixel and APA102/Dotstar addressable LED strip.