Tool/software:
Hi Team,
Hope you are doing well.
I am using DRV8421BDGQR stepper motor deriver IC and design costumer required customized design board to derive the NEMA17 stepper motor. I control it using four pin namely IN1, IN2, EN. I using the Arduino IDE and ESP32 C3 development board and write the sample code to derive the the NEMA17 motor clock wise and counter clock wise. Motor is successfully derive only clock wise direction.
Issue is that stepper motor is not to derive counter clock wise direction. Please guide me to derive the motor clock wise and counter clock wise direction.
I use 12V 2A power adopter, I common all ground like ESP32C3 and power adopter. The ESP32C3 is powered via USB cable connected to PC and ESP32C3 run on 3V3 volt. Also I check on 12V 1A stepper motor.
Please find the attachment of schematic and code snippet.
// Pin Definitions
const int EN_PIN = 1; // Enable pin for DRV8421B
const int IN1_PIN = 5; // Input 1 pin for direction control
const int IN2_PIN = 6; // Input 2 pin for direction control
// Motor Control Parameters
const int STEPS_PER_REVOLUTION = 300; // Typical for NEMA17 (1.8 degree step angle)
void setup() {
// Initialize pins
pinMode(EN_PIN, OUTPUT);
pinMode(IN1_PIN, OUTPUT);
pinMode(IN2_PIN, OUTPUT);
// Initialize Serial for debugging
Serial.begin(115200);
// Ensure motor is initially disabled
digitalWrite(EN_PIN, LOW);
}
// Function to rotate motor clockwise
void rotateClockwise(int steps) {
// Enable the driver
digitalWrite(EN_PIN, HIGH);
// Set up for clockwise rotation
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, HIGH);
// Step the motor
for (int i = 0; i < steps; i++) {
// Alternate between IN1 and IN2 to create stepping
digitalWrite(IN1_PIN, High);
delayMicroseconds(3000);
digitalWrite(IN1_PIN, Low);
delayMicroseconds(3000);
}
// Disable the driver
digitalWrite(EN_PIN, LOW);
}
// Function to rotate motor counter-clockwise
void rotateCounterClockwise(int steps) {
// Enable the driver
digitalWrite(EN_PIN, HIGH);
// Set up for counter-clockwise rotation
digitalWrite(IN1_PIN, LOW);
digitalWrite(IN2_PIN, HIGH);
// Step the motor
for (int i = 0; i < steps; i++) {
// Alternate between IN2 and IN1 to create stepping
digitalWrite(IN2_PIN, HIGH);
delayMicroseconds(3000);
digitalWrite(IN2_PIN, LOW);
delayMicroseconds(3000);
}
// Disable the driver
digitalWrite(EN_PIN, LOW);
}
void loop() {
// Rotate clockwise for one full revolution
Serial.println("Rotating Clockwise");
rotateClockwise(STEPS_PER_REVOLUTION);
delay(1000);
// Rotate counter-clockwise for one full revolution
Serial.println("Rotating Counter-Clockwise");
rotateCounterClockwise(STEPS_PER_REVOLUTION);
delay(1000);
}
Thanks and Regard
Manish Ruhela

