how I recreated pong on my ESP32 (part 1)

Last month, I decided to venture into the world of embedded programming, bringing some of my software knowledge closer to the hardware itself. I’m going to walk you through some of the stuff I learned to get this game fully working. But first, what is embedded programming?
Embedded programming is writing software for specialized computer systems, and it’s primarily concerned with tight hardware integration. This range is quite large. It can look like programming a clock on a microwave, or a navigation system on a fighter jet. Given that this is my first real foray into embedded, I decided to stick to something microwave-esque :)
As mentioned earlier, all embedded work revolves around hardware, so let’s start there.
The Hardware
There are three main components I’d like to highlight:
- ESP32 (microcontroller)
- 0.92" OLED screen (128 × 64)
- Breadboard
The ESP32 is a microcontroller containing a CPU, RAM, I/O, and flash storage. Essentially, it’s what allows you (the programmer) to actually execute your code. Unlike a laptop or desktop, this thing runs one program, very close to the metal, with tight memory and performance constraints.
The screen is relatively straightforward. It’s a screen. It has four I/O pins: GND, Vin, SCL, and SDA. It communicates using the I2C protocol, which is a common two-wire communication standard in embedded systems. This means multiple devices can share the same data lines, as long as they have different addresses.
The breadboard is kind of the glue of this whole operation. A breadboard is a prototyping tool used by embedded and electrical engineers alike. It lets you create electrical connections without soldering everything together, which is extremely nice when you’re experimenting or inevitably messing things up.
One cool thing I learned from working with the breadboard is daisy chaining. This is when you essentially “chain” electrical connections together using wires (in my case, DuPont cables), allowing you to make more connections from a single point. This is especially helpful when you have a limited number of jumper wires, which I absolutely did.
The Software
I took a somewhat unconventional approach here. Normally, most embedded work is done in C or C++, but I went with Go. More specifically, I used the TinyGo compiler, which is optimized to create small, efficient binaries for microcontrollers.
Why? Because I wanted to learn some Go. lol
Since this is embedded programming, we have to write our software specifically for our hardware. Here’s one example. The screen I’m using is 128 by 64 pixels. That means the display contains 8,192 pixels total.
So for every screen refresh, I’m essentially updating an array representing all 8,192 pixels.
const (
SCREEN_WIDTH = 128
SCREEN_HEIGHT = 64
)
TinyGo’s machine library, is the main libary I used to actually interact with the hardware, here are some of the neat things you can do with it.
- Configure the pins for I2C communication

- Draw individual pixels on the screen

Example Drawing player 1’s paddle
Going back to the idea of embedded being far closer to the hardware, drawing Player 1’s paddle is literally just flipping specific pixels on and off in the correct columns and rows. There’s no concept of “sprites” here. Everything is manual, which really forces you to think about what the hardware is actually doing.
That’s all for now! Next time, I’ll dive deeper into the software, discussing how I got collision detection working, and made an AI to play against.
Originally published on Medium.