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.
-
Yes, I'm going to get a more powerful input source, I'm looking at a 12V 4A/5A.
-
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.
-
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);
}