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.
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.
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.
Comments