Wand Pong – Software
Friday, December 12th, 2008Software Development
While working on the development of the pixel grid hardware, we were simulteanousely developing a series of software tools to that would give life to our creation as well as give us the ability to rapidly develop software for the platform that we were creating.
Serial Communication
From the beginning of the project we knew that we needed to drive the hardware device with visual data that would be generated on an external computer. While it would be possible to write the software on the microcontroller itself, we were concerned about performance issues that may arise from having both application and display logic running on the same device. In addition, splitting out the software development environment from the hardware microcontroller allowed us to develop application code without the need for a working hardware device at our disposal.
Our first attempt at setting up serial communication utilized a simple call/response methodology. First, the microcontroller would contact the computer via a serial connection with a predetermined string of bytes. The software on the computer would respond with another predetermined string of bytes, and after which the computer would begin to send display data to the microcontroller using a series of bytes. We decided to attempt to take full advantage of the fact that the TI5940 chip supported PWM, so we started by sending a full byte of information per LED. This would yield a maximum possiblity of 256 different value per color, giving us a whopping 16 million possible colors per pixel.
Of course this didn’t work.
We found that sending this much data (243 bytes per frame at 30 frames per second) was beyond the ability of the serial connection. On top of this, we quickly realized that our call/response methodology was inadequate for this purpose – we needed a way to keep the display in sync with the computer in order to prevent dropped frames and ensure that the display was always in sync with the driver software. We established a new protocol that works as follows:
- Computer sends: ping? (later shortened to “p” to help improve the data transfer rate)
- Arduino receives: ping?
- Arduino sends: pong! (later shortened to “o”)
- Computer receives: pong!
- Computer sets a flag that indicates that it’s OK to send data. The program is allowed to caluclate the next frame of display data.
- The next frame is broken down into bits based on color values. For our example we broke down each pixel into three bits – red (on/off), green (on/off) and blue (on/off). These bits are packaged into bytes and are sent to the Arduino at the end of the frame calculation cycle.
- Arduino recieves: specified number of bytes and uses a series of bitmasks to extract the color values for each of the TI5940’s output pins. The Arduino then updates the display accordingly.
- Arduino sends: “success” to indicate that the display has been updated
- Computer receives: “success” and sets a flag to indicate that the microcontroller is ready for another set of bytes. This flag permits the system to generate another frame of visual data, and the process repeats itself.
This process worked great, and kept the display in sync with the computer. Once the basis of this system was in place we went ahead and tweaked the serial baud rate to increase performance, and at 56kbps we were able to achieve almost 30 frames per second of video on our display.
Grid API
In order to extend the functionality of the Wand Pong project, we wrote a grid API object that provides a standard means of interacting with our hardware device. Written in Processing, this API object provides a basic toolset for the setting, clearing and loading of pixel data between a sketch and the display. The API is fully integreated with the call and response serial protocol outlined above, which allows the end programmer to focus on creating applications rather than worrying about the mechanics of how to send visual output to the display.
Human Interface
Now that we had the ability to drive the display and had a standard framework in place for software development we were able to focus on human interaction. We toyed around with a few ideas, but the standard ones that came to mind (buttons, force sensors, IR beams, etc) seemed to lack something. We wanted to try and capture the “fun” of multicolored ping pong balls, so Bryan took the lead and developed two wands that light up using green and blue LEDs.
We borrowed some previous work we made on the augmented reality display to track these colors using a live video feed. The goal was to use these wands as a simple way to physically interface with the display – a webcam would be mounted on the top of the display which could determine if a wand was in it’s field of view. If it was, we would enter into an interactive mode of play, namely the classic game of “Pong!”










