Erratic stepper motor behavior when "serial.print.." contained in code

Hi there,

I'm at the early stages of the electronics side of a project involving a stepper motor. I'm very much at the beginning of my journey into the World of stepper motors, hence why the code is so basic. When I include a serial print line in 'void loop' section the motor is behaving differently to when this line isn't included.

Details as follows:

Board: Arduino Uno
Motor driver: TB6600 ( set to200 steps per revolution, 2A/2.2A pk)
PSU: 36V DC 9.7A
Motor: Nema 23 3A bipolar

Wiring diagram attached (taken from makerguides.com).

When I run this code the motor judders and doesn't turn:

/* Example sketch to control a stepper motor with TB6600 stepper motor driver and Arduino without a library: continuous rotation. More info: https://www.makerguides.com */
// Define stepper motor connections:
#define dirPin 2
#define stepPin 3
float i = 1;

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  // Set the spinning direction CW/CCW:
  digitalWrite(dirPin, HIGH);
  Serial.begin(9600);

  
}
void loop() {
  // These four lines result in 1 step:
  i ++;
  Serial.println(i/200);
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(1000);
  

}

When I run this code (without serial.println(i/200) the motor runs fine:

/* Example sketch to control a stepper motor with TB6600 stepper motor driver and Arduino without a library: continuous rotation. More info: https://www.makerguides.com */
// Define stepper motor connections:
#define dirPin 2
#define stepPin 3
float i = 1;

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  // Set the spinning direction CW/CCW:
  digitalWrite(dirPin, HIGH);
  Serial.begin(9600);

  
}
void loop() {
  // These four lines result in 1 step:
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(1000);
  

}

Any help would be much appreciated.

Thanks,
Marc

I notice from your wiring diagram that you are not enabling the controller. Why not? Or is there a jumper on the board that enables it permanently?

Paul

marcyagi:
When I run this code the motor judders and doesn't turn:

I think the problem is that Serial.println() is being called so often that the Serial Output Buffer will fill up and the Arduino will wait for it to empty. It is not a good idea to try and print with every single step.

...R

Especially at 9600 baud. Pick up the pace a little.

However, I can't see why that would cause a total failure to step. I would expect it to be slower but still work.

Thanks for your replies.

My understanding is that by leaving the ENA- & ENA+ wires disconnected the motor should work because the enable pin is always LOW thus the driver is always enabled.

I'm going to add code so that the count is only printed every second or so - I will let you know whether this fixes the problem.

Thanks,
Marc