Introduction: Setting Up a Stepper Motor Driver
If you need to use stepper motors in some kind of way for a project, this guide will cover how you can get started with the SlushEngine. By the end of this guide, you will be able to move 4 stepper motors at once. You will also learn how to use the position control features of the SlushEngine.
This SlushEngine board is the summary of a years' work towards our official Kickstarter campaign.
It is a state of the art stepper motor controller and driver for the Raspberry Pi (and Arduino!). With its high end driving capabilities it can drive up to 4 steppers at a time. The SlushEngine is also the simplest stepper motor driver to use. With a few lines of Python code you can have a motor spinning in no time.
With its easy to use features and advanced control options, this board is great for Education, Hobbyists and Engineers alike!
Step 1: What You Will Need
- A SlushEngine (You can get one here)
- A Raspberry Pi (B, 2, 3, 0) and an SD card with Raspbian: most other Raspberry Pi OSs will work
- A power supply: A wall adapter, car battery, computer power supply, any thing that supplies voltage between 9v and 36v
- A Stepper motor (You can get one here): Almost all Bipolar stepper motors will work with the SlushEngine
Step 2: Getting the Raspberry Pi Running
The first thing we need to do before we make any motors move is install some software packages on the Raspberry Pi that will allow it to communicate with the SlushEngine. These packages are easy to install and we test them regularly with the OS(Raspbian, Trusty, etc...) on the Raspberry Pi webpage to ensure they are up to date and working. There are many different ways to connect to your Raspberry Pi. You can use VNC, SSH or just plug it into a monitor. All of these options will work for the SlushEngine.
First we have to enable SPI and I2C, these are the communication buses that will be used to communicate with the Raspberry Pi. To Enable these, we need to change there settings using the Raspberry Config program.
This will open up a terminal based configuration window. You can use the arrow keys to scroll around and look at the cool features (now is not the time to enable overclocking). We want to do the following:
Advanced Options > SPI > Yes & Advanced Options > I2C > Yes
Once you have enabled both the SPI and the I2C, you can restart the Raspberry Pi.
With the Raspberry Pi rebooted, you want to make sure you have an Internet connection on the Raspberry Pi. All of the software is located on-line and will be installed automatically using a series of commands. Following the commands below will ensure proper installation. First, we will install the required packages we need to then install other packages (the installers installers).
sudo apt-get update
sudo apt-get install python3-pip git
Then install the library used to communicate with the SPI bus that we enabled before.
pip-3.2 install spidev
Now we will install a package that is used to communicate with the I2C bus. This will communicate with the temperature sensor and the IO on the SlushEngine board.
sudo python3 setup.py install
All of the required packages have now been installed and we can finally install the SlushEngine software. This will be installed using the same method as was used for installing the I2C driver.
git clone https://github.com/Roboteurs/slushengine
sudo python3 setup.py install
The hard work is finally over! Now you can hook up some hardware and we can get some motors moving.
Step 3: Connecting the Hardware
It is always good practice to make sure that whenever you are connecting wires you have the power turned off. This can save a stray wire shorting out something and maybe killing a board.
First, we will connect the Raspberry Pi. This is done simply by placing the Raspberry Pi into the connector of the SlushEngine. You can see from the pictures attached which way the Raspberry Pi should be connected.
Then we can connect the power wires to the Raspberry Pi. In this example, I am using an old laptop charger cable. It provides 17 Volts and 1.5 Amps. This will be more than enough to run a few stepper motors.
The stepper motor can now be connected. The wire coloring of stepper motors can vary depending on where you get your stepper motors from. If you use our stepper motors you can match the coloring of the wires to the connectors as they are seen in the picture. Essentially you need to figure out which wires coincide with which phases of the motor ( phase A and phase B). If you have no way of finding that information you can connect the wires to the SlushEngine and if the motor does not spin properly you can rearrange the wires until the motor runs properly.
Step 4: Moving the Motor
Moving the motor is the easy part, and if everything is connected correctly, you will have a motor spinning in a few minutes. To test the motor, we are going to use Pythons Idle program. To open this, click menu in the top left corner, then Programming and Python3. Make sure you are using Python 3 or the code will not work correctly.
Now, line by line we can test to see if the motor is spinning, then we will be able to create and run a program. Type the following code line by line pressing enter after each line. This will initialize the Slush library and setup a motor.
b = Slush.sBoard()
m = Slush.Motor(0)
The motor will now have moved a very small amount, 1000 micro steps. There are 128 micro steps in a step, so this is a very small and precise angle. Now that you have the motor moving you can try some different commands to see how the motor works.
These are just some of the many features of the SlushEngine. You can do other things with the motor as well like setting the power to the motor, setting temperature limits, and using a limit switch to set a home position for the motor.
Step 5: Troubleshooting
This guide will go through some of the problems that our users have and that we have encountered while using the SlushEngine. Browse through the questions, and see if you can find an answer to yours. If you are stuck, you can email email@example.com and we will try and post an answer to your problem.
Q: I get the error "Cannot load spidev"
There are two different causes to this problem. The first is that the spidev library was not installed. See the beginning of the getting started guide to install the library. The other is that you could be using Python 2.7 (Python2) the SlushEngine currently requires that you use Python3.
Q: The motor just vibrates and makes noises
This is cause by incorrect hookup of the stepper motor wires. Switch the wires around or check the product page for the motor to find the correct wiring
Q: The power to the Raspberry Pi from the SlushEngine cuts out
This happens if there is too much of a load on the Raspberry Pi USB ports. The SlushEngine can only provide 2 Amps to the Raspberry Pi. This is enough to power a Wifi dongle, Bluetooth, and a Display. If you have an external hard drive or other load connected it may be to much for the power supply.
We have a be nice policy.
Please be positive and constructive.