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.

Game Architecture

What you’ll need

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

  • Samsung ARTIK 10 Circuit Boards
  • Medium One Account with Edge Analytics (see below for activation link)
  • Game Boards
    • ¼” thick polycarbonate for game boards (4 pieces total, 1 top and 1 bottom plate for each board)
    • 26 Arcade-style LED Push Buttons (we used these)
    • 2 50-pin-wide ribbon cables
    • 12 3″ metal standoffs
    • 24 1/2″ length metal fasteners with washers, 1/8″ outside thread diameter
    • Self-adhesive vinyl sheets for logo decal sticker
    • Velcro strips to secure boards to table/playing surface
  • Bread Boards
    • Circuit diagram
    • 2 SN74HC595 integrated circuits
    • 2 SN74LS245N integrated circuits
    • 2 TC74LS148N integrated circuits
    • 2 Ribbon Cable‐to‐breadboard adapter, 50‐pin (we used these)
    • 2 Breadboards (we used Philmore Proto-board Model rh32) and wiring kits
    • 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!

shiny new boards ready to be unwrapped!

top board

top board

bottom board

bottom board

 

 

 

 

 

 

 

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

bulbs and press buttons

lights and press buttons

assembled light in board

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.

  • Note 1 – The LEDs only light up with voltage applied in one direction only, so keep your supply and ground connections consistent
  • 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

soldering on button terminals

board_with_solderedwires

completed cable soldering

breadboard_from_side2

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

marty_breadboardFirst, you will need to set up a breadboard for each game board. The breadboard has circuitry to allow the game board lights to communicate with the ARTIK 10.

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.

breadboard part 1 breadboard part 2 breadboard part 3 breadboard part 4

breadboard part 5

Below is what the complete breadboard should look like.

breadboard_artik_closeup        artik_closeup

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

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 :

  • game_stats
  • player_registration
  • text_messages
  • 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:

  • processed
    • action_start_of_game
    • action_whack
    • action_end_of_game
  • raw
    • page_refresh
  • game_stats
    • game_id
  • player_registration
    • player_name
  • text messages
    • 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

Workflows_small

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

WorkflowA_StartofGame_smallWorkflowB_LiveGameUpdates_small

 WorkflowC_EndofGame_smallWorkflowD_PostGameStatistics_small

 

WorkflowE_PlayerRegistration_smallWorkflowG_TextMessages_small

WorkflowH_EmailLeaderboard_small

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.

WorkflowC_ProcessedMod1_small

Workflow C Processed Data Stream 1

WorkflowC_ProcessedMod2_small

Workflow C Processed Data Stream 2

Workflow C Processed Data Stream 3

Workflow C Processed Data Stream 3

Workflow D Processed Data Stream

Workflow D Processed Data Stream

Workflow E 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:

  • a scoreboard/stats page that shows live updates of the players’ scores during the game and summary stats for game history
  • 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
  • a player queue page that shows a waiting list of players
  • a browser version of the game board
RegistrationPage_small

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

  • Hit : Hitting a lit button    + 1 point
  • Miss: Failing to hit a lit button  0 points
  • 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.

StatsPage_small

Have fun!!

Young Sohn

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

Author: Rochelle Drenan