1

I'm using a NEMA 17 stepper motor with A4988 motor driver and Arduino Uno board. I have used full microstepping (1/16th, so one revolution = 3200 steps).

I'm coming across this strange problem. Whenever I upload any code, for example

void loop()
{  delay(20);
   digitalWrite(stepPin, HIGH);
   delayMicroseconds(100);
   digitalWrite(stepPin, LOW);
   delayMicroseconds(100);
}

the motor spins rapidly for about 1000 steps clockwise (before "avrdude done. Thank you." appears), and then executes the code. When a similar code is placed in void steup() with an empty void loop (), the same thing happens - motor spins rapidly, executes what's written and then stops. The initial rapid spinning is always the same speed and direction, no matter what code is uploaded.

When I upload empty code -

void setup() {}
void loop() {}

the motor continuously spins rapidly with the same speed, same direction. If I add a delay(1000) anywhere in the above program, same thing happens. When I long/short press the reset button on the board, same thing happens. When I upload programs unrelated to the motor, like the example Blink program, same thing happens. Buddy of mine told me to upload the eeprom_clear program from Examples, same thing happened.

I tried uploading this program -

void setup(){
for (int i=0; i<=13; i++)
  {pinMode(i,OUTPUT);
  digitalWrite(i,LOW);

  }  

}
void loop(){}

and motor spun like crazy while uploading (same ~1000 steps, clockwise direction) and then stopped. Uploading any program after this has same behaviour. If it an empty/delay only program, motor spins crazily forever. If it is a specific program (example - run for 1000 steps), it spins crazily while uploading, executes the main program, then stops.

As I'm typing this, the motor is spinning like a crazed maniac even though I just uploaded an empty void setup() {} void loop() {} program.

I've tried changing the computer that the Arduino is connected to, I've changed the motor driver and plugged in a brand new one, I've changed the USB cable, I've changed the motor and I've reset all Arduino and breadboard connections. I went to Device Manager > Ports (COM & LPT) > USB-SERIAL CH340(COM5) and updated driver. Current Arduino IDE is Arduino 1.8.10 on Windows 10.

No change in outcome. This problem has been spoiling my sleep for the past few nights as I can't upload anything to the board without the Arduino either spinning crazily endlessly or spinning crazily just while uploading and then behaving properly.

Any solutions? Thanks a lot!

Edit - Added schematic of the electronics connections. Original image from www.lastminuteengineers.com

Schematic of the electronics connections. Original image from www.lastminuteengineers.com

8
  • How do you have it connected to the Arduino? You aren’t using pins 0 or 1 are you? – Delta_G Nov 18 '19 at 21:48
  • Maybe the pins are floating during programming and the motor driver sees this as valid input? An exact schematic would help. – Maximilian Gerhardt Nov 18 '19 at 22:02
  • Pins 9,10,11 are for microstepping (all HIGH for 1/16 stepping). Pin 2 for direction, pin 3 for Step mode. Also using 5V pin and GND pin from the POWER section of the Arduino Uno board, connected to the appropriate pins of A4988 motor driver. – Rahul Bharathwaj Nov 18 '19 at 22:03
  • @MaximilianGerhardt - I've added the schematic of the connections. – Rahul Bharathwaj Nov 18 '19 at 22:31
  • Most pins are floating while programming. Do some pull-up or pull-down resistors help? – the busybee Nov 19 '19 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.