• Medium One

DIY Whack-a-Mole with Medium One Workflows and Samsung ARTIK

AUTHOR:  Marty Fabry

At Medium One, we love making things.  Here is something we made to show off our real-time python workflows working together with Samsung ARTIK IOT modules.  In this blog post, we’ll show you how to make your own Whack-a-Mole-style arcade game, using the Samsung ARTIK 10 module as the local game controller engine and the Medium One workflows to drive the real-time game logic, game statistics, web page updates, user communication and more.

What you’ll need

To construct two game boards, you’ll need the following set of materials:

  1. Samsung ARTIK 10 Circuit Boards

  2. Medium One Account with Edge Analytics (see below for activation link)

  3. Game Boards

  4. ¼” thick polycarbonate for game boards (4 pieces total, 1 top and 1 bottom plate for each board)

  5. CAD for Top Board

  6. CAD for Bottom Board

  7. 26 Arcade-style LED Push Buttons (we used these)

  8. 2 50-pin-wide ribbon cables

  9. 12 3″ metal standoffs

  10. 24 1/2″ length metal fasteners with washers, 1/8″ outside thread diameter

  11. Self-adhesive vinyl sheets for logo decal sticker

  12. Velcro strips to secure boards to table/playing surface

  13. Bread Boards

  14. Circuit diagram

  15. 2 SN74HC595 integrated circuits

  16. 2 SN74LS245N integrated circuits

  17. 2 TC74LS148N integrated circuits

  18. 2 Ribbon Cable‐to‐breadboard adapter, 50‐pin (we used these)

  19. 2 Breadboards (we used Philmore Proto-board Model rh32) and wiring kits

  20. 1k ohm resistors

Construct your Game Boards

Each game board is made up of two hexagonal plates of polycarbonate plastic. The top plate has 13 1 inch holes for our 13 buttons. In each board there are 6 mounting holes for the screws that connect the two boards.

We took our CAD design to TAP plastics, who provided the polycarbonate plates and cut and drilled them to our design specifications.

shiny new boards ready to be unwrapped!

top board

bottom board

Our buttons are arcade style buttons with two functions: the LED light and the button switch.

lights and press buttons

assembled button in board

We assembled the buttons and placed them in the top plate of the game board.

To connect the breadboard to the buttons, we used a 50 pin wide ribbon cable such as is used in IDE hard drives. We stripped one side of the cable, and soldered it onto the individual switch and button terminals.

  1. Note 1 – The LEDs only light up with voltage applied in one direction only, so keep your supply and ground connections consistent

  2. Note 2 – Since the ribbon only has 50 wires, and we actually have 52 total button terminals (26 x 4), we “borrowed” ground for the center button from a neighboring one with common rework wire

The other side of the cable connects to the breadboard.  After the soldering, you can connect the two plates of the game boards.

soldering on button terminals

completed cable soldering

ribbon cable connected to breadboard

The boards may shift around if players get really enthusiastic with their whacking technique, so you will probably want to secure them to whatever surface you are using to play. We used Velcro strips for this.

Connect your ARTIK module

The ARTIK 10 has 10 GPIOs. We have 13 buttons, each with two functions (light and button press). We want to read the button presses from the game board (input), and control the lights from the ARTIK (output).

To get these 26 input and output signals through the 10 GPIOs, we have implemented a port expansion circuit on the breadboard. The port expansion circuit maps each GPIO to a particular set of chips on the breadboard.

Below is what the complete breadboard should look like.

Connect ARTIK to Medium One cloud

Set up your ARTIK 10 to connect to the Medium One IOT development platform by activating it here, and following the instructions on the Medium One ARTIK Quick Start Guide to set up the Edge framework.

When you activate your ARTIK 10, a new Medium One project will be created for you, that will contain some default workflows. You will also be sent a config file, mediumoned.conf (attached to activation notification email). This file contains your assigned Medium One username (‘myuser’), auto-generated password (e.g. ‘8ixwUoab’), and API key. 

Project Name

If you already had a Medium One account with the same email, navigate to this project by clicking on the dropdown menu next to the little building icon in the top right corner of your Sandbox account.  Your Medium One project will be named whatever you put in the Project Name field when you filled out the Activate your ARTIK form.

If you didn’t already have a Medium One account, then this will be the default project you see when you log in.

Add New Data Streams

We need to add a couple of new data streams for the game workflows. In your Sandbox account, go to Config > Data Streams , and click on Add New Stream.

Add the following new streams :

  1. game_stats

  2. player_registration

  3. text_messages

  4. event_log

Go back to your terminal, and run the commands below to send the tags we’ll need for our ARTIK Whack-A-Mole workflows to Medium One. (Note: myuser is the API basic username that is automatically created as part of the Medium One project).

curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/processed/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"action_start_of_game":true}}'
curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/processed/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"action_whack":true}}'
curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/processed/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"action_end_of_game":true}}'
curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/game_stats/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"game_id":"game_id"}}'
curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/raw/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"page_refresh":true}}'
curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/player_registration/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"player_name":"player name"}}'
curl -b cookies.txt -X POST -k -H 'Content-Type: application/json' -i 'https://api-sandbox.mediumone.com/v2/events/text_messages/myuser' -d '{"observed_at":"2015-03-04T12:00:00.0-0700", "event_data": {"body":"text message"}}'

Now, in your Sandbox account, go to Config > Data Streams, and find each new tags and make sure the Active box for the tag is checked.

List of Data Streams with tags:

  1. processed

  2. action_start_of_game

  3. action_whack

  4. action_end_of_game

  5. raw

  6. page_refresh

  7. game_stats

  8. game_id

  9. player_registration

  10. player_name

  11. text messages

  12. body

Note: for stream event_log  there are no associated tags, but it is used as part of the Processed Data Stream module in some of the workflows.

Set up Workflows

Whack-A-Mole Workflows

Now that the new streams and tags are added, we are ready to set up the workflows for the game.

In your Sandbox account, go to Workflow Studio. You will need to create 8 workflows as shown in the image above. For each workflow, follow these steps:

  1. click on Create

  2. Open the Tags and Triggers menu in the sidebar and find the stream(s) (e.g. “processed”), and the tag(s) (e.g. “action_start_of_game”) from the corresponding workflows image below, and drag that tag onto the canvas.

  3. Open the Modules menu in the sidebar, go to Foundations, and drag a Base Python module onto the canvas.

  4. Click and drag to connect the input and output nodes to match what you see in the workflow image.

  5. Double-click on the Base Python module to open, and replace the code in the Script box with code from the corresponding .py file in our BitBucket repo, and Save.

  6. If the workflow contains an orange Processed Data Stream module, open the Outputs menu in the sidebar, and add the Processed Data Stream module. Connect the output of the Base Python module to the input of Processed Data Stream. Double-click on the Processed Data Stream module to open, and edit any values that are not the defaults (see the images of each processed data stream below)

  7. For all workflows *except* Local Game Controller, open the Revisions menu in the sidebar, and click on the checkbox to activate your most recent revision.

  8. For workflow Local Game Controller, do not activate the revision, but instead double-click on the note icon in the top-left corner, and paste this in: { “info”: { “remote_status”: “active” } }

Workflow Images

Processed Data Stream Images for Workflows C, D, and E

See the images below for the info that must be entered into the orange Processed Data Stream module for the three workflows that have them.

Workflow C Processed Data Stream 1

Workflow C Processed Data Stream 2

Workflow C Processed Data Stream 3

Workflow D Processed Data Stream

Workflow E Processed Data Stream

Set up Player Registration and Stats pages

We have set up a BitBucket repo with the webpages here. The webpages include:

  1. a scoreboard/stats page that shows live updates of the players’ scores during the game and summary stats for game history

  2. a player registration page that allows new players to sign themselves up to play, and to optionally provide their age, for the reaction time by age summary stats

  3. a player queue page that shows a waiting list of players

  4. a browser version of the game board

Whack-A-Mole registration page

You’re ready to play!

Get your game started in terminal

Check that the Edge framework is running by running the following command in your terminal:

 sudo systemctl -l status mediumoned.service 

If it is not running, please review the activation instructions at: https://mediumone.com/samsung/artik.

If it is running, you can go ahead and start the game, by running the CURL command below, either locally on the individual ARTIK modules, or from another computer posting remotely to the appropriate HOSTNAME. (Note: artik_local_server_password is the default password assigned when you set up your ARTIK with Medium One project, so don’t replace this value)

curl -X POST -d '{"observed_at": "2015-01-10T00:00:00-0800", "event_data":{"start_controller": true}}' https://$HOSTNAME:13373/v2/events/raw/LocalGameController --header "Content-Type: application/json" --user artik_local_server_login:artik_local_server_password -k --header "Content-Type: application/json"

How to Play

When the board is on and ready to play, all the lights will blink. To start a game, hit the center button. This will begin a sequence of single lights turning on and off. The goal of the game is to hit the buttons when they light up, before they turn off.

Scoring Rules

  1. Hit : Hitting a lit button    + 1 point

  2. Miss: Failing to hit a lit button  0 points

  3. Error: Hitting a button that is not lit  -1 point

The Medium One Stats page will show you three types of information:   real-time updates for current game (a ticker with points), summary statistics for the most recent game (total number of hits/misses/errors, average reaction time), and analytics for the history of game play, such as reaction time by age.

Have fun!!

Young Sohn, President and Chief Strategy Officer, Samsung Electronics, having fun at the 2016 Samsung Developer Conference


© 2018 Medium One   All Rights Reserved

4633 Old Ironsides Dr. #280, Santa Clara, CA  95054                



  • LinkedIn - White Circle
  • Twitter - White Circle
  • YouTube - White Circle
  • Google+ - White Circle