Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 7.67 KB

README.md

File metadata and controls

76 lines (53 loc) · 7.67 KB

Electronic dice demo (STM32L432KC)

An STM32 HAL example of an electronic die/dice1.

Charlie with a dice in action

The main goal for this example is to lure you into experimenting with the (T)RNG peripheral of the STM32 uC. The example also implements the Charlieplexing technique to reduce the pin count. Here Charlieplexing is performed in the blocking mode. It is just for the concept demonstration purposes - to deploy it in a control system you have to rewrite the code into a non-blocking one. Before we move on I must confess that my agenda is much more evil - I want to lure you into the world of unpredictability manifested by radioactive decay ☢️, quantum mechanics :atom: and chaotic systems 🎲 2

Why electronic dice?

Because it's fun. Because they are more versatile - you can emulate any RPG dice in practically no time. And they are usually much more fair than an unbalanced/imperfect/unsymmetrical physical dice. "The RNG is a true random number generator that continuously provides 32-bit entropy samples, based on an analog noise source. (...) The RNG true random number generator has been tested using NIST statistical test suite SP800 rev1a (April 2010)." [RM0394].

Missing files?

Don't worry 🙂 Just hit Alt-K to generate /Drivers/CMCIS/ and /Drivers/STM32L4xx_HAL_Driver/ based on the .ioc file. After a couple of seconds your project will be ready for building.

Libraries

Exemplary hardware

IMHO useful gadgets

Readings and videos

Randomness

Probabilistic thinking

And now exercise your critical thinking skills

Humans as weak sources of entropy

Physical dice fairness

Charlieplexing

Next steps

Hooked on randomness? Good! This is just the first chapter. Now test the RNG on your own. Use STM32 as USB HID keyboard to feed the data directly into an online bitstream tester that implements the NIST Statistical Test Suite for Random and Pseudorandom Number Generators such as https://mzsoltmolnar.github.io/random-bitstream-tester/. Or use UART if you are up to more than, let's say, 1000 bits - it's much faster. Then build your own TRNGs. Experiment with different sources of entropy. A Geiger counter4. A thermal noise (ADC)5. A physical dice roller with automatic face detection6. I will join you along the way with my contraptions if time allows ⌚ And first and foremost, never ever trust your gut when assessing randomness. We humans tend to be very bad at that. Successful thinking in terms of probabilities, including the probabilities of probabilities, probability density functions and Bayesian probabilities, without proper training is usually hard - explore Readings and videos for some illustration of that. Train yourself in probabilistic thinking. Funny thing is that thinking itself can be regarded as the process of using all the stats being continuously stored in your brain. For example, learning a natural language is a Bayesian endeavour.

Call for action

Create your own home laboratory/workshop/garage! Get inspired by ControllersTech, DroneBot Workshop, Andreas Spiess, GreatScott!, ElectroBOOM, Phil's Lab, atomic14, That Project, Paul McWhorter, and many other professional hobbyists sharing their awesome projects and tutorials! Shout-out/kudos to all of them!

Warning

Automation and control engineering - do try this at home ❗

190+ challenges to start from: Control Engineering for Hobbyists at the Warsaw University of Technology.

Stay tuned!

Footnotes

  1. Dice vs. Die – Which Is Singular and Which Is Plural? (Grammarist)

  2. Randomness, uncertainty, chaos and unpredictability are not synonyms if we want to be rigorous. For example, rolling dice create a chaotic system, even a single rolling die creates a chaotic system with the environment it interacts with, whose behavior is highly sensitive to initial conditions - when we roll dice we do NOT intend to exploit the fundamental unpredictability at the level of a quantum event (such as a single atom's decay).

  3. I wouldn't call it a paradox. The numbers on the bingo card are not uniformly distributed. The initial guess should be then that the probability of hitting a row vs. the probability of hitting a column are probably 😉 not equal. Nevertheless, it is still an example of a counter-intuitive result when the ratio of these probabilities is to be guessed.

  4. Arduino True Random Number Generator (Instructables)

  5. A true random number generator that utilizes thermal noise in a programmable system-on-chip (PSoC) by Shunsuke Matsuoka, Shuichi Ichikawa and Naoki Fujieda

  6. Fair Dice Tester (Pt. 1) by Gerry Chen