In this example, we'll go through how to:
- Connect the Diablo to a Raspberry Pi
- Connect the Diablo to a power supply
- Connect the Diablo to a 4 wire stepper using a multimeter
- How to enable I2C on the Raspberry Pi
- How to install the Diablo libraries and use the stepper example
Parts you will need
- One Diablo board with I2C connecting cables.
- A Raspberry Pi
- A bench DC Power Supply (we used this one).
- One four wire stepper motor (we had an old one kicking around our office, but this one will work well) .
- Two 30cm lengths of red 16 AWG wire
- Two 30cm lengths of black 16 AWG wire
- A Phillips head screwdriver
- A multimeter with a continuity mode
- Eye protection, safety first!
Connect the Diablo to a Raspberry PiFor 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 supplyConnect 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).
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 PiFor 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 exampleTo 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
chmod +x 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
We are also looking for the coil resistance, in our case it is 1.4 ohms. This will be our
Finally, our bench power supply gives 13.8V so that is our
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
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.
FinallyYou can use this tutorial to guide you through the setup for the
diabloStepper.pyexample or the
diabloStepperSeq.pyexample, as they both have the same wiring configuration.
Leave a Comment
Leave a Reply