Blog

Programming a PLC to be a Game Console

Programming a PLC to be a Game Console

PLC Code

This past week, I took on the challenge of turning one of our IO demo kits connected to a Siemens PLC into a working game system. I chose to program the classic games Bop It and Simon Says as they would be easy to understand while still presenting their own challenges in both programming and playing.

I first created a simple infrastructure that would allow users to select which game they would like to play using one of the two colored push buttons on the IO kit. I associated each game with a different LED flash sequence to indicate which game had been selected.

Physical IO trainer used for BopIt game

The first game I decided to tackle was Bop It. In place of the original game’s “Twist it,” “Pull it,” etc., I used the IO kit’s toggle switches and push buttons.  I wrote a simple logic sequence that would randomly illuminate one of the four colored LEDs and wait for the user to press/toggle the corresponding button/switch. Like the original game, if the user waited too long or selected the wrong button or switch, they would lose the game and the program would play a failure LED sequence and return to the game selection sequence. After enough correct button pushing and switch flipping, the program would display a winning LED sequence and return to game selection.

Simon Says used similar code but with a few differences. These changes were needed due to the game’s sequence, stored using an array, which would be flashed by the LEDs then input by the user. The LED flash was accomplished using a counter up to the current length of the sequence, reading the index of the array at the current count and flashing the corresponding LED. The user input used similar logic, comparing the user’s selection to the array after each button push or switch flip. After successfully repeating a sequence of 10 LED flashes the program displays the winning sequence and returns to the game selection.

User Interface

I created a project in Ignition to graphically display the state of the game and monitor some key statistics. This endeavor added some useful functionality to the PLC code through the powerful tools provided by Ignition Perspective.

Main Ignition screen for Bop It game

The perspective session has three main views: an overview screen and two screens for the games. It is set up so that additional games can be added easily. The overview screen offers navigation to both games, as well as a leaderboard and a popup that explains the games. Each game screen displays a brief description of the game, the status of each digital output, and the player’s current progress. Additionally, a timer shows the player how much time is remaining to make a move, a feature that is not available on the physical kit. Each game screen displays the current high score for that game. This data is pulled from a PostgreSQL database of player initials, scores, and dates. This database is also used to populate the leaderboard.

Leaderboard used to show Bop It and Simon Says high scores

This project utilizes several of Ignition’s powerful features. Perspective can pull data from the PLC with OPC tags. These tags are then used with both built-in and custom graphics, in combination with Ignition scripting to display the status of the game. Ignition also connects to the database to create the leaderboard and high score features, through additional scripting and SQL queries. Additionally, popups are used in combination with scripts and event handlers to provide a seamless navigation experience for the user. This project uses one PLC, one database, and six windows, but these features can easily be applied to much larger automation applications.

Currently, the Perspective session only reads data from the PLC. An interesting next step could be to use Ignition to write to the plc, maybe with inputs more realistic to Bop It (i.e. twisting and pulling). This project takes advantage of some of the functionality of Ignition, but there are numerous other features that could be utilized for additional functionality.

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts