Black Jack Folk: an AI-Powered Companion Robot for Card Games

by Hugo Gómez-Cornejo Sorgato in Circuits > Raspberry Pi

20 Views, 0 Favorites, 0 Comments

Black Jack Folk: an AI-Powered Companion Robot for Card Games

5884273975309831480_121.jpg

Picture this: my grandfather, sitting alone at his dining table with a dusty deck of cards. He loves Blackjack, but finding someone to play with every single evening just isn’t realistic. That lonely image stuck with me—and it’s exactly where the idea for Black Jack Folk was born.

I didn't just want to build a machine. I wanted to create a companion. A friendly little robot that could sit across from him, deal a hand, and keep him company during those quiet hours. The goal isn't to replace human interaction, but to fill those moments with fun, strategy, and a little spark of joy—all through a device that’s simple enough for an 80-year-old to use without frustration.

So, how does this quirky friend actually work? Under the hood, it’s a wild mix of AI and hardware. I hooked up a Raspberry Pi as its brain and spent countless hours teaching a YOLO26 Nano model to recognize every single card in the deck (all 52 of them, from tricky angles and bad lighting!). To make it feel alive, I designed a cute, 3D-printed body using Siemens NX, added a servo motor to give it a moving "arm," and threw in an LCD screen and RGB LEDs so it can react to your moves. The best part? I built a ridiculously simple Gradio interface—so easy that anyone, regardless of tech skills, can jump right into a game.

In this Instructable, I’ll walk you through every step of bringing your very own Black Jack buddy to life. No robotics PhD required—just curiosity and a love for card games. Let’s build something that plays cards, but more importantly, keeps people company.

Supplies

Screenshot 2026-06-19 071438.png

This project requires a combination of electronic components, software, and 3D-printed parts. Below is the complete list.


Electronics:

- Raspberry Pi 4 (4GB RAM recommended) or Pi 3B+

- USB Webcam (720p minimum, compatible with Raspberry Pi)

- 16x2 LCD Screen with I2C backpack

- Micro Servo Motor (SG90 or equivalent)

- RGB LED (common cathode or NeoPixel)

- 5V 3A Power Supply for Raspberry Pi

- Jumper wires (female-to-female, male-to-female)

- Breadboard (optional, for prototyping)

- M3 screws (various lengths) for enclosure assembly


Software:

- Python 3.9+

- YOLOv8n (Nano) or YOLO26 Nano

- Roboflow account (free tier works for this)

- Gradio (for web interface)

- OpenCV

- RPi.GPIO library


Tools:

- 3D Printer (FDM, PLA filament)

- Siemens NX (or any CAD software for STL export)

- Screwdrivers (small Phillips head)

- Super glue (for non-moving parts)

- Sandpaper (fine grit, for post-processing prints)


Estimated Cost: €150 - €200 (depending on local prices)

Dataset Preparation & YOLO Training

Goal: Train a YOLO model to recognize playing cards from the camera feed.


3.1. Classes to Detect


In Blackjack, the suit (hearts, spades, etc.) does not affect the gameplay. Only the card value matters. Therefore, you can simplify your dataset to 10 classes:


1. Ace

2. 2

3. 3

4. 4

5. 5

6. 6

7. 7

8. 8

9. 9

10. 10 (this includes 10, Jack, Queen, King - they all have value 10)


Optional: If you want the robot to "see" the actual card names, you can use 52 classes. But for a functional Blackjack game, 10 classes is sufficient and reduces training time significantly.


3.2. Data Collection


Take photos of playing cards from different angles and lighting conditions. You need at least 50-100 images per class.


- Place cards on different backgrounds (wooden table, white paper, etc.)

- Vary the distance and tilt of the camera

- Include images with no cards (background/negative samples)


3.3. Annotation with Roboflow


1. Upload your images to Roboflow

2. Draw bounding boxes around each card

3. Assign the correct class label (e.g., "ace", "5", "10")

4. Apply augmentations (rotation, brightness, blur) to increase dataset size

5. Export the dataset in YOLO format


3.4. Training


Clone the YOLO repository and run the training script. Use the following command as a baseline:

yolo train data=your_dataset.yaml model=yolov8n.pt epochs=50 imgsz=640


Monitor the mAP (Mean Average Precision) metric. A value above 0.85 is considered good.


3.5. Export


After training, export the best weights file (best.pt). This will be loaded by the Python script on the Raspberry Pi.


Attached Files:

- Sample dataset structure

- Training notebook (Google Colab compatible)

Python Backend & Gradio Interface

Step 4: Python Backend & Gradio Interface


The software has two main components:

- A Python script that runs the YOLO model and controls the hardware

- A Gradio web interface that the user interacts with


4.1. Python Backend


The backend does the following:

- Loads the YOLO model weights

- Captures frames from the USB camera

- Runs inference on each frame

- Sends commands to GPIO pins based on game logic


GPIO Pin Mapping (example):

- Servo signal: GPIO 18 (PWM)

- RGB LED red: GPIO 22

- RGB LED green: GPIO 23

- RGB LED blue: GPIO 24

- LCD I2C: SDA (GPIO 2), SCL (GPIO 3)


4.2. Gradio Interface


The interface should be simple. Use large buttons and clear text.


Example layout:

- Left: Live camera feed with YOLO detections overlay

- Right: Game status text and two buttons (HIT and STAND)


4.3. Running the System


To start the system, run:

python app.py


This will launch the Gradio server on the Pi's local network. Access it via the Pi's IP address from any device on the same network.


Attached url: github

https://github.com/howest-mct/2025-26-projectone-ctai-GomezCornejoHugo

3D Enclosure Design

5884273975309831484_121.jpg

The enclosure was designed in Siemens NX and 3D printed using PLA.


5.1. Design Overview


The enclosure consists of three main parts:

- Body (houses the Raspberry Pi, LCD, and wiring)

- Hat (holds the USB camera)

- Arm (attached to the servo motor)


5.2. Fastening Method


The body halves are secured using M3 screws. Alignment pins ensure the pieces fit together correctly. The hat is attached with super glue (no need to open it after assembly).


5.3. Printing Settings


- Material: PLA

- Layer height: 0.2 mm

- Infill: 20%

- Supports: Required only for the arm mechanism


5.4. Post-Processing


Remove supports and sand any rough edges. The parts should fit together with light pressure.


Attached Files:

- STL files for all three parts

- Siemens NX source files (if you want to modify)

Assembly

5884273975309831481_121.jpg

1. Mount the Raspberry Pi inside the body base using standoffs or double-sided tape.

2. Connect the servo, LEDs, and LCD to the GPIO pins using jumper wires.

3. Place the camera inside the hat and secure it.

4. Route the camera cable through the designated channel in the body.

5. Align the two body halves and secure them with M3 screws.

6. Attach the servo arm to the servo horn.

7. Glue the hat to the top of the body using super glue.

8. Attach rubber feet to the bottom of the robot.


Ensure all cables are routed cleanly and do not obstruct the servo movement.

The Moment of Truth

5870869919249927723_121.jpg

1. Connect power to the Raspberry Pi.

2. Run the app.py script.

3. Open the Gradio interface on a laptop or phone.

4. Place a card in front of the camera.

5. Verify that:

- The card is detected and labeled correctly

- The LCD displays the game status

- The RGB LED changes color based on game events

- The servo moves when the AI decides to "Hit"


Common Issues:

- Camera not detected: Check USB connection and permissions (/dev/video0)

- YOLO model not loading: Verify file path and that opencv-python is installed

- Servo not moving: Check GPIO pin number and PWM frequency

- LCD not showing text: Verify I2C address (use i2cdetect -y 1)