This article is all about how to turn a Stepper Motor using a Raspberry Pi using the MOTORplate Controller and some software
A short Video
- Hardware needed
- Setup Raspberry Pi2 with raspbian using Noobs
- Steppermotor with MOTORplate hookup
- Enable GPIO on Raspberry
1. Hardware needed
There are several pieces of hardware (HW) needed to test this
- HDMI Monitor (not needed if you install a VNC server)
- Raspberry Pi-2 or Pi-3 or Pi-3+, I bought it from Pi-Shop (about CHF 40)
- Raspberry Pi heatsink, I think a must (Pi-shop about CHF 4)
- 16GB, 32GB or 64GB Memory card (SD card), ex. SAMSUNG EVO Plus 64GB from Microspot (about 30)
- Power-supply raspberrry Pi, 5.1V, 2.5A (Pi-shop, about 20)
- Stepper motor, Nema 17 Bipolar 1.8deg, 26Ncm (36.8oz.in), 0.4A 12V, 42x42x34mm, 4 Wires (about 7)
- MOTORplate, (Pi-shop, about 50)
- USB mouse (not needed with VNC)
- USB keyboard (not needed with VNC)
- HDMI cable (not needed with VNC)
- Network cable or Wifi
2. Setup Raspberry Pi-2 using NOOBS
- Download the latest Version of NOOBS from Raspberrypi.org. I like the Lite Version because the download is very fast and the setup of the SD card is easy. During the install, the raspberry needs to be hooked up to the internet.
- Get the SD card ready. Be careful, when your card it >32GB and you want to boot from it, you need to format the SD card with a special tool using a Fat32 filesystem. I used Guiformat.
- Now insert the SD card, boot NOOBS and install raspbian. If you are using NOOBS-lite you need to select what you want to install. Click on below image to see the install.
3. Stepper motor with MOTORplate hookup
Well I cut the connector of from the motor and soldered the ends.
I used the User-Guide from Pi-Plates to determine the stepper motor hookup and the reference card that came with the motor. You need to select an address using the little jumpers for each Pi-module. This is important for the software to address each module. Based on the User-Guide I selected address = 6.
4. Enable GPIO on raspberry
By default the raspbian OS has the GPIO interface disabled. I had to learn this the hard way when I noticed a run failures executing the software.
I used the terminal window and modified the config.txt file or you can use the GUI. (see below)
#sudo nano /boot/config.txt
un-comment the following line and save your changes and reboot
or use the GUI:
Menu > Preferences > Raspberry Pi Configuration > Interfaces and make sure SPI is set to Enabled.
First things first, we update to all the latest OS patches via terminal window
- #sudo apt update
(in order to get the system ready)
- #sudo apt upgrade
(the actual upgrade)
- #sudo rpi-update
(the firmware upgrade)
(and the reboot which is needed after a firmware upgrade)
5.2 Development Editor
Now we choose our Dev environment, I like Geany
#sudo apt install geany
Since raspbian is linux and development is usually done in Python I want to go forward with the newer Version of Python 3. The current Version is 3.5. With raspbian, python is already installed, what we need though are some libraries from pi-plates.
pi@raspberrypi:~/Downloads $ sudo pip3 install Pi-Plates
Installing collected packages: Pi-Plates
Successfully installed Pi-Plates-4.1
to update to a newer Version of Pi-Plates:
#sudo pip3 uninstall Pi-Plates
#sudo pip3 install Pi-Plates
In case “pip3” is not yet installed:
#sudo apt install python3-pip
Where are the files being installed to?
pi@raspberrypi:~/Downloads $ sudo pip3 install RPi.GPIO
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (already installed)
5.4 MOTORdemo Software from Pi-Plates
pi@raspberrypi:~/Downloads $ wget https://pi-plates.com/downloads/MOTORdemo.tar.gz
–2018-10-19 09:35:42– https://pi-plates.com/downloads/MOTORdemo.tar.gz
Resolving pi-plates.com (pi-plates.com)… 18.104.22.168
Connecting to pi-plates.com (pi-plates.com)|22.214.171.124|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 11480 (11K) [application/x-gzip]
Saving to: ‘MOTORdemo.tar.gz’
MOTORdemo.tar.gz 100%[============================>] 11.21K –.-KB/s in 0s
2018-10-19 09:35:49 (27.1 MB/s) – ‘MOTORdemo.tar.gz’ saved [11480/11480]
pi@raspberrypi:~/Downloads $ sudo tar -xzvf MOTORdemo.tar.gz
5.5 Create Geany Project
Now we make a few modifications:
- We need to change the terminal for Geany, Menu – Edit – Preferences
to verify that xterm is installed, use
#sudo apt install xterm
- Now the Build Command change for Python3
Menu – Build – Set Build Commands
Notice the python3 in the Compile line and IN the Execute line
5.5.1 Code Modifications
I ran into some minor problems and will tell you the fixes.
First in MOTORdemoOOP.py change to the following 2 lines
from Tkinter import *
from tkinter import *
from tkinter import font
addr = 6
then search and replace all of the following:
“tkFont.Font” to “font.Font”
“(0,” to “(addr,”
- tkinter is now lowercase
- I used the library font because tkFont is already within tkinter
- In addition the demo code was hardcoded to Address = 0 and I changed my Pi-Plates MOTORplate to Address ID = 6, so whereever there was a call to a function
“MOTOR.stepperCONFIG(0, ” it now reads “MOTOR.stepperCONFIG(addr,”
5.6 Run the code
press F5 and the code should run