You're welcome to scroll down to the physics-engine section if you like. There you will find a video and installation instructions for the Raspberry Pi (RPi). (This tale is related to the scripts and videos presented on the main tutorial page.)
Click to manage cookies. If you accept them, click a video to load; click again to play.
(Written in 2015, updated 2025; much has changed.)
From need to revitalize my stereo system came incentive to buy a first Raspberry Pi (RPi). My college-age sons had introduced me to Spotify. This amazing music resource needed to somehow get connected to a Bryston amplifier and Magneplanars that had been too quiet in recent years.
A web search yielded several solutions to this "connection" challenge where new meets old. Volumio seemed like a nice approach: headless, and with control from my laptop or Android device. The overall cost of the project was about $100:
The photo shows the DAC board stacked (on the glowing pastic post) on top of the RPi (in the shadow underneath). Both are housed in the Dog Bone case. If you look carefully, you can see the little extensions to the case's corner metal posts that I ordered to accommodate the added height of the DAC board.
It works well and with a significant step up from Bluetooth audio quality (of 2015). I like to make playlists using the Spotify client on my laptop and then access the playlists from the Volumio client. But you can also search for music directly on the Volumio client. An endless supply of new tunes...
Volumio has integrated the functionality of the old Spotify Connect plugin into the main Spotify plugin. So, it's much easier to setup now, only need one plugin, just install the main Spotify plugin that is available in Volumio. Playlists are accessible via a Spotify client running on a laptop, tablet, phone, etc. You do this by using the "Connect to a device" feature in the Spotify client. This renders (casts) your choices (e.g. pick a song, start a playlist,...), in the Spotify client, onto to your Raspberry Pi which is the hardware host for Volumio.
It seemed like only seconds after I put down my cash on the RPi-1-B+ that the new and improved RPi-2 was announced. Wow, a promising six-fold improvement in performance and a new incentive to buy. Instead of encouraging me to listen to new tunes, this RPi-2 would be making objects move on its screen and hopefully at frame rates that provide a smooth and stable rendering.
The video here shows that, yes, RPi-2 and its 900MHz ARMv7 CPU and VideoCore IV GPU are enough for the job. This was taken using a camera aimed at the RPi's display (note that software-based screen-capture methods burden the RPi-2 and reduce framerates). The script file running here is A16c_2D_B2D_serverN.py (see corresponding topic on Using Pybox2d in Our Framework from the main page).
Most recently, upgraded to a RPi-5 featuring a 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, along with an 800MHz VideoCore VII GPU.
First, I'll ask you to run a script on your RPi-5 and interact with the objects in the Pygame window. Most of these scripts will work with only Python and Pygame installed. (Note: to run the A06, A07, or A16 scripts, you'll need to follow the installation instructions for the Conda environment in the following section.)
From a web browser on your RPi, download a copy of the github repository for these python files. Look for the green "code" button, click it and use the "Download ZIP" option.
Code repository: https://github.com/m-jim-d/pet-code
From the RPi file manage, naviagate to the downloaded file and right click it and use the "Extract Here" option.
Then from a terminal window on the RPi-5:
cd ~/Downloads/pet-code-main
python A15a_2D_finished_game.py
Note that a wildcard character (*) is helpful for typing these long filenames. For example, the second line can be typed using the much shorter command:
python A15a*
Now it's time to use your keyboard and mouse to interact with objects in the Pygame window.
python A10_2D_baseline_client.py 192.168.1.197
The parameter at the end of the command is an example IP address. You'll
need to provide the actual address of the computer hosting the
A15a_2D_finished_game.py script (or any of the server scripts). It will print its IP address in the
command window immediately after starting. In the video, you'll see a
second cursor acting to manipulate objects. That's a client computer
which has connected to the RPi server. In the video, I'm working both mice, left and
right hands... The RPi-5 has plenty of muscle to host a Python physics engine. Its modest cost opens all this to teaching/learning environments that are not as well funded as a college J-term course: a high school, a community center, or even a church looking for a way to share its message and give the gift of learning to its parishioners and neighbors in its area.
This guide walks through installing Miniconda and the physics/graphics packages on a Raspberry Pi 5:
Python and Pygame may already be on your RPi. Installing this Conda environment is optional, only needed if you are running the A06, A07, or A16 scripts.
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh
chmod +x Miniconda3-latest-Linux-aarch64.sh
./Miniconda3-latest-Linux-aarch64.sh
Create a new conda environment with Python 3.11 (recommended for best compatibility). Run these commands, one by one:
conda create -n physics -c conda-forge python=3.11 pygame box2d-py
conda activate physics
pip install pygame-pgu
This installs:
After installation, you can verify the packages are installed correctly:
conda list
Now, try running the A06 or A07 scripts from the box2d-pgu environment. These have a gui interface and depend on pgu.
python A07*
Next, try running one of the A16 scripts. These use Box2D and depend on box2d-py. For example, A16c is the Box2D version of the final game script.
python A16c_2D_B2D_serverN.py