My Account

Wish List (0)

Control a Stepper Motor using Diablo

Written by in Diablo - Build on .

In this example, we'll go through how to:

Parts you will need


Connect the Diablo to a Raspberry Pi

For details on how to wire up a Diablo to a Raspberry Pi please follow the Connect the Diablo to a Raspberry Pi section of our Quick Start Guide. Once your Raspberry Pi is connected move onto the next part of this tutorial.

Connect the Diablo to a power supply

Connect one pair of red and black wires to the Diablo, matching the red wire to the red terminal on the power supply and the V+ terminal on the right hand side. Match the black wire to the right hand GND terminal on the Diablo and the black terminal on the power supply.


Similarly connect the second pair of wires to the Power Supply and Diablo.


Connect the Diablo to a 4 wire stepper

Inside our 4 wire stepper motor there are two coils which are used to turn the motor. Each coil has a pair of wires attached to it, and we need to work out which two wires form pairs for our motor. To do this we can test the resistance across each possible pair of wires, and when we find a pair the multimeter will beep and/or show a low resistance on the screen (meaning that the pair of wires form a circuit inside the stepper).

Split out the stepper wires so they can be tested. Turn your multimeter on and set it to continuity mode. Choose any one of the wires and connect it to the red probe. Using the black probe test it against the remaining three wires.


When the multimeter beeps, you've found a pair of wires, which for us was red/blue and green/black.

Each pair of wires on the 4 wire stepper motor will be connected to one of the motor terminals on the Diablo.

Take your first pair of wires and connect one to the M1+ terminal and the other to the M1- terminal.

Take the second pair of wires and connect one to the M2+ terminal and the other to the M2- terminal.


Apply some eye protection and turn on your power supply, being ready to turn off the power in case of an issues with the Pi or wiring.

How to enable I2C on the Raspberry Pi

For details on how to enable I2C on the Raspberry Pi please follow the Enable I2C on the Raspberry Pi section of our Quick Start Guide.

How to install the Diablo libraries and use the stepper example

To install the Diablo drivers we need to obtain the code from GitHub. In a terminal window type:

git clone https://github.com/piborg/diablo-build
cd diablo
chmod +x install.sh
./install.sh

Inside the diablo folder, there will be the diabloStepper.py example which allows you to run a stepper safely.

If we try to run the script by typing python diabloStepper.py it will show the error: "Please set the voltageIn, stepperCurrent and stepperResistance to appropriate values in the script."

If you put too much power through a motor, you can blow it up. If you put too little power through a motor, it won't turn. So we need to find out what the settings are for our stepper motor, and to do this we can look at a data sheet or the information printed on the motor itself.


We are looking for the maximum current the motor can handle, in our case this is 2A. This will be our stepperCurrent.

We are also looking for the coil resistance, in our case it is 1.4 ohms. This will be our stepperResistance.

Finally, our bench power supply gives 13.8V so that is our voltageIn.

It's important to find your stepper motors own values and not use the ones we are about to input.

Open a terminal window and type nano diabloStepper.py. On the highlighted lines below containing voltageIn, stepperCurrent and stepperResistance (under the comment "# Tell the system how to drive the stepper"), edit the values to be the values from our stepper.

Inside the script further down, we're calculating the maximum power based on these voltage, current and resistance values.

Exit and save the file by pressing CTRL+X and then hitting "Y" and enter. Now we can run our script using python diabloStepper.py (or python3 diabloStepper.py).

A prompt will appear on the command line asking for the number of steps to move. Give a positive number to move forwards, and a negative number to move backwards. If you input 0 the script will exit.

Finally

You can use this tutorial to guide you through the setup for the diabloStepper.py example or the diabloStepperSeq.py example, as they both have the same wiring configuration.

Last update: Aug 19, 2019

Related Article

Related Products

Comments

Leave a Comment

Leave a Reply

The product is currently Out-of-Stock. Enter your email address below and we will notify you as soon as the product is available.