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.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.