vibrating stepper motor when using ESP32 and L298N motor driver from keyestudio

35 Views Asked by At

I have got an ESP32 dev board, a NEMA17 stepper motor and an L298N motor driver from keyestudios. I’ve linked IN1 and IN2 on the motor driver to pins 5 and 18 respectively on the ESP32, and IN3 and IN4 to pins 2,4 as well, from the motor driver to the stepper motor i've connected the MOTORA output to 1 of the coils on the motor (its a 4 pin motor) and MOTORB to the second coil. i have already tested that the connected coils are actually the right ones, however when i power everything on the motor just vibrates instead of rotating, and both the driver and motor heat up rapidly. (i use a 5v supply from my computer for the ESP32 and a 12v plug power supply for the motor driver)

#include <Arduino.h>
#include <AccelStepper.h>

// ESP32 Pin Definitions
 // Enable A (not used in this code, but might be necessary for some setups)
const int IN1 = 5; // Input 1
const int IN2 = 18; // Input 2
const int IN3 = 2; // Input 3
const int IN4 = 4; // Input 4

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::FULL4WIRE, IN1, IN2, IN3, IN4);

void setup() {
  // Initialize serial port for debugging
  Serial.begin(9600);

  // Set initial speed and acceleration
  stepper.setMaxSpeed(500); // Adjust this value to find a good balance for your setup
  stepper.setAcceleration(100); // Adjust this value to find a good balance for your setup
}

void loop() {
  // Example of controlled movement
  if (stepper.distanceToGo() == 0) {
    // Randomly choose a new position within a range
    long newPosition = random(-1000, 1000);
    stepper.moveTo(newPosition);

    // Log the new position
    Serial.print("Moving to position: ");
    Serial.println(newPosition);
  }

  // Continuously run the stepper
  stepper.run();
}
0

There are 0 best solutions below