The Arduino platform is probably not the first to come to mind for projects involving 3D animation, thanks to its focus on real-time control and sensing. While that leaves many looking for alternatives, for others it proves a challenge: is it really possible to squeeze a functional 3D engine into the Arduino Uno, with its 2KB of RAM and 16MHz clock speed?
Michael Rule is one of those who took up the challenge, and a hundred hours after beginning his project he has an answer: yes. Having found existing projects designed to use a low-cost colour liquid-crystal display (LCD) shield struggled to render animations smoothly, Michael went back to the drawing board. The result: a library for the ILI9341 LCD driver used in the shield which solves the problem of flickering and tearing typically seen on Arduino 3D rendering projects.
The problem stems, Michael explains, from a lack of memory and processing grunt. "There simply isn't enough processing power on the Arduino to render anything significant within one frame length, and isn't enough memory to perform off-screen rendering," he laments in his write-up of the project. "The ILI9341 supports a 16-bit RGB color interface with 320x240 pixels, and buffering even a single frame would take 150 kilobytes of memory, compared to the ATmega328's two kilobytes of RAM." The solution? A technique dubbed "incremental hand-over-hand erasing," in which subsequent frames are drawn over the top of the existing frame and only the pixels that have changed between the two are erased. This technique still needs memory to store the two frames for comparison, though, and Michael found a clever way of increasing the RAM available: using the low-order pixel bits of the colour data stored in the display controller itself.
By rewriting the driver to allow both writing to and reading from the ILI9341's pixel data buffer, Michael has been able to create smooth, solid 3D animations. While his optimisation techniques will be accessible only to those with a solid grounding in programming and mathematics, the Arduino Sketch he has written is available to all as a basis for adding 3D rendering to their next Arduino project and a reminder of just what you can do in 2KB of RAM and a 16MHz processor.
There's a lot of room to develop this further as a project. There are plenty of optimization puzzles to solve to accelerate graphics rendering. It would be cool to implement Phong shading, or implement a basic 3D game like Spectre. Supporting other LCD drivers or Arduino models besides the Uno could also be an interesting challenge. And of course, maybe we can eventually return to the problem of rendering animated GIFs on the Arduino.