picc3200tionary
real-time drawing game implemented on TI CC3200
disconnected from game server...
about the project
table of contents
- overview
- design & system architecture
- implementation
- circuit wiring
- challenges & pain points
- future work
- bill of materials
- demo video
- resources & downloads
project overview
For our final project, we created an internet-connected drawing and guessing game called picc3200tionary. The game is a simplified version of Pictionary, where one player has to draw a prompt given to them, and the other player must input their guess in 60 seconds using the IR remote. The drawing is done using an external accelerometer by rotating it around its axes, and the drawing player can change the color of the marker using SW3 and cycle through cursor-marker-eraser (draw white) using SW2. The drawing is also broadcasted LIVE to the guessing player’s board, as well as on the website. If the guessing player inputs a guess, the game transitions to show a score state, where 10 points are awarded for a correct answer. The mode switches on both boards, so then the previously drawing player now has to guess the other player’s drawing, and vice versa. Audience members can view the game in real time via the website, and can send comments that broadcast onto the players' OLED displays as well as other audience members on the website.
design & system architecture
Our system architecture is built around the premise of a two player game with each player on a CC3200, and a theoretically unlimited size set of audience members. Each actor is synchronized with a server that handles the ground truth for game state and inter-device messaging logic.
Each player has their own device, with a CC3200 at the core, an external accelerometer to handle drawing, an IR circuit and TV remote for text input, and an OLED screen for displaying the game, drawing, UI (titlescreen, game lobby, turn change prompts, etc.). Two buttons on the CC3200 Launchpad board are used to control color palette changing and drawing mode changes (cursor, marker, eraser) during gameplay.
Below, a hardware block diagram of the player device is included, as well as a sample game flow/state diagram from the perspective of one player with annotations describing how the hardware components are used in each state. State on the microcontroller is entirely dictated by the server, except for drawing canvas updates, ready state, and guesses, which are streamed back to the server to update the ground truth. The microcontroller boots into a title screen and wifi connection state prior to the main eight states shown in the diagram, but those initial states are trivial and serve only as a setup stage.
Audience members can also join. The state handling of an audience member in principle is the exact same as on the microcontroller, however, they do not participate in the game via drawing or guessing - they can only receive incoming data to view the live drawing, live guess, word to be guessed, etc. - they can also send chat messages via the same socket interface to be displayed to other players and audience members.
Finally, the game server is described - the server handles the ground truth for all clients, and all clients (players, audience members) are expected to synchronize with the server state upon joining via either the websocket protocol or the REST endpoint. An example synchronization over websocket and REST is shown with multiple clients below:
With all components put together, the overall block diagram is:
implementation
Player Device
The microcontroller connects to the internet via a websocket client implementation, which was written to manually upgrade a socket connection. This was mostly done with the help of Gemini, due to the protocol being sufficiently complex, with poor documentation and examples on TI’s part. The data we send over the websocket connection is a simple colon-delineated text protocol.
This protocol is parsed with simple string manipulation, making it very easy and lightweight to implement with a sequential parser on the microcontroller - no JSON parsing is required.
The external accelerometer we chose is the LSM6DSOX, packaged on the Adafruit 4438 breakout board - it uses I2C to communicate with the microcontroller, and features a three axis accelerometer with three axis gyroscope for six degrees of freedom. We configure the accelerometer with sensitivity and check we can read from it at startup, but otherwise only interface with it during the drawing phase of the game. On a high level, the main loop begins with initializing the accelerometer registers, then when gameplay starts, the raw acceleration is read from the LSM6DSOX into 3 pointer variables. For the drawing player, the acceleration is adjusted with an arbitrary constant to be processed in a drag processing function, which converts the values of the acceleration coordinates to x and y position updates. Next, depending on the mode the draw is in (cursor, marker, erase), different updates are sent. If the player is in the cursor mode, the pixels under the green cursor are saved in a cursor_saved buffer so when the cursor leaves the region, the pixels that were previously under it are restored on the next iteration of the while loop. If the mode is in drawing mode, a pixel is drawn and buffered in the drawn_pixel_list. Similarly in erase mode, a larger circle of white pixels (for better erasing UI) is drawn and buffered into the drawn_pixel_list. All of these options also store the pixels in the positions_to_send buffer, which flushes periodically to the server to update the positions of pixels to color.
If the player is the guesser, then the guesser can see the drawing from the other player on their canvas in real time via the websocket connection (described earlier). The guesser uses the IR remote to input their guess, with the same cycling letter scheme as Lab 3. For responsiveness, we use a double buffered setup - the incoming data gets put into one buffer, and the data being parsed is read from the other. When a full set of bits comes in (new data), then the pointer to the current incoming data buffer swaps. This prevents most loss of data when the IR sensor is picking up new information (e.g. rapid button presses from the remote, like when cycling characters) and allows for data parsing while new data is still being partially received.
When a correct guess is sent, the current round ceases and 10 points are awarded - otherwise, the drawer can see the current guesser’s guess, also in real time. The prompts are common nouns that can be guessed easily (animals, fruits, etc) as well as prompts related to the class (microcontroller, ChatGPT, Dr. Ghiasi). The modes then switch, gameplay continues, then a game over screen is displayed at the end with the final scores. After 30 seconds, the players are put back in the lobby, where they may re-ready themselves to play again.
Above, an image of the canvas state being reflected from the microcontroller to the website is included. This image shows a state from testing, not the final product, but the concept and aesthetics remain similar.
A gallery of mockups which are used as UI on the board is also included. Note that these were done in Affinity Photo and saved as bitmap components in a header file, and some alterations were done on the board to accomodate things like color depth, stack size, and ease of drawing (e.g. using the onboard font in some locations).
Website Implementation
The website is a simple websocket client. It is built on SvelteKit and deployed as a static page on GitHub pages, making a websocket connection to the server, and parsing protocol messages exactly the same as the CC3200 or server would be doing, like updating the live pixels streamed on the canvas.
The UI and UX is handcrafted for a premium experience during gameplay.
Server Implementation
The server is written in Go, a high performance language designed for use in web servers. It features robust concurrency through a language feature called goroutines, which we use in this project. The server has a global game state, and the struct definition for that is shown below:
LobbyMaxPlayers int `json:"lobby_max_players"` // max number of players allowed in lobby AudienceUUIDs []string `json:"audience_uuids"` // uuids of spectators on website PlayerUUIDs []string `json:"player_uuids"` // indexed p0, p1, p2... players on CC3200s PlayerPoints map[string]int `json:"player_points"` // points for each player uuid Turn int `json:"turn"` // current turn number TimeLeft int `json:"time_left"` // seconds left in current turn Word string `json:"word"` // word to draw for p1 LiveGuess string `json:"live_guess"` // real-time guess from p2 LiveDrawing [16384]uint8 `json:"-"` // 128 x 128 canvas, omitted from sync API
The server accepts incoming websocket connections and looks at the user agent to determine if it is a player or audience and then adds it to the state accordingly. It keeps the connection alive with the UUID as a reference, and passes messages between clients using a broker goroutine. Messages, as described above in the CC3200 section, are a simple text protocol that can easily be parsed by any client. The protocol is as follows:
MP_Error MessageType = "e:" // <error message> /* lobby and join-related messages */ MP_Join MessageType = "j:" // <uuid>:<audience|player> MP_Leave MessageType = "l:" // <uuid> MP_Sync MessageType = "s:" // <uuid> D->H | <property>:<value> H->D | <"done"> H->D MP_Ready MessageType = "d:" // <uuid>:<0,1> /* ephemeral audience messages */ MP_Chat MessageType = "c:" // <message> MP_Rating MessageType = "a:" // <uuid>:<0|1|2> /* gameplay/state-related messages */ MP_LobbyMaxPlayers MessageType = "m:" // <max players> MP_AudienceCount MessageType = "n:" // <audience count> MP_Points MessageType = "d:" // <player_uuid>:<points> <- the same as the ready message MP_TimeLeft MessageType = "t:" // <seconds> MP_Turn MessageType = "r:" // <turn number> MP_Word MessageType = "w:" // <word to draw or guess> MP_LiveGuess MessageType = "g:" // <guessing player's uuid>:<guess> /* drawing livestream */ MP_ColorChange MessageType = "h:" // <color> (color in hex, e.g. #ff0000 for red MP_PixelStream MessageType = "p:" // <new_pixel_list>
A message is sent like s:data:data:data with a prefix and data arguments. It is validated
on the client or server before it is parsed.
When a message is received, it may be parsed by the server and affect game state (like join and leave messages), or simply be forwarded to other clients like chat messages are.
circuit wiring
The following components are required (2x each for two players):
- IR sensor
- AT&T U-Verse TV remote
- 100uF capacitor
- 5k resistor
- Jumper wire
- Adafruit SPI SD1351 OLED display
- Adafruit LSM6DSOX 6 DoF Accelerometer and Gyroscope
- Texas Instruments CC3200 LaunchPadXL
Substitutions can potentially be made but the driver and logic modifications in code to support changes are left as an exercise to the reader. Wire it up as follows:
To wire the circuit, match the pins to the diagram and table above. IR corresponds to IR, and MOSI, SCLK, etc. correspond to the OLED - all of the pin names match the silkscreen. The table can also be referenced to set up the pinmux in TI SysConfig.
challenges & pain points
IMU pencil-like drawing - tilt drawing
Our initial plan was to use an LIS3DH 3 axis-accelerometer to simulate drawing on a GPIO-driven copper surface using a “puck like” drawing scheme. However, 3 axes was not enough to figure out the logic for detecting and eliminating tilt for “drag” drawing, so we switched to an LSM6DSOX accelerometer with 6 axes to use the gyroscope and trigonometry to try and cancel the tilt. However, it wasn’t the most reliable, so we still used the LSM6DSOX for tilt, as it was more responsive and reliable than the LIS3DH, but we were unable to mount it to a pencil and just used tilt-to-draw.
IMU shipping delays and UPS troubles
We decided to use a new accelerometer midway through the project, and got expedited shipping for the LSM6DSOX to arrive on Tuesday the 2nd week of the lab. However, shipping issues, which caused it to arrive a day late. Reading documentation ahead of time and writing preliminary code for the LSM6DSOX helped us to jumpstart quickly when the accelerometer arrived and was soldered.
User interface - stack size on the microcontroller limited:
In order to keep track of the pixels drawn and send them to the server, a very large amount (128*128=16384 pixels) need to be tracked for color changes and draw updates. However, a 2D array of pixel objects (which take 2 uint8_t for the position + 1 uint16_t for the color) uses too much memory to compile. Instead, we created a 50 pixel buffer that stores the position of the pixel to update in terms of y*128+x, or a single uint_16 to store the position. The color of the pixels is sent separately and only on color changes (SW3 presses).This tells the server to flush the current buffer of old colored pixels, and start drawing the following pixels to the desired color.
No websocket client in SDK for the CC3200
The CC3200 SDK we are using (and in fact, any newer SDK) does not include a websocket client. It includes a server implementation, but only for AP mode, not STA mode as we need to connect to our server. However, it is possible to implement a manual connection upgrade using the TCP sockets provided by the CC3200 SDK. We wrote (relying on Gemini 3.1 Pro to debug and frame) a websocket client that does exactly this. It functions without TLS, as with TLS, the handshake fails - due to the time constraint we were unable to debug further and decided to just connect over the standard port 80 without TLS.
future work
We would’ve liked to implement a cursor that matches the color of the set marker color, which we didn’t end up having time for, but would provide for an easier drawing interface and simple way to see the current color to be drawn without being in marker mode. Similarly, other interface polish/improvements, like more art, an on-screen instructions page, configurable lobby settings, could be added.
We also would’ve liked to look through the accelerometer libraries further to see if a drag-to-move calculation could be referenced to perform more puck-like, realistic drawing with a pencil that the user can orient and hold naturally.
bill of materials
Many components were loaned by the lab, and as such did not cost extra money to purchase. We approximately an extra $25 after tax on the accelerometers we used. Shipping was refunded and became free due to a courier delay.
| component | cost/unit | cost | source |
|---|---|---|---|
| TI CC3200 Launchpad | - | - | Provided |
| Adafruit OLED Display (SSD1351) | - | - | Provided |
| TV Remote | - | - | Provided |
| IR Receiver (TSOP38238) | - | - | Provided |
| Passives (C,R) | $0.50 | $1.00 | Provided |
| Breadboards & Jumper Wires | $2.00 | $4.00 | Pre-owned |
| Adafruit 4438 (Accel) | $11.95 | $23.90 | Mouser |
demo video
We showcase a demo video with a round being played. If you are viewing this on the printed PDF copy of this report, please view this video on the website at https://app.ivy.direct/picc3200tionary.
resources & downloads
source code (zip): download here