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. The instructions below assume you're using a Raspberry Pi running Raspberry Pi OS, but if your setup is Linux based the process should be very similar. 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.
Install the build tools:
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlibDownload the Pico SDK:
git clone https://github.com/raspberrypi/pico-sdk.git ~/pico-sdkSet the
PICO_SDK_PATHenvironment variable on your system:echo 'export PICO_SDK_PATH="~/pico-sdk"' >> ~/.bashrcLog out, log in (or
sudo rebootyour 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.
Download our PicoSystem SDK:
git clone https://github.com/pimoroni/picosystem.git ~/picosystemCreate a build folder:
mkdir ~/picosystem/buildBuild the examples (if you're using a Pi 4, you can
make -j4to use all the cores and make things go a little faster).cd ~/picosystem/build cmake .. makeYou will now have the example projects built in
~/picosystem/build/examples. You can copy the.uf2files 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.
We've created a boilerplate template to make setting up a new C++ project super simple.
Download the boilerplate into a new directory, to keep things tidy:
git clone https://github.com/pimoroni/picosystem-boilerplate.git ~/ourproject
cd ~/ourproject
(we're calling our directory ourproject, but call yours what you will!).
This new project directory will contain a few different files, but the ones you'll be primarily concerned with are:
CMakeLists.txtcontains instructions to the compiler and linker about how to build the project. You will need to change the options in here if you want to change the project name or set high level options like resolution or turning the splash screen on or off. By default PicoSystem will build the project inpixel_doublemode, which gives us a resolution of 120x120 pixels and will mean we get lovely retro-vibe graphics.main.cppcontains the source code for our project - this is where your game code will go and where the magic will happen!
Open up main.cpp in an editor (on a Pi, you can nano main.cpp) and add some simple code to draw on the screen.
#include "picosystem.hpp"
using namespace picosystem;
void init() {
}
void update(uint32_t tick) {
}
void draw(uint32_t tick) {
pen(0, 0, 0);
clear();
pen(15, 15, 15);
text("Hello, world!", 0, 0);
}
Then, as we did with the examples, create a build directory for the compiler
to output into and tell it to build our project.
mkdir ~/ourproject/build
cd ~/ourproject/build
cmake ..
make
Once completed there will be a .uf2 file in your build
directory (by default it's called my_project.uf2). Put your PicoSystem into DFU mode and copy it over.
Search above to find more great tutorials and guides.