Third party cookies may be stored when visiting this site. Please see the cookie information.
PenguinTutor YouTube Channel

Pygame Zero for Makers

Creating novel computer interfaces for controlling electronic projects

Pygame Zero for Makers is a collection of resources to demonstrate how Pygame Zero can be used for Maker projects. This is designed for a Raspberry Pi, although can be used with other platforms. This includes using Pygame Zero as an alternative front end to electronic circuits, as well as how touch screens can be integrated into a maker project.

The overriding philosophy is that interfaces do not need to be boring.

Controlling electronics with Pygame Zero

These examples combine electronics connected to the Raspberry Pi with a fun graphical interface. The GPIO pins on the Raspberry Pi can be connected to various different electronic sensors or output devices, including LEDs, motors or a smoke generator. This is controlled using GPIO zero. The interface is a graphical inteface using virtual buttons and images which the user can interact with. This is created using Python Pygame Zero. The interface can be used with a touch screen (such as the offical Raspberry Pi touch screen) for a touch interface, or a regular screen using a mouse.

The worksheet example goes through simple switches and LEDs connected to the Raspberry Pi, but also show a bargraph, speedometer and how electronics in a 3D printed house can be controlled using Pygame Zero. This includes Christmas LEDs, a colour changing snowman and a smoke generator including in the building chimney. The building is created in approximately G-Scale so is suitable for use on an outdoor model railway. This is also included in the supplied source code.

The buttons used are created using Blender, but any other image files can be used. I've created a video tutorial to getting started with Blender.

Workshop Worksheet

The Pygame Zero for Makers worksheet was created for the UK 3D Printer meet-up 2019.

It is a hands on workshop that creates a graphical interface to control some simple electronics. This is used to create the electronics.py demonstration.

Screenshot of the Pygame Zero for Makers electronic GUI for the Raspberry Pi

The worksheet is designed for use on a regular sized screen (minimum 800 x 600 pixels). The video example shows how it can be used for the Raspberry Pi touchscreen. Source code is included for both examples.

Other demos / resources

The rest of the code shows examples of how Pygame Zero can be used to make novel interfaces.

pgzero-demo.py - Provides a demonstration of creating buttons and LEDs which doesn't need any external electronics.

Demonstration of pygame zero Button and LED

pgzero-demo-sml.py - Is a smaller version of the pgzero-demo. It is designed to fit onto the official Raspberry Pi 7inch touch screen.

bargraph.py - Shows a simple bargraph display similar to one you may use on a volume control display

Bargraph created using Pygame Zero

bargraph-speed.py - Shows the bargraph alongside a speedometer type display. These show the same value, but damping is used on the speedometer to make if feel more natural.

Pygame Zero interface providing bargraph and speedometer

house.py - provides a very different look to most other interfaces. In this case used to control the Raspberry Pi Christmas House that I used in an earlier project Model railway Christmas House project.

Pygame Zero House novel interface with GPIO Zero electonics, NeoPixel and smoke generator

You may also be interested in the Space Asteroids game that I created using Pygame Zero and GPIO Zero along with images created in blender.

Download Pygame Zero Makers Worksheet and code

Future projects

I'm always working on new projects
To find out about the updates please:
Subscribe to the PenguinTutor YouTube Channel
and
Follow @penguintutor on Twitter

Previous SnowPi RGB Python Game
SnowPi RGB Python Game
Next Space Asteroids Game
Space Asteroids Game