Nothing is worse than trying to play a card game where one person has to constantly shuffle the deck, but worse yet is when you run into a patch of bad luck and end up losing a bunch of money to your friends. To address these issues, Youtuber 3DprintedLife created a DIY card shuffling machine that is not only able to rearrange decks of cards, but also determine the position of each card. This can lead to some very interesting outcomes when playing games such as blackjack or Texas hold 'em poker, because now the player can always win.
The machine consists of three main parts: a card dispenser/holder, an eight-bin organizer, and computer vision system. Three stepper motors control the movement of the card dispenser and organizing shelf, along with a pusher that moves cards from each compartment back into the holder. They are driven by several A4988 stepper motor drivers, all connected to an Adafruit Feather. Computer vision is carried out by a Raspberry Pi Zero, and it also hosts a simple webpage for controlling the machine. Nearly every part is 3D-printed, so the total cost for this machine is around $200.
To begin, a player places a deck of cards into the top compartment that contains two sets of rollers. The bottom roller moves a single card about 3cm, where the second set then spits it out. This entire assembly is mounted onto a carriage and can move vertically.
When each card is about to be ejected from the first mechanism, it is read through a small window by a Raspberry Pi Camera module. This data is fed into the Raspberry Pi Zero which is running an OpenCV program. It detects the value and suit of the card by adding a couple of filters and applying an edge-detection algorithm. After some training, the system was able to accurately identify and place each card into its respective bin.
Under normal circumstances, cards get randomly shuffled. This feat is achieved by selecting one of eight bins at random and placing a card in that location. After all 54 cards have been run through, a simple mechanism pushes each small stack back into the card dispenser area, where it then rises up and lets the player collect the now-shuffled deck.
All control is handled through a simple web interface that is hosted by the Raspberry Pi. When a user makes a selection, a text file is generated where it is then read by the Python script. Some options include the game mode, whether cheating is enabled, and shuffling settings. The submitted form is handled by a basic PHP that simply writes each value to a file called "data.txt". Based on the parameters, the machine will shuffle randomly for a set amount of cycles or do a planned shuffle where each card is read by OpenCV and placed deliberately.
If you find this project interesting and are considering building it yourself, the code and other associated files can be found in this Github repository. It contains firmware for the Adafruit Feather, PCB files, the web app, the primary Python script, and a bit of documentation.