Machine Learning in WIO Terminal (Seeed Studio) to recognize shake and roll two die using True Random Number Generator (TRNG)

GitHub: debsahu/WIOCatanDieRoll


  • When WIO is shaken it will roll two die signifying a turn on Settlers of Catan board game
  • Die roll needs to be completely random uniform distribution
  • Die roll must happen when device is shook vigorously



  • WIOImuTap: Uses in-built IMU to look for double tap to roll 2 die using TRNG
  • EdgeImpulse: Upload and train NN using sensor data on Edge Impulse, deployed on WIO with live classification on serial port. Model is included
  • AIShakeDie: Uses in-built IMU to recognize shake using NN from Edge Impulse and rolls 2 die using TRNG

Collecting data from WIO & storing on Edge Impulse, training Neural Network on Edge Impulse, Export and deploy TinyML on WIO

1. Collecting data from WIO & storing on Edge Impulse

Installing dependencies (Windows)

  1. Install Python 3
  2. Install Node.js v14 or higher - install additional Node.js tools or-else install Microsoft Visual Sudio 2015
  3. Open powershell as admin, install edge-impulse-cli
npm install -g edge-impulse-cli --force

For other OS please follow instructions from here.

Connecting WIO to Edge Impulse

  1. Connect WIO to computer using USB-C cable
  2. Enter bootloader by sliding power switch down twice in quick succession. enter_bootloader_wio
  3. WIO will show up as a new USB drive named Arduino, copy latest released precompiled UF2 firmware to Arduino drive
  4. Start sending data to Edge Impulse, open a powershell and type
C:\> edge-impulse-daemon

Follow instructions on screen by logging into your Edge Impulse account and selecting a project.

  1. Open the Edge Impulse project on a browser and see if WIO is connected


2. Storing Accelerometer data on Edge Impulse

  1. Start collecting data from device:


  1. Generate appropiate labels for each data point, click on start sampling. When the countdown starts, perform appropiate action on the WIO based on the label given
  2. Once a 10s data collection is complete, check the collected data section and click on hamberger icon and split sample


  1. Split the sample into 1s chunks and click split


  1. Repeat to have lots of data for each label
  2. Do the same for Test data (top-left) for each label

3. Create Impulse & Process/Clean up data & training NN

  1. Create a new impulse (overall design of the project)


  1. Generate Spectral Features - clean up your raw accelerometer data


  1. Generate Features


  1. Train your neural network using cleaned-up training data features from previous step


4. Testing your NN performance

Click on Model Testing > Classify All


5. Deploying your NN on WIO

  1. Click on Deployment
  2. Select Arduino library


  1. Build your Arduino library


  1. Copy contents from src directory into your project

  2. See implementation in EdgeImpulse folder

TinkerGen IDE

Machine Learning on TinkerGen IDE in WIO Terminal (Seeed Studio) to recognize shake and roll two die

  1. Navigate to TinkerGen IDE and create a free account.

  2. Connect WIO terminal using USB-C cable and run CodeCraft Assistant

  3. Navigate to Model Creation and create a new model using accelerometer data.


  1. Start obtaining accelerometer data from WIO terminal for various labels by clicking on Data Acquisition. Note that the accelerometer data is collected for at least 2s which makes up 128 points (62.5Hz).


  1. Collect lots of data, more data is better. Yes, it takes time. Do not skip or skimp on this step

  2. Train your model using the collected data by clicking on Training and Deployment.


Look for accuracy of the model generated.

  1. Deploy your model by clicking on Programming