How to start prototyping a sorting machine | #MyCardSorter DevLog 2

The setup

Welcome back to the DevLog for MyCardSorter, a DIY card sorter for Magic: The Gathering. In the previous blog post I talked about the idea and motivation about this project. In this edition I want to briefly cover my first steps with electronics to gain experience for building my prototype.

For my first prototype, I decided to build a simple machine using Lego bricks and cheap electronic components controlled with my Raspberry Pi, which I already had at home. I had most of the Lego parts I would need and only had to order the remaining components like a breadboard, some jumper cables, a servo motor, and a Pi cam.

Note: This is part of a series of blog posts I am currently writing (Fall 2023) looking back, realizing that some details might be a bit fuzzy. I failed to document my progress from the beginning, but I wanted to do a write-up anyway.

The goal in this step: Get to know how to control a motor with Python and the Raspberry Pi, learn how to take a picture, and learn the basics of electronics.

Thankfully the article which I mentioned in the previous post helped me to get a good headstart. 

The Setup

While I waited for the components I made sure that the Raspberry Pi hat a running OS (Debian) and I could connect the Raspberry Pi to a monitor and keyboard / mouse. After that I installed Geany as the IDE for my first tests.

After the ordered components had arrived, the first plan would be to somehow get a motor to spin and learn how to control this spin. Luckily, the Raspberry Pi ecosystem offered good documentation and libraries to get this working fairly easily.

Run the motors

Most of the motors can be controlled with "Pulse Width Modulation" which basically means you tell the component how long they should be active and non-active in a very fast way. You can set the frequency of how fast the signal turns on and off in the motor via code:

# Set the PWM frequency to 50
servo = GPIO.PWM(servoPin, 50)

This code means that the PWM signal for the motor will cycle (on and off) 50 times per second. 

I then can control how long the PWM signal is "on" per cycle by configuring the Duty cycle:


Using this I can test and set how long a motor should run in certain situations which helps me later.

After learning this, I tried mounting the servo motor to a Lego block. I also wanted to control a second smaller motor which "releases" the card after taking a picture, so I hooked another one up.

Two running motors

Two running motors The following video shows the first running version. It first spins the larger servo motor which later will pull the cards and the smaller motor which later will release the card.

The code:

import RPi.GPIO as GPIO
from gpiozero import AngularServo
import time
import sys


def setup():
# Assign motors from pins.

# Start motors.

	while True:
		print ("Spin large motor")
		print ("Spin small motor")
except KeyboardInterrupt:

The video which shows what happens:

Excuse the mess, this was months ago and previously not recorded for the public :)

Video file

I was quite happy after I got this running - it looks easy when I look back now, but there was a lot of reading, trying, and frustration when I hacked this together.

Moving cards

The next step would be to move cards somehow. It would be quite a challenge, although I had the original blog post by Michael Portera. Since I did not have the same parts and the images and videos did not paint a complete picture, I had to figure out most of the stuff by myself.

The main idea was clear, though: Put a pack of cards on to a platform where small wheels would be at the bottom high enough to move cards when the wheels start to spin. I liked how Michael tried to block excess cards with another wheel on top to make sure that only one card lands in the tray where the card would get captured. This part was the hardest to get working since cards are usually quite thin but not always the same size, the same shape (some are a little bit curved or bent), or have the same texture (some are smooth and some are more rough on the surface).

Part 1 without cards
Part 2 without cards

In my first tries, I did not succeed in building this version. There were always some issues with the wheels or blocking cards, so I made a step back and thought about other solutions.

Instead of pushing the cards from the bottom using multiple wheels, I wanted to test if I can pull cards one by one from the top of a stack. This meant to set the servo motor wheel on top of the stack and at the edge of the card. I also would have to apply pressure to allow the wheel to have grip. Also, the arm with the motor had to be able to tilt automatically since the fewer cards in the stack the lower the arm has to be to push cards.

I got this to work more or less. By using the parts of Lego I had lying around and the good ol'e rubber band, I was able to build this part out. I noticed that I would have to implement some kind of pull-back since the cards would stick together more often than not, but I was quite happy with the result.

The following video shows an example run:

Video file

But I knew this would not be the best solution for later. It was flimsy, the time for the push and pull to static, and it was not easy to mount the card stack into it since the build was quite fragile.

Although this part was quite hard to accomplish and I knew this would not be a lasting solution, I was quite happy with the progress. I had a lot of ideas on how to possibly make this part work, which I will cover in the next edition.

In the next blog post, I will tell you about the progress towards the first working prototype. Until then, enjoy my cat Fussel questioning the sanity of its owner:

My cat Fussel helping out



Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.