Project tutorial
Smart DICE: The Physical + Digital RNG

Smart DICE: The Physical + Digital RNG © CC BY

An electronic dice that does not take away the thrill of the roll. The motion data from a roll generates a random number shown on LED's.

  • 2,437 views
  • 2 comments
  • 7 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Inception

The idea for this project originally came from this Kickstarter for an LED Dice - Luma Dice. I play a variety of board and card games and most of them include a dice of some sort. When playing with friends, I end up whipping out a phone and running a dice app on it. This however takes away from the visceral joy of rolling the dice and watching it settle to my desired value.

So I wanted to design an electronic design that took the randomness of the rolling motion and used that as a source of entropy to generate a result. On the plus side compared to a physical multi-hedral dice this electronic version does not need to be a specific shape, a simple cube or 8-ball enclosure will do. The actual value shown is determined by the code, as is the case in a phone app.

I received the FRDM K82F Arduino shield compatible board from NXP as part of their contest and it has all the peripherals needed to make my project a reality.

Stepping through RGB Led display in preparation for the 7-segment display

Experimentation

The first step was getting some LED's blinking with the board. The demo code on the FRDM K82F comes with support for the built in LED's on Pins 8, 9 and 10 of port C. I decided to drive the entire 7-segment LED display which will show the dice output via Port C as well to reuse the existing codebase. The video above shows stepping through the code in Kinetis Design Studio to cycle through the LED's.

The accelerometer reading code is also already implemented in the bubble demo. I experimented a bit by showing the LSF(least-significant-figure) of the readings on a seven segment display, this proved to be not random enough.

The other method of generating True Random Numbers (TRNG) on the FRDM board is provided as a sample in the SDK. This method uses a ring oscillator (series of oscillating NOT gaets) on the SoC as an Entropy source and after a certain delay produces a string of random bits which pass statistical checks.

The 2 random numbers (from accelerometer noise and ring oscillator) can be combined to generate stronger ones.

Implementation

There are several papers on using accelerometers as an Entropy source. One of the earlier works was done using RFID cards and more recently using phone accelerometer with long term filtering to remove adversorial tampering. The implementation here is relatively simple, it combines 2 samples of the LSB of the accelerometer readings and 1 sample of the TRNG generated data using bitwise-XOR operation.

640 CPU cycles are used for ring oscillator entropy accumulation and 10cycles are used between accelerometer readings to allow decorrelation of successive reads.

The "physical + electronic" dice keeps rolling as long as the board is off near horizonal position as measured by accerometer x and y readings. The dice fixes on a value once the board become horizontal.

I also included a battery charger shield from SeeedStudio to allow operation away from the computer and USB ports. This shield allows connection of solar panels for long term use. This mode of operation is illustrated the video below.

Triggering Random Numbers with tilt/shakes

Completion

To finish off the project I built a cardboard enclosure using Pepakura.

This type of enclosure allows me to choose a theme according to any game I might be playing.

This project also makes a great toy for school age kids learning their numbers. A digit is shown on shaking the dice and the challenge is to quickly name it. It functions as a flash card for larger numbers, additional digits can be included by dedicating an enable pin per digit to increase the degree of challenge in the game.

I am getting the Adafruit NeoPixel Shield for more flexibility in number display.

Code

FRDM-K82F Accelerometer Dice
This is the firmware for the board. Clone from git, import project into Kinetis Development Studio and deploy to the board over USB using Segger Jlink.

Custom parts and enclosures

Dice Shaped Enclosure
Enclosure shape for FRDM K82F dice, scale it suitably and 3D-print or build with card stock and Pepakura
dice_cube.obj

Schematics

Arduino proto board wiring
This is an image of the protoboard clearly showing the pins on Port-C of the Kinetis MCU used to drive the 7-segment display
K82f dice

Comments

Similar projects you might like

MicroView Digital Dice

Project tutorial by Giovanni Gentile

  • 635 views
  • 1 comment
  • 2 respects

Arduino Digital Dice

Project tutorial by xXarduino_11Xx

  • 886 views
  • 5 comments
  • 8 respects

Smart Home - Smart Rules using ARTIK Cloud & Photon

Project tutorial by Raghavendra Ponuganti

  • 4,027 views
  • 2 comments
  • 13 respects

Smart BT Lock with Custom Number

Project tutorial by jegatheesan

  • 3,776 views
  • 2 comments
  • 22 respects

Gesture Drive: Accelerate with Freedom

Project tutorial by Shahariar

  • 2,940 views
  • 0 comments
  • 12 respects

Digital Dice

Project showcase by SKYMDev

  • 1,476 views
  • 0 comments
  • 0 respects
Add projectSign up / Login