I want to control a Nema 17 stepper motor using Arduino Mega and a4988 driver.
The problem is when I turn the Arduino on, or when I press reset button in it, or when I try to upload code on it, the stepper motor randomly vibrates and rotates back and forth for 1 second, and after that all things works fine just as programmed. There is no delay between turning the Arduino on and the vibration. I tried to remove unnecessary codes but still stepper motor vibrates on start even with uploading following code to the Arduino:
Note that I also added Enable pin from driver to pin 4 of Arduino to disable driver on setup to check if vibation goes away (as in the code), but didn't helped.
I use a 320 watts computer power supply to power stepper motors with 12volts/18amps.
I also tried 5 different stepper motors and 5 different a4988 drivers, but same thing was happening all the time.
Stepper motors have no label on it. All I know is that the store owner that I bought the Prusa i3 kit from said the motors are made in Taiwan and their torque is 4kg.cm. That's all I know about it. But I sent a message to him to tell me the exact model and I'll tell you when he replies to my message.
I just checked impedance between ground pin and potentiometer and it says it's 4. All drivers are set on 4 by default (and it was working with that setting on the 3d printer).
You have probably not set the A4988 current limit correctly. Study the A4988 data sheet to learn how, and watch Pololu's video (guaranteed to work properly only for their drivers, though).
You also need to know the motor details, and we can't help until you provide those details.
I tried to set current limit from very low values to higher values but didn't fixed the issue. But I will stop guessing values after the store owner replies to my message (right now, it's not working hours here).
Also I noticed something new, when I remove following two lines from the code above, the motor keeps vibrating and spins randomly for ever.
Obviously I'm not an expert in electronics, but my skeptical programmer mind keeps saying that there is a problem with step pin. I'm suspecting that Arduino sends signals to the driver as soon as it starts to boot, before running setup function.
I tried to change driver pins from PWM pins 2,3,4 to digital pins 22,23,24 and also disabling driver in first line of setup function (following code), but no success.
One other thing that I just noticed is that the weird vibration goes away as soon as Arduino's LED stops blinking on start.
Also when I connect/disconnect 12v power source to the driver (V-Mot) after that first second, there is no vibration on motors and everything works fine.
The correct solution is to ensure that all inputs have appropriate pullup or pulldown resistors, so they are not floating during program upload, or Arduino starting up.