← Back to list

Interactive Devices: Space Explorer Game

Introspective Python game built with the pygame library that utilizes ESP32, potentiometer, joystick, and button hardware.

Alec Mildenhall · 2022-03-21 02:54 · 0 claps · 3.5 min read
#esp32 #arduino #python #pygame #interactive-devices
Open on Medium ↗
Wiki topics: 📟 · Gadgets & IoT 🔭 · Astronomy & Space 📚 · Books & Reading

Interactive Devices: Space Explorer Game

Space Explorer interactive device

Space Explorer interactive device

Link to documentation, setup instructions, and code can be found here:

[embed]GitHub - alecmildenhall/Space-Explorer: Python game created using pygame that works with ESP32… Python game created using pygame that works with ESP32, potentiometer, joystick, and button. …github.com

The Task: I wanted to create an interactive device that would send data back to a media generation process using an ESP32 TTGO T-display, battery, button, joystick, and a potentiometer. I wanted create an enclosure for this device and connect it to an ESP32 which would run a program that collects sensor data and send it over a serial a laptop running some media generation program handling the data.

Bringing the Artistic Vision to Life: I also wanted to make a device that gave the user control, and given the joystick, the first thing that came to mind was a game. I knew I would control the player with the joystick, but I still had to figure out what functionality I could build in with the potentiometer and button — as well as what game to build!

Before I could start any of that though, I had to assemble my hardware. This required using wires to connect the hardware to different pins of the ESP32 (more specifics can be found here). I then attached the software to a cardboard box such that only the interactive interfaces of the hardware would be exposed to the user once it was closed. In hindsight, I would prefer to make a much cleaner inside of the enclosure such that faulty hardware could be easily fixed and replaced.

Inside of enclosure ft. ESP32, joystick, potentiometer, and button

Inside of enclosure ft. ESP32, joystick, potentiometer, and button

Once the hardware was physically setup, I had to make sure I could interpret the values it was generating and communicate it to another program. This required writing an Arduino program (found here) that ran on the ESP32. The program reads from the specified ports where hardware is connected and then translates those values into something useful for media generation. These transformed values are then printed to serial in JSON format.

When developing the hardware setup, I ran into issues wiring and interpreting the values from the potentiometer. I recommend using female to female wires for all connections where possible to prevent these issues likely caused by bad soldering. If erroneous values continue to show, I also recommend filtering out the values in your Arduino program.

Portion of space-explorer.ino Arduino program discussed

Portion of space-explorer.ino Arduino program discussed

Next was to create the game. I had some experience communicating with hardware using Python, so I decided to create the game in Python using the pygame library. After scouring through a few tutorials using the library, I created a game where the player icon, a white rectangle, had to dodge enemies, smaller white rectangles, against a black backdrop as the screen seemed to scroll. When the player hit an enemy the program would quit. The visuals gave me this very introspective space-like feel which I decided to run with.

The white rectangle among other white rectangles

The white rectangle among other white rectangles

The joystick controls the movement of the player, the potentiometer controls the speed in which the player moves (or seems to move, in actuality it speeds up/slows down the enemies around you), and the button “stops time,” as long as it’s held down, the player and the enemies are frozen. The entire game is set to a digital-intergalactic beat (Space Ambience by Alexander Nakarada¹) and when the player collides with an enemy a randomized quote relating to space exploration is displayed on screen for 6 seconds before the program quits. The game is called “Space Explorer”.

Space Explorer isn’t meant to be particularly challenging, nor is its player meant to achieve some goal. The game is meant to let you be with your thoughts as you travel across space, dodging the enemies semi-unconsciously. Of course, however you play the game is up to you, and I welcome any modifications to the code.

The Execution: The enclosure exposes the potentiometer, button, and joystick to the user and labels them for clarity, acting as a controller for Space Explorer.

Space Explorer enclosure design

Space Explorer enclosure design

Complete demo, showing hardware being used in conjunction with software:

[embed]

Recording of demo gameplay:

[embed]

Demo of pause feature:

[embed]

Demo of speed feature:

[embed]

¹ Space Ambience by Alexander Nakarada | https://www.serpentsoundstudios.com Music promoted by https://www.free-stock-music.com Attribution 4.0 International (CC BY 4.0) https://creativecommons.org/licenses/by/4.0/


메타데이터
post_id
2bf27f321ce0
slug
interactive-devices-space-explorer-game-2bf27f321ce0
url
https://medium.com/@alecmildenhall/interactive-devices-space-explorer-game-2bf27f321ce0
canonical_url
https://medium.com/@alecmildenhall/interactive-devices-space-explorer-game-2bf27f321ce0
author_url
https://medium.com/@alecmildenhall
status
ok
fetched_at
2026-08-02 18:16:27