Connecting all control pins from DRV8825 to NodeMCU
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
So GPIO1 aka TX is used for some special boot mode so it can't be pulldowned: https://bbs.espressif.com/viewtopic.php?t=796
So I moved direction to gpio16 instead. Now I'm also getting a direction indicator on the NodeMCUs inbuilt LED that is connected to gpio16.
I also had problem with gpio15 not being pulldowned enough when connected to DRV8825. So for now I removed it and shorted sleep and reset together to be controlled by the same pin.
Found out that fault (that I pulled up) is connected to the sleep pin on the DRV8825. So have to remove it and see if it will work after.
Test code:
// Test sketch for drv8825 on NodeMCU v1.0
// pinout definition for generic ESP-12E
#define stepPin 3
#define directionPin 16
#define sleepPin 15
#define resetPin 13
#define m2_Pin 12
#define m1_Pin 14
#define m0_Pin 4
#define enablePin 5
#define faultPin 2
#define endswitchPin 0
#define MOTOR_STEPS 200
void setStepSize() { //Going to add more later
// Full step
digitalWrite(m0_Pin, LOW);
digitalWrite(m1_Pin, LOW);
digitalWrite(m2_Pin, LOW);
}
void setup() {
// REMEMBER THAT YOU CAN'T USE SERIAL FROM THIS POINT
// DRV8825 has inbuilt pulldown resistors for all input pins. No need to set it.
pinMode(stepPin, OUTPUT);
pinMode(directionPin, OUTPUT);
pinMode(sleepPin, OUTPUT);
pinMode(resetPin, OUTPUT);
pinMode(m2_Pin, OUTPUT);
pinMode(m1_Pin, OUTPUT);
pinMode(m0_Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
setStepSize();
digitalWrite(resetPin, HIGH);
digitalWrite(sleepPin, HIGH);
digitalWrite(enablePin, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(directionPin, HIGH);
for (int i = 0; i < MOTOR_STEPS; i++) {
digitalWrite(stepPin, LOW);
delay(10); //10 ms
digitalWrite(stepPin, HIGH);
delay(10); //10 ms
}
digitalWrite(directionPin, LOW);
for (int i = 0; i < MOTOR_STEPS; i++) {
digitalWrite(stepPin, LOW);
delay(10); //10 ms
digitalWrite(stepPin, HIGH);
delay(10); //10 ms
}
delay(1000);
}
After flashing the code the motor is spinning 360 degrees and back again, wait 1 s and repeat.
PROOF: https://www.facebook.com/beaverelectronics/videos/vb.161215301217651/242073909790273/?type=2&theater
Going to add WiFi control, add better motor control, fix the small issues and test sleep in next step.
This list is made with only mentioning how it handles digital logic and interrupts
DRV8825: https://www.pololu.com/product/2133
Pin | Function | Status |
---|---|---|
EN | Logic high to disable device output and indexer | Input, Internal pulldown |
M0 | Set step mode | Input, Internal pulldown |
M1 | Set step mode | Input, Internal pulldown |
M2 | Set step mode | Input, Internal pulldown |
RST | Logic low to reset indexer and disable output | Input, Internal pulldown |
SLP | Logic low to enter low-power sleep | Input, Internal pulldown |
STP | Rising edge move stepper one step | Input, Internal pulldown |
DIR | Logic level sets direction | Input, Internal pulldown |
FLT | Logic low when in fault condition | Output, open-drain, pullup to sleep pin |
Limit switch:
Pin | Function | Status |
---|---|---|
1 | Endstop, need interrupt pin preferably | Output, Normaly Open |
This means that we need 8 outputs that doesn't have fixed pullups and can handle boot with pulldowns on the pins. And 2 interrupt inputs with at least one that has a pullup.
As seen in the list below this means that D3 and D4 need to be inputs and one of the serial lines as output.
NodeMCU v1.0 Amica ESP-12E:
Pin | Function | Status | Can be used as |
---|---|---|---|
D0 | GPIO16 | Not usable with deepsleep, Hi-Z DIO, no interrupt | Output |
D1 | GPIO5 | Hi-Z DIO | Output, Input, Interrupt |
D2 | GPIO4 | Hi-Z DIO | Output, Input, Interrupt |
D3 | GPIO0 | No Hi-Z DIO (prefere pullup) | Input, Interrupt |
D4 | GPIO2 | Don’t connect to ground at boot time (prefere pullup) | Input, Interrupt |
D5 | GPIO14 | Hi-Z DIO | Output, Input, Interrupt |
D6 | GPIO12 | Hi-Z DIO | Output, Input, Interrupt |
D7 | GPIO13 | Hi-Z DIO | Output, Input, Interrupt |
D8 | GPIO15 | Can't have pullup (only pulldown DIO) | Output |
RX | GPIO3 | Not usable during Serial transmission | Output, Input, Interrupt (if serial not used) |
TX | GPIO1 | Not usable during Serial transmission, Don’t connect to ground at boot time | Output, Input, Interrupt (if serial not used) |
A0 | ADC0 | Analog | Not usable as DIO |
SD3 | GPIO10 | Might be connected to flashmemory!!! | Not usable |
SD2 | GPIO9 | Might be connected to flashmemory!!! | Not usable |
SD1 | MOSI | Unknown | |
CMD | CS | Unknown | |
SDO | MISO | Unknown | |
CLK | SCLK | Unknown | |
EN | Enable | DigitalWrite/Read not possible | Not usable |
RST | Reset | DigitalWrite/Read not possible | Not usable |
Create an account to leave a comment. Already have an account? Log In.
I haven't added WiFi code yet, but the motor spins now. I don't know what I did to make it work :/
Here are some points that might affect it that I thought about.
I made sure to split the GND and 12V to the motor and ESP-12E regulator directly at the connector to make the path from the DRV to the ESP long.
And made sure that the capacitor (470µF, 50V) was placed between the DRV8825 pins and the powersupply connector.
I'm using a pre-made switching regulator PCB to take down the 12V to 5V for the NodeMCU. https://www.electrokit.com/produkt/switchregulator-step-down-0-8v-17v/
Set the current limit on the DRV8825 to 0.4A as specified for my motor: hy200-17-13-0040-bx06
But I haven't added the power hungry WiFi code yet.
Nice, I did something like this a couple of years ago (https://hackaday.io/project/13122-my-dalek-build).
I had problems with electrical interference and back EMF from the stepper motors upsetting the ESP-12E. You may find some of the designs interesting. I was running two steppers for the drive and a servo/ultrasonic sensor.
AlanX
Interesting, will check it out. Sorry to here that ESP-12 didn't work for you, hope I have better luck with EMF.
Become a member to follow this project and never miss any updates
While the ESP-12E (for me) would stop working due to EMI/EMF from the steppers, it was never damaged. The worst problem was that there is very little "science" to fix this. Twisting the stepper leads, using ferrite beads and moving the ESP-12E away from the steppers worked but I don't really know which worked the best or why. It not like any or all of these measures will always work or are always necessary. It was trial and error and very little science.
The ultrasonic sensor and servo problem was back EMF and could be measured so specific things could be done to fix it. First was to block the back EMF going back through the power supply and upsetting the ESP-12E and the second was to absorb/store the back EMF current.
There were two problems with the ultrasonics sensors however, the first was that back EMF would destroy them and the second was that they did not work very well anyway.
Having said all this I have completed other stepper projects using Arduinos that worked flawlessly without any additional EMF/EMI precautions (refer to https://hackaday.io/project/29585-little-monster-scanner and https://hackaday.io/project/28478-a-better-turret).
So perhaps the ESP-12E is just "too" sensitive to EMI/EMF to be useful in this area. If I was contemplating using the ESP-12E again, I would start with separate power supplies for the ESP-12E and the Steppers, and an opto-isolator interface. In addition to separation of the steppers from the ESP-12E, and twisted steppers power leads.
Anyway best of luck, regards AlanX