Marble sorting machine - Thomas More

Explore how Jonas Claes built a Python library for a marble sorting machine, making it easily programmable and intuitive for students.

Marble sorting machine - Thomas More
Thomas More

What is the marble sorting machine?

The marble sorting machine is a small machine that sorts different colors of marbles on 7 different lanes. This is done with a servo motor, stepper motor and Arduino. These are connected to a computer or a Raspberry Pi or something similar.

About the assignment

The purpose of the assignment was to program the Arduino and build a Python client (package/library). How one did this did not matter, it just had to be intuitive to use for other students.

Implementation

Arduino

I started by writing the Arduino code. I added some structure by dividing everything into modules. For example, a Chute module and a Feeder module, which then correspond to the chute with servo motor and the feeder wheel with stepper motor. These modules have some useful functions as public members to control the modules.

Then I built a custom 2-byte serial protocol. This protocol consists of the following information:

  • Byte 1: Command (None, Chute, Feeder)
  • Byte 2: Amount (Which lane should the Chute go to? How many marbles should the Feeder feed).

This protocol is then being read by the Arduino and controls the modules.

Python

I then used Python to build a library that is a wrapper around the serial connection to pyserial. This library then wraps in simple functions what the machine should do. Below is a list of possibilities:

  • move_to(int chute): This function moves the chute to a lane
  • feed_one(): This function feeds 1 marble
  • feed(int amount): This function feeds a number of marbles

I then published this library on PyPi so that students can easily install and use it.
You can find the library here: knikkersorteermachine

Pictures