An STM32 HAL demo of an automatic dice roller with a computer vision to automatically log consecutive results.
The ST3215 servo from Waveshare seems to be a rebranded STS3215 servo produced by Feetech - you can use manuals and examples from both companies to write your own library. I cannot share here a complete implementation for STM32 because writing the missing part is the lab exercise 😇 The demo code is written as a blocking one. One of the tasks is to rewrite the library into a non-blocking one (_IT, _DMA, _ReceiveToIdle). Other class activities may include error handling and object-like structures for more elegant handling of multi-servo scenarios. This is exactly the same story as for SC15/SCS15 already told here. Note that not all registers are copycatted. For example, in the SCS15 servo the motor mode is activated by setting both angle limits to zero, whereas the STS2315 servo has a dedicated register to enable switching between modes.
And now let's use the servo in some useless machine 1. Or maybe let's prototype something potentially more useful - some testing equipment. My contraption was inspired by Fair Dice Tester. However, I had to cut corners because I had alloted only two evenings for building it and making it run. Therefore, writing my own computer vision system was not an option.
There are almost countless evaluation kits helping us dive into the word of robotic vision systems. Maybe you already have one in your home laboratory? If yes, try to use it in a similar contraption. If not, try to use ESP32-CAM (can easily be bought under $10). My vision system was not bought deliberately for this project. A couple of years ago the Pixy2 vision system from Charmed Labs caught my attention for its straightforward integration with the LEGO EV3 platform2 and Arduino projects3. I still use a timeless line follower from time to time to lure high schoolers into robotics and then to welcome them at our Alma Mater as the full-blown university students 😎 Back then the choice of such pretrained camera systems for tinkerers was rather limited. Today, i.e. when I'm writing this README.md, it is a whole new ball game. You have to do your own research and pick one that best suits you current (and future) needs. Coincidentally, my Pixy2 turned out to be a perfect choice for the dice with color-coded faces.
Don't worry 🙂 Just hit Alt-K to generate /Drivers/CMCIS/ and /Drivers/STM32H5xx_HAL_Driver/ based on the .ioc file. After a couple of seconds your project will be ready for building.
- OLED: stm32-ssd1306 (MIT license)
- Kostka kolorowa do gry K6 16 mm Kostki Oko / Color-Dice 20mm, White, 6 Colors
- Baseus Mini Clip Lamp - a diffused white light helps me get consistent readings. Note also tires/tyres4 deployed to limit the field of view and a neutral to the dice faces black hot-melt adhesive 5.
Pixy2 in action:
- ST3215 Servo (Waveshare)
- Arduino library for Feetech's STS smart servo (matthieuvigne on GitHub)
- Feetech STS3215 manuals EN (matthieuvigne on GitHub)
- Edge Impulse
- Simple ESP32-CAM Object Detection (DroneBot Workshop)
- ESP32-CAM: Machine Vision Tips, Camera Guides and Projects (ArduCam)
- SenseCraft (Seeed Studio)
- ESP32 CAM Object Detection & Identification with OpenCV (How to Electronics)
- Machine Vision with HuskyLens (DroneBot Workshop)
- Pixy2 Camera - Image Recognition for Arduino & Raspberry Pi (DroneBot Workshop)
- Pixy2 and STM32 (PixyCam)
- OpenMV
- JeVois Smart Machine Vision
- OpenMV vs. Huskylens: which one to buy with LEGO MINDSTORMS or SPIKE (Antons Mindstorms)
- NVIDIA Jetson Nano (Waveshare)
- Get Your AI in Gear with a JetBot AI Robot Kit (NVIDIA)
- Understanding The Chi-Squared Test (Matteo Courthoud)
- Understanding the Chi-Square Test: An Introduction to Its Concept and Applications (Medium)
- Chi-Square Test (GeeksforGeeks)
- Chi-square statistic for hypothesis testing | AP Statistics | Khan Academy
- GNU Scientific Library
- What is Random? (Vsauce)
- What is NOT Random? (Veritasium)
- Riemann hypothesis (Wikipedia)
- RSA (cryptosystem) (Wikipedia)
- Could Riemann hypothesis solve certainly RSA? (StackExchange)
Write a function that implements Pearson's chi-squared test67. Let your robot roll the dice at least for 30 times8. Is you dice fair? No? Even if the dice is biased you can still generate a truly random bitstream. Why? It is still a chaotic system. How? Check the Von Neumann extractor910. Verify the resulting stream using one of the statistical test suites11.
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, Max Imagination, 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
-
https://www.mathworks.com/hardware-support/lego-mindstorms-ev3-simulink.html ↩
-
[fun fact] Largest annual volume toy tyre manufacturer ever ↩
-
The initial orange hot glue stolen from my daughter's workshop turned out to be totally impractical. Guess why 🙂 ↩
-
Pearson's chi-squared test (Wikipedia) ↩
-
Dice Testing with the Running Chi-Square DistributionDice Testing with the Running Chi-Square Distribution (Western Kentucky University) ↩
-
How can I test whether a die is fair? (StackExchange) ↩
-
How to best obtain bit sequences from throwing normal dice? (StackExchange) ↩
-
How to test random numbers? (StackExchange) ↩