USB port broke while stepper motor was being controlled

Hi there!

With the following code I try to control two stepper motors:

#include "AccelStepper.h"

#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38
#define X_MIN_PIN           3
#define X_MAX_PIN           2

#define Y_STEP_PIN         60
#define Y_DIR_PIN          61
#define Y_ENABLE_PIN       56
#define Y_MIN_PIN          14
#define Y_MAX_PIN          15

#define Z_STEP_PIN         46
#define Z_DIR_PIN          48
#define Z_ENABLE_PIN       62
#define Z_MIN_PIN          18
#define Z_MAX_PIN          19

#define E_STEP_PIN         26
#define E_DIR_PIN          28
#define E_ENABLE_PIN       24

#define Q_STEP_PIN         36
#define Q_DIR_PIN          34
#define Q_ENABLE_PIN       30

#define SDPOWER            -1
#define SDSS               53
#define LED_PIN            13

#define FAN_PIN            9

#define PS_ON_PIN          12
#define KILL_PIN           -1

#define HEATER_0_PIN       10
#define HEATER_1_PIN       8
#define TEMP_0_PIN          13   // ANALOG NUMBERING
#define TEMP_1_PIN          14   // ANALOG NUMBERING

//char serialData;
int ct = 0;

AccelStepper stepperY(1, Y_STEP_PIN, Y_DIR_PIN); // 1 = Driver

void setup() {

  pinMode(FAN_PIN , OUTPUT);
  pinMode(HEATER_0_PIN , OUTPUT);
  pinMode(HEATER_1_PIN , OUTPUT);
  pinMode(LED_PIN  , OUTPUT);
  pinMode(X_STEP_PIN  , OUTPUT);
  pinMode(X_DIR_PIN    , OUTPUT);
  pinMode(X_ENABLE_PIN    , OUTPUT);
  pinMode(Y_STEP_PIN  , OUTPUT);
  pinMode(Y_DIR_PIN    , OUTPUT);
  pinMode(Y_ENABLE_PIN    , OUTPUT);
  pinMode(Z_STEP_PIN  , OUTPUT);
  pinMode(Z_DIR_PIN    , OUTPUT);
  pinMode(Z_ENABLE_PIN    , OUTPUT);
  pinMode(E_STEP_PIN  , OUTPUT);
  pinMode(E_DIR_PIN    , OUTPUT);
  pinMode(E_ENABLE_PIN    , OUTPUT);
  pinMode(Q_STEP_PIN  , OUTPUT);
  pinMode(Q_DIR_PIN    , OUTPUT);
  pinMode(Q_ENABLE_PIN    , OUTPUT);
   digitalWrite(X_ENABLE_PIN    , LOW);
   digitalWrite(Y_ENABLE_PIN    , LOW);
   digitalWrite(Z_ENABLE_PIN    , LOW);
   digitalWrite(E_ENABLE_PIN    , LOW);
   digitalWrite(Q_ENABLE_PIN    , LOW);


void loop () {
  if(digitalRead(X_MIN_PIN) == 0){
    ct += 1;
  } else {

This worked pretty well at first until my PC suddenly shut down. Since then, my USB port has unfortunately stopped working, although I have updated and reinstalled the driver in the device manager.

Does anyone have any idea what could have caused the problem so that another port won't break next time?
Thank you very much in advance!

Hi All

I have run into the same problem when using a power supply plugged into the wall to run the steppers I could not have the usb plugged in at the same time as the power supply was. had to do the programming and then disconnect the usb to run it. found out I could use my lap top as long as it was not plugged in to the wall.


Whilst in the correct section a schematic would be most useful.
Even if it is hand drawn !
From what you have posted it may be you were powering the motors via the Arduino ? (BAD THING)
Disconnect EVERYTHING from the board then try an upload of the example blink sketch.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Simple the Arduino is a computer, NOT a power supply. Rule 1 never power ANYTHING inductive with the Arduino even if it can supply the power. What you are experiencing is probably failure to follow this rule. Also you may have fed power back into the USB port, this is a big NO-NO. I do not know how many computers you can afford to buy but try this first. Why not start by defining the problem with specifications including a flow chart and schematic. Define what is the expected outcome. Purchase the Arduino cookbook and read it, this will give you some basics. also use the online tutorials and videos available, there are many good ones on this web site. At this point you will be able to define the problem and may have already solved it.

Using a powered USB hub to connect to the Arduino can protect your computer to some degree.

If you were driving a stepper you should have been using a stepper driver like the DRV8825.

You can add 1k--2k resistors in series with both the step and direction pins to such a driver to protect
the Ardiuno much better should the driver get fried, which sounds like what happened here, allowing
high voltages back into the Arduino and USB cable.

Such resistors also allow you to power down the stepper driver while uploading a sketch.

Unfortunately I forgot to give you some significant information.
The project was based on several tutorials, including 3D Printer | Homemade - Part 1 - YouTube.
I used a 240 watt power supply, an Arduino Mega 2560 and a RAMPS 1.4.

Grounds may be an issue. Back in the era of the Northwood P4, it wasn't uncommon for a computer to reboot when something was plugged into the USB port and a static discharge ocurred at the moment the shields met. I have seen that with multiple computers of that era. If you hook two separately grounded systems together, each ground may be at a different potential. If you are using a laptop at the end of that USB cable, try running the laptop from the battery, rather than plugged into the wall.

Not directly related to your issue:
Not being familiar with 3D printers, but a little familiar with stepper motor drivers. I noticed that each driver has a current adjust pot on it in the video. It's common to run stepper motors at higher than rated voltages to get some snap in the motion. At higher voltages, the maximum winding current is reached more quickly. You must set the current protection on the driver to make sure that the current rating is not exceeded at the voltage you are using to drive the stepper. The stepper can draw a lot of current, which could also brownout some other parts of the system if the current is uncontrolled.

Steppers don't (shouldn't) have a rated voltage, they are current driven... A lot of people selling them
have no clue about this.