Last updated on 19th December, 2020
I have read all sorts of information on the internet about the compatibility of the TB6600 and ESP32. Some suggested level shifting was needed, some said it just wouldn’t work, and others said it it fine. Well, I’ve tried it and here is what I found.
For those of you that don’t know, the TB6600 is a 4A rated stepper motor driver and the ESP32 is a popular microcontroller. At the heart of this post is the fact that the popular ESP32 microcontroller is 3.3v logic. This means that the GPIO pins read 3.3v when they are “ON” and 0v when they are “OFF”. However, the popular TB6600 stepper motor driver has a 5v logic input. So would a 3.3v “ON” from the ESP give a stable active “ON” on the TB6600?
Another concern I had was the current draw. The TB6600 datasheet suggests that a normal current draw is 10mA. Since the TB6600 has three inputs (Enable, Direction and Pulse), that should be 30mA. Let’s say 50mA to be on the say side. Checking the ESP32 datasheet, the maximum current is 1200mA across all GPIO pins. So 50mA for my driver should leave 1150mA on my ESP…all good!
Wiring it up
Wiring up is pretty straight forward on this one. I’ve put together the below diagram but I think this actually makes it look more complex and it is! All you need to do is connect:
- ENA+, DIR+ and PUL+ on the TB6600 to 3 free GPIO pins on the ESP32 (I used GPIO pins 25, 26 and 27 in the diagram below)
- ENA-, DIR- and PUL- on the TB6600 to the GND pin on the ESP32 AND the GND pin on the motor supply. More on this later….
- the four stepper motor wires to A+, A-, B+ and B-. A little tip to check find the motor pairs on your stepper is to stick and LED across two wires. Turn the motor, if the LED flashes, you’ve found a pair!
- motor power supply (12v in my case) to the VCC and GND on the TB6600
- a USB cable to power your ESP32
Wait, is it ok to wiring the high voltage ground to the ESP32 ground?! Absolutely. It ensures that the signal from the ESP are correctly read by the stepper driver.
So do the TB6600 and ESP32 work together?
Yes! The TB6600 and ESP32 work perfectly together!
The TB6600 is a very powerful driver which I have hooked up to a 2.8A Nema 23. I am running 32microstepping and a T10x2 leadscrew. The result is a very smooth motion which is very power – I can’t stop it by hand even if I wanted too! I am using this set up to lift about 30kg over 600mm in about 1minute. I’ve been testing this system for about a month now and everything seems reliable! I’ve even managed to link this to my Alexa smart home system. This controls a secret bar which I have built into some industrial looking sideboards.
Anyway, short and sweet on this post. I hope it helps!
Thank you very much for this post as I am searching over the internet that ESP32 input 3.3v sufficient for TB6600 driver as it expections is 5V input signal power but after this post I am sure TB6600 can operate with 3.3v voltage.
I will try same setup and update in weekend.
Thanks,
Sandip 🌿
Hey, I love the secret bar project. Is it really lifting over 30 kg?!
I have a project I’m working on that requires three stepper motors. It’s a self-controlled back massager using three lead screws to provide 3-axis coverage (x,y, and z).
I’m lightly experienced with Arduino and I have a little bit of electronics background. Do you think the ESP32 board can control three NEMA 23 stepper motors if I use three TB6600 drivers? They wouldn’t all be running at the same time I don’t think. Thanks!
Hey! Sorry for the delay in reply! My blog has taken a back seat recently with other projects on the go. Yes, it is lifting over 30kgs and is still working well! Although I try not to load it that much to be on the safe side!
Your project sounds interesting. I think the ESP32 will be fine with 3 steppers. You only need two outputs per stepper (Enable and Direction) – the other two wires are just reference voltages. The ESP32 typically has over 20 output pins to work with depending on the type of board you pick. The only thing to watch out for is if the voltage drops too much on the 3.3V line of the ESP32. The TB6600 expects 5v but as I found, works with 3.3v. But the more you hook up to the ESP, you might find that the 3.3v will drop slightly so might not then work as well with the TB6600. Let me know how you get on!
HI, I can need your code please, thanks.
Hi, no worries – you can find this on this post
Hi,
I’ve been using ESP32 with a 4.5A version of TB6600 for driving Nema23.
The problem is the direction pin of the TB6600 which is not working correctly because by holding the motor shaft tightly, its direction gets reversed automatically.
Please help me because it’s been 2 months of me sticking with this same issue.
I have tried using an optocoupler relay because I felt it’s because of low power at ESP32 GPIO, but it didn’t help either.
Hi Umair,
Thanks for your comment. This is a strange issue. I have just checked with an ESP32 and TB6600 driver on my bench. I stalled the motor but it did not reverse the direction. Have you measured the voltage at the connection of the stepper motor driver? It should be 3.3v assuming you have minimal resistance in your wiring. Any less than this and you will be close to the trigger point of the driver (~2.5v).
If you have a spare 3.3v power source, you could try tying the direction pin directly to 3.3v from the external source. Set the motor turning (will only go in 1 direction since you’ve wired the direction pin to 3.3v). Try to hold the motor shaft again. If it still reverses, this suggests the TB6600 is at fault. If it doesn’t reverse, this suggests the ESP32 or code.
Hope this helps!
Greetings Wayne,
I was relieved to see your project involving the TB6600 operating at a lower than spec’d voltage. I was concerned about having to cobble together a level shifter to boost the anemic ESP32 to a level strong enough to drive the optos in the 6600, but alas it works fine as it is!
Is there a part two for this post still in works? I’m curious why you chose to drive the high side of the opto inputs, and tie the low sides together with the motor ground. Isn’t it electrically noisy?
Secondly, what firmware are you running on the ESP, looking at your next project the Alexa enabled bar, I’m guessing it’s a WiFi enabled firmware. Have you experienced WiFi interrupts causing the stepper to be a little crunchy?
I’m experimenting with ESP32 driving a 1200 oz/in nema 34 stepper right now as well, with the same TB6600 driver. I have the high sides all tied to the 3v3 rail from the ESP, and switch the low sides using the ESP, figuring it’s safer to sink current than source it. Motor bus remains separate.
Using ESPHome for the firmware, it drives OK but has occasional hiccups which I can only assume are due to wifi interrupts stealing cpu time at the wrong time and interrupting the pulse train.
Thanks! Gordon
Hi Gordon,
Hope you’re well and thanks for the comment. Like you I instantly jumped to a level shifter but I thought I would give it a go without as a test – I’m glad I did! I usually play with CNC machines and knowing the TB6600 works like this is a big plus for me.
With regards to joining the grounds together I was a little concerned about noise from the motors. But after a little reading around about the importance of shared grounding, my logic was I would tie them together and test. If things seemed a bit unstable I would then add in a noise filter on the HV side. However, everything worked well so I didn’t bother in the end. Although I think you are right, switching the low sides might be the better way to go.
The code I am using is a modified version from my post how to control a stepper motor from alexa. You can download the full code from that post. The only modification is basically some additional code to control from LED strip lights in the bar.
So far I’ve been running this set up for about 3months and it has been pretty reliable – so much so my wife recommended we put a daily limit on the number of times the bar can be opened! Occasionally, I notice that the ESPAlexa side of things stops responding so I have got into a habit of giving it a restart every 3weeks or so (I am tempted to program this in). I also have a capacitive touch switch which also opens the bar, so no issues when Alexa fails on me.
I will be writing up a detailed build guide for the bar which will include some more details on the circuit and firmware. Apologies for not getting this out sooner – unfortunately house DIY has taken over fun jobs at the moment!
I dabbled with ESPHome when I was running a Home Assistant set up in the past – its a fantastic set up. The device type support is great. The ESPAlexa set up I am using treats everything as a light so not ideal. I’d be really interested to hear how you get on!
Thanks,
Wayne
Thanks for the fast response.
So far so good on my robotics project. It’s neat controlling the big heavy NEMA34 motor using a tiny wireless microcontroller. So far no issues keeping my driver ground separate from the digital ground. I have a USB o-scope on a shelf somewhere, I should hook it up and see what the square waves look like from the ESP driving the optos inside the TB6600. I’m using unshielded twisted pair cable (cut the ends off some old cat 5 patch cords), it seems to be working well.
I ended up getting an external optocoupler board for connecting some 12v hall switches to inputs on the ESP, that seemed safer and easier than soldering up a voltage divider to drop the output signal down. I have two channels left on that board, which I could use to drive the TB6600 if needed.
Regards,
Gordon
Great to hear Gordon – I like the use of the CAT5! I have millions of those hanging around so useful to remember. Nema32 is a beast – what are you driving?
Also, part 2 post on the Alex enabled bar is in progress and should be out soon.
Thanks,
Wayne