Skip to content

Pixy2 camera and STS3215/ST3215 servo automatic dice roller/tester using STM32/HAL.

License

Notifications You must be signed in to change notification settings

ufnalski/pixy2_dice_roller_h503rb

Repository files navigation

Pixy2 camera and STS3215/ST3215 servo automatic dice roller/tester (STM32H503RB)

An STM32 HAL demo of an automatic dice roller with a computer vision to automatically log consecutive results.

STS3215/ST3215 in action

STS3215/ST3215 OLED

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.

Missing files?

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.

Libraries

Software tools

Pixy2 dice roller serial debug

Exemplary hardware

Pixy2 in action:

Die blue face Die green face Die orange face Die red face Die violet face Die yellow face

Docs, libraries, tutorials and examples

STS3215 servo drive

Robot vision for tinkerers and beyond - just a couple of examples out of almost countless out there

The Chi-squared test

Randomness, prime numbers and cryptosystems

What next?

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.

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, 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

  1. Useless machines/boxes on YT

  2. https://www.mathworks.com/hardware-support/lego-mindstorms-ev3-simulink.html

  3. Hooking up Pixy to a Microcontroller (like an Arduino)

  4. [fun fact] Largest annual volume toy tyre manufacturer ever

  5. The initial orange hot glue stolen from my daughter's workshop turned out to be totally impractical. Guess why 🙂

  6. Pearson's chi-squared test (Wikipedia)

  7. Dice Testing with the Running Chi-Square DistributionDice Testing with the Running Chi-Square Distribution (Western Kentucky University)

  8. How can I test whether a die is fair? (StackExchange)

  9. Von Neumann extractor

  10. How to best obtain bit sequences from throwing normal dice? (StackExchange)

  11. How to test random numbers? (StackExchange)

Releases

No releases published

Packages

No packages published