PCB badges have exploded in popularity in recent years. Starting out as a fun token of entry to a conference, they’re now being developed by all manner of independent groups, with DEFCON serving as the heart of the #badgelife movement. After DEFCON 26, Kate Morris and associates decided to undertake the development of their own badge, to celebrate the 50th anniversary of the Apollo landing. Kate’s talk at the 2019 Hackaday Superconference serves to tell the tale of creating a retro game to run on a badge platform.
The benefit of creating your own badge from the ground up means that you can select hardware that’s perfectly suited to your end goals. Given that Kate’s team wished to recreate Lunar Lander, they wanted some serious grunt so their game could have fancy graphics and smooth animations. To this end, an ESP32 was selected as the heart of the build, running at up to 240MHz — blazing fast as far as microcontrollers go. The badge would also need an appropriate display, with a color LCD with 320×240 resolution being chosen to do the job. A smattering of LEDs and buttons were designed in, along with the obligatory SAO port for the fans out there.
Kate begins the talk by exploring the hardware and toolchain used, with a special emphasis on project management. Software takes ages to write, so it pays to get a head start while the hardware is still in development. Waiting for final PCBs to ship wastes valuable coding time, after all. Coding for the Lunar Lander game began with a bunch of Adafruit parts laced together on a breadboard so the software team could get out ahead of the game. Code was written in C/C++ in order to maximise performance for smooth animation, with an aim to making the game play with a proper arcade quality.
The talk touches on several techniques used to achieve this. Direct processor calls were used where necessary, and spin loops were used instead of delays to avoid stutter, and to prevent issues with button polling and Bluetooth connections. Kate gave a shoutout to Charles Lohr, who preceded her talk with one covering the value of lookup tables. These were used in the Lunar Lander code to avoid time-costly floating point calculations for things like rotating the lander vehicle. There’s also discussion of where best to store bitmap data, and how to get clean readings out of the onboard hall effect sensor (hint: averages!).
Rather than using raster techniques like animating with sprites, the game works with vector code. This involves drawing lines, circles, triangles and so on to represent the various game objects. Careful management of the drawing code is necessary to avoid unsightly flicker or jerky movement, and Kate goes into detail on how this was achieved. There’s plenty here to teach the budding game developer, such as how to handle coordinate transformations efficiently, as well as basic scrolling methods.
Communication also threw up some hurdles for the team. While the Bluetooth functionality isn’t essential to gameplay, it helps run the high-score table that allows players to share their data with friends. Badges that interact are always a great way to create socialisation at cons, so the team paid special attention in this area. The multi-core nature of the ESP32 plays a role here, as well as techniques used to repartition the storage to best fit all the necessary data for the game and supporting code.
Finally, Kate shares her thanks with the wider #badgelife community. It’s a group that’s always happy to chat and share advice and commiserations when things don’t quite go right. Plus, it’s fun to share projects with a huge number of hackers from all over the world who get just as excited about blinky LEDs and artistic PCBs as you do. Often, talking with others is a great way to get perspective on the debugging process, or discover little-known tricks or pitfalls that can get you unstuck when you hit a brick wall.
Kate’s talk serves as a great intro to anyone eager to develop their own badge, or those wishing to get into software development for existing platforms. There’s files up on Github too, for inquisitive minds. We can’t wait to see what bling Kate’s crew brings to the next big con, and we’re always on the lookout for other exciting badge hacks, too. If you’ve got one, drop us a line – and we’ll see you out on the con floor!