Bipolar stepper + L298N + AccelStepper: current spikes start/end of rotation

I've got a project set up largely based on Stepper Motor with L298N and Arduino Tutorial (4 Examples) using roughly the same schematics:

One notable difference: I've split the input and also connected the arduino (mega) jack to the same 12V DC 2A adapter/power source. There's also a volts/amps display in front of everything to measure what's going on.

(There's also another split after the volts/amps meter to a step-down module to create a separate 5V circuit for other LEDs/servo's down the road, but that's not currently connected to anything. Basically, the goal was to plug in a single jack to power everything in the box.)

The motor is a NEMA17 bipolar stepper which I've not found any particular SKU or datasheet for, but according to the sellers' information (Stappenmotor - 23mm dik - 0.13N.m - 1.0A - NEMA17 - JST-PH Compatible Connector - NEMA17-JSTPH013NM) should be using 1.0A per phase. There's no heavy load on the motor; it rotates a GT2 pulley connected with other pulleys attached to leadscrews in bearrings, it's all rotating smoothly.

The motor controller is a L298N, connected to the 12V input, which has a max current of 2A per bridge, times two bridges = max 4A. I assumed it'd only use what the motor asks for (2x1.0A=2A total) but that was apparently naive, as it seems to be drawing around 1.5-2.5A during regular movement.

At the start and end of the movement the power adapter kills the current, so it's apparently spiking beyond the power limits. Arduino continues to run as that's currently connected via USB for debugging, but the rest of the circuit shuts down.

The code is pretty simple (included after my questions below), and uses the AccelStepper library, with acceleration/deceleration to avoid heavy spikes, unfortunately not with the result I'd hoped tho it's still smoother than the standard Stepper.

  1. Yes, I'm going to get a more powerful input source, I'm looking at a 12V 4A/5A.

  2. Is there anything more I can do here from a software point of view to avoid spiking? This motor will only run once or twice an hour, for around 20 seconds, to move a platform up/down with the leadscrews. It's okay if that happens slower due to a lower current, tho it seems slowing the acceleration only causes it to draw more.

  3. I'm seeing comments on the forum that the L298N is quite old and not very efficient (it certainly warms up a fair bit even after short operation, which is why I've added a fan - not currently connected - to the top of the box to help with cooling) - what might be a better motor driver for a bipolar stepper? I'm seeing a bunch of different ones (L9110S, A3967 EasyDriver, DRV8825, A4988, ...) but would appreciate recommendations for a better replacement as I truly have no idea how to compare these things in a useful way. Having one with a current limiter seems like it would be a good idea so it doesn't try to draw more than eg 1.0A - would the DRV8825 be a better option?

Code (functions called from main tab setup/loop):

// Include the Arduino Stepper Library
#include <AccelStepper.h>

// Define the AccelStepper interface type:
#define MotorInterfaceType 4

// Create Instance of AccelStepper library
AccelStepper platform_stepper(MotorInterfaceType, 8, 9, 10, 11);

void platform_setup()
{
  platform_stepper.setMaxSpeed(400);
  platform_stepper.setAcceleration(50);
}

void platform_loop() 
{
  // Set target position:
  platform_stepper.moveTo(1000);
  // Run to position with set speed and acceleration:
  platform_stepper.runToPosition();
  delay(2000);
  // Move back to original position:
  platform_stepper.moveTo(0);
  // Run to position with set speed and acceleration:
  platform_stepper.runToPosition();
  delay(2000);
}

The L298 is not a stepper driver. It is for brushed DC motors, although it can be used with some old fashioned, low current steppers. The L298 is also midleadingly advertised, and cannot handle even 1 Ampere current per channel (continuous) without extra cooling. Unfortunately it is cheap and sold everywhere, so there are lots of bad tutorials to mislead beginners.

With your motor, the L298 will overheat and shut down. You need a current limiting stepper driver.

Any of the modern stepper drivers, like the A4988 or DRV8825 will work. You MUST follow the instructions to set the current limit properly.

Pololu sells the best selection of modern stepper motor drivers. Of course you can buy cheap clones on Amazon or eBay, but you will probably get a counterfeit, reject or used motor driver chip, and of course, Pololu's clear instructions for setting the current limit won't apply.

I assumed it'd only use what the motor asks for (2x1.0A=2A total)

The motor does not "ask for current". The 1.0A specification is the maximum allowed steady state current per winding. If you apply 12V directly to that motor, each winding will draw (12 V)/(4 Ohms) = 3 Amperes (6 Amperes total), and the motor will eventually burn up.

Also consider reducing the voltage to the Arduino.
They will often work better with 7 to 10 volts and be more reliable long term.

Spikes have so many causes but the more common reasons are bad wiring, lack of shielded cables with long runs, insufficient power supply and a few more.

Most common cures are ferrite rings on longer runs of cable, shielded wiring, Capacitors and or snubber circuits on external buttons/controls,

The search function (upper right of screen) will bring you some useful information.

EDIT..
Going back to your original Q. Almost any OTHER motor driver will suffice if that is your complete circuit.
Do AVOID L298, L9110, ULN2003
Always use a heatsink on your driver chips (I use super glue for mine)

But if you have other things also connected then a better schematic may be of use to those wanting to help.

A picture of your current set up may also be useful ?

Thanks jremington & ballscrewbob! Your replies are very useful and I learned a couple of new things today. :slight_smile:

The seller specifically advertised the L298N as suitable for bipolar steppers, so I'll have to be a bit more critical of what they say moving forward.

I'll get the DRV8825 to replace the L298N to make sure I'm properly limiting the current. That also comes with a heatsink and I'll keep the fan in as well.

For now things are working as expected and I'll just have to get the higher power supply and current-limiting stepper driver hopefully.

--

Attached is an annotated picture of what I'm doing (with the L298N still in). Figured the simplified schema before was easier than the mess I'm making!

The bit on the right with the V/A display and the input is a bit hard to see, but basically the thicker red/black cables are inserted between the ground on the input jack and the ground inside the box: ground on terminal block > thick red cable to meter > thick black cable to ground on the jack. The jack input positive is directly attached to the terminal block, going to the step-down and the power supply thingy on the top left to power the mega and stepper driver.

Also attached is an image of the set-up of the stepper itself with the pulleys, timing belt, leadscrews, and the brass bits the platform will be attached to.

A man after my own heart :grin:
I do a lot of my case work with what I have to hand too !

The only thing I can see is that the motor wires seem to dissapear under the MEGA.
And you seem to have a positive and negative crossing at almost 90 degrees to them as they go under the board.

I would move the motor wires and if power has to cross the motor wires do it at an angle or shield some of them.

Also going to point you to a CNC related post that covers a lot of things some of them may be very useful for your application.