Introduction
The Gertbot is an add-on board for the Raspberry Pi, compatible with all existing models.
It brings power and motor control capabilities to the Raspberry Pi, but can also be used with other controllers supporting serial communication. Because the Gertbot has it's own CPU dedicated to the real time activities, the Raspberry Pi is only required to pass high level commands such as "DC motor 1, ON", "Stepper motor 2, 200 steps at 500Hz". The drivers come in two flavours: Python and C/C++. There is also an optional GUI, not requiring the use of code to use the Gertbot.
To know more about Gertbot, visit: http://www.gertbot.com
In this post, I'll be demonstrating how to control two stepper motors using the Gertbot Python drivers.
Setting up
Getting everything set up is really easy and can be done in a matter of minutes.
The first step is to connect the Gertbot to the Raspberry Pi, but before doing so, ensure the Pi is powered off. Take the Gertbot and connect the 26-pin header, starting from pins 0 and 1. The Gertbot should slide in nicely next to the ethernet port, without touching it.
The result should be as follows:
Next, the Gertbot Python drivers need to be installed on the Raspberry Pi. To do this, power on the Pi and using a terminal, browse to where you'd like to deploy the drivers.
The Gertbot Python drivers can be downloaded from the Gertbot website using following command:
The output of the command should be similar to this:
pi@PiDesk ~ $ wget http://www.gertbot.com/gbdownload/src/gertbot_py.tgz --2015-05-04 19:28:43-- http://www.gertbot.com/gbdownload/src/gertbot_py.tgz Resolving www.gertbot.com (www.gertbot.com)... 93.93.130.166 Connecting to www.gertbot.com (www.gertbot.com)|93.93.130.166|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 8537 (8.3K) [application/x-gzip] Saving to: `gertbot_py.tgz' 100%[================================================================================>] 8,537 --.-K/s in 0.01s 2015-05-04 19:28:43 (752 KB/s) - `gertbot_py.tgz' saved [8537/8537]
The downloaded drivers are compressed. In order to be able to use it, the file must be extracted:
- tar -xvzf gertbot_py.tgz
pi@PiDesk ~ $ tar -xvzf gertbot_py.tgz gertbot.py
There you have it, the "gertbot.py" file. By importing this file in other Python scripts, it is possible to call certain functions that will facilitate the control of the motors.
Script
At the bottom of the Gertbot's download page, some example scripts are provided. Starting off from the "Simple Rover" Python script and looking at the "Stepper Rover" C code, I came up with my own simple Python script to control two stepper motors. The script allows the control of two stepper motors to either go in one direction or the other. This is for example useful to control the Z-axis of a 3D printer. It's possible to define the number of steps and the frequency at which the steps are taken.
As for the hardware, I used two 200 steps, bipolar, 12V NEMA17 stepper motors and connected them to the Gertbot as per the documentation. The underside of the Gertbot also indicates how to connect the motors.
Demo
As a demo application, I've built a prototype of a lift to slide a screen in and out of place. The lift is controlled using the Python script documented earlier.