Adjust stepper motor with l298

hello everyone. I want to control the 4-pin stepper motor fast, slow according to the potentiometer, and make the stepper motor rotate according to the number of revolutions I want, I have also searched for a few documents but still can't, can anyone tell me the principle How to adjust the number of revolutions of the stepper motor and the speed and slowness of the motor? thanks!

The L298 is a crappy DC motor driver an even worse stepper driver. Post a data sheet for your motor and we can help you to find a better driver.

Here is a demo code that I wrote for someone else that varies the speed of a stepper with a pot. The code is written for a modern step/dir stepper driver like the A4988 or DRV8825. It uses the AccelStepper library. Hopefully you can extract the part(s) that you need.


// rotate stepper 1 turn with push of button at speed set by potentiometer.
// by groundFungud AKA charlie goulding.

// change step, dir, button and pot pins to match your set up
// tested with an Uno with CNC shield V3,
// hence the step, dir and enable pin numbers
// stepper set to 4X microstepping
// pushbutton toggles stepper move direction

#include <AccelStepper.h>

const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;  // stepper enable for CNC shield
const byte buttonPin = 9;  // wired to ground and pin 9
const byte potPin = A0;

bool moveDir = false;  // stepper direction flag
long moveSteps = 800;  // number of steps to move per button press

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, stepPin, dirPin);

bool lastButtonState = HIGH; // button history

void setup()
{
   Serial.begin(115200);
   pinMode(enablePin, OUTPUT);
   pinMode(buttonPin, INPUT_PULLUP);
   digitalWrite(enablePin, LOW);  // enable steppers
   // Change these to suit your stepper if you want
   stepper.setMaxSpeed(100); // initial speed only
   stepper.setAcceleration(500);
}

void loop()
{
   int potValue = analogRead(potPin); // read pot   
   potValue = map(potValue, 0, 1023, 50, 4000);
   stepper.setMaxSpeed(potValue); // change the speed by pot setting.
   stepper.setAcceleration(potValue / 2);
   
   static unsigned long timer = 0;
   unsigned long interval = 50;  // check switch 20 times per second
   if (millis() - timer >= interval)
   {
      timer = millis();
      // read the pushbutton input pin:
      bool buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW) // button went from not pressed to prssed
         {
            Serial.println(potValue);
            moveDir = !moveDir; // toggle direction
            if (moveDir == true)
            {
               stepper.move(moveSteps);  // move 800 steps, RELATIVE to current position
            }
            else
            {
               stepper.move(-moveSteps);
            }
         }
      }
      // save the current state as the last state,
      //for next time through the loop
      lastButtonState = buttonState;
   }
   stepper.run();  // must be called very often
                   // ideally once every loop iteration
}

Thank you for sharing with me, I will refer to A4988 and DRV8825. thank you so much!

Maybe your L298 can drive the stepper motor, but if you don't tell us which stepper motor...

Leo..

I use a 4 pin stepper motor at 1,8 degrees or more. maybe I don't understand you talk something but you know, can you talk to me about control stepper motor with l298? thank you

That tells us nothing about the electrical specifications of the stepper.
Post a weblink to the stepper motor.
Leo..