Introduction: Raspberry Pi, Python, and a TB6600 Stepper Motor Driver

This Instructable follows the steps I took to connect a Raspberry Pi 3b to a TB6600 Stepper Motor Controller, a 24 VDC Power Supply, and a 6 wire Stepper motor.

I'm probably like many of you and happen to have a "grab bag" of left-over parts from many an old project.. In my collection I had a 6 wire stepper motor, and decided that it was time to learn a bit more about how I could interface this to a Raspberry Pi model 3B.

As a bit of a disclaimer, I didn't invent the wheel here, I simply pulled together a bunch of information readily available on the Web, added my little slant to it, and tried to make it work

The intent here was really just to pull a few things together (at minimal cost), write some Python code for my Raspberry Pi, and make the motor spin. This is exactly what I managed to accomplish.

So let's get started...

Step 1: The Raspberry Pi

As for the Raspberry Pi, I used three standard GPIO pins so this should work (I have not tested) with any Pi, or Orange board, Tinker board or clones that are available out there. You may (and should) comb through my overly commented Python code and select different GPIO pins if you are using a different processor, or just want to change things around a bit.

Please note that I am direct connecting to the GPIO pins on the RPi, so I'm limiting the voltage that the GPIO pins see to 3.3volts.

Step 2: TB6600 Stepper Motor Driver / Controller

As I previously noted, I opted to use a TB6600 Stepper Motor Driver / Controller.

This controller is:

  • Readily available (search eBay, Amazon, Ali Express or many others).
  • Very configurable with easy access switches.
  • Configuration and wiring details are silk-screened on the case.
  • Input voltage range of 9 VDC to 40 VDC
  • Capable up to 4 amp motor drive output.
  • Has an internal cooling fan and decent heat sink.
  • Is equipped with 3 removable connectors.
  • Has a small footprint,
  • Easy to mount.

But the low cost to purchase is really what sealed the deal on this one.

Step 3: The Stepper Motor...

The stepper motor I used is a bit of an unknown.. I've had it for many years, and don't recall the history of how I acquired it or what it's previous use was.

In this Instructable I'm not going to detail how to figure out it's capabilities - I don't have a real life use for it (other than experimental) so I'll skip that.

I used a fairly generic stepper motor. I did spend a bit of time on YouTube and here on Instructables to try and decipher the wires coming from it.

My motor actually has 6 wires on it... In this application, I left the two "Center Tap" wires insulated and unconnected.

If you have a similar "generic" type of stepper motor, I'm certain that with an Ohm Meter and a bit of time you too could figure out the wiring and make it work in this manner. There are plenty of YouTube videos that will guide you to easily sorting out your own motor.

Step 4: Power and Power Supplies.

Caution needs to be given here...

Depending on your build, you may need to connect to Line Voltages (house power). Be sure to use all appropriate safety precautions:

  • DO NOT try to make electrical connections to live power sources.
  • DO use appropriate size fuses and circuit breakers
  • DO use a power switch to power your PSU (this will make it easy to isolate the power supply from live line voltages).
  • DO properly terminate all wires and make robust connections. Don't use clips, or frayed wires, or ill fitting connectors.
  • DO NOT use Electrician's Tape as an insulator

I used a 24 VDC (5 Amp) Power supply to power the Stepper Motor Driver Controller. I also used the output of this same power supply to drive a DC to DC Buck PSU in order to generate 3.3 volts to use as the source for the ENA, PUL and DIR signals (see the wiring Diagram)

DO NOT try to use the RPi to sink current from a 5.0 VDC source.

I DO NOT recommend trying to source the " + " sides of the PUL, the DIR and the ENA signals with 3.3 VDC from the RPI.

Step 5: Circuit Protection...

Note that in the wiring diagram that follows, I do not mention how to connect the power supply to "AC Power", or list a circuit breaker for it. If you are intent on building a test system similar to this, you'll need to take the time to specify a Circuit Breaker and Fuse that will match the power supply(ies) that you will be using. Most modern power supplies have voltage and current specifications listed on them. These need to be followed, and appropriate circuit protections installed.

Please... Don't skip this important step.

Step 6: The Wiring Diagram

Power Supplies

The output of the 24 VDC power supply is fused with a 5 Amp fuse and then routed to:

  • TB6600 Stepper Motor Driver / Controller "VCC" pin (RED wire in the diagram).
  • It is also routed to the input of the 3.3 VDC "DC to DC Converter" (again a RED wire in the diagram).

The output of the 3.3 VDC "DC to DC Converter" is routed to pins "2", "4" and "6" of the TB6600 Stepper Motor Driver / Controller (BLUE wire in the diagram).

NOTE - the controller itself marks these pins as "5V".. It will work if 5V were supplied to those pins, but because the voltage ratings of the GPIO pins on the RPI, I opted to limit the Voltage to 3.3 VDC.

NOTE - I DO NOT recommend trying to source the " + " sides of the PUL, the DIR and the ENA signals with 3.3 VDC from the RPI.

GPIO Mapping

GPIO Mapping GPIO 17 PUL PINK wire in diagram GPIO27 DIR ORANGE wire in diagram GPIO22 ENA GREEN wire in diagram

Step 7: Operation

Basically, the Raspberry Pi hardware controls three signals:


GPIO22 - ENA - Enables or disables the functionality of the Stepper Motor Driver / Controller.

When LOW, the controller is DISABLED. This means that if this line is HIGH or NOT connected, then the TB6600 is ENABLED, and if proper signals are applied, the motor will spin.

GPIO27 - DIR - Sets the motor spin direction.

When HIGH or Not Connected, the motor will spin in one direction. In this mode, if the motor is not spinning in the direction you want, you can swap the two A motor wires with each other, or the two B motor wires with each other. Do this on the green connectors at the TB6600.

When this pin goes LOW, the TB6600 will switch internal transistors, and the motor direction will change.

GPIO10 - PUL - Pulses from the RPI that tell the TB6600 Stepper Motor Driver / Controller how fast to spin.

Please refer to the attached images for the setting of the Stepper Motor Driver / Controller switch positions I used.

Step 8: Python Code

Attached is my overly commented code.

Feel free to use and edit this as you wish.. I found parts of it on the web, and added it for testing and evaluation purposes.

== == ==

Step 9: Synopsis

It worked.. there is a lot of room for improvement, and the code could be cleaned-up, but OK.

I'd appreciate hearing your thoughts suggestions and of any changes / updates you make.