Stepper motor not running with Arduino - Panddive PD42-3-1141

Hi all,

I have a stepper motor, Pandrive PD42-3-1141, documentation: http://www.trinamic.com/fileadmin/assets/Products/Drives_Documents/PD-1141_hardware_manual.pdf

I have connected pin 1 and pin 2 of the "Power and RS485 Connector" to a 24V powersupply (pin 1 to the - and pin to the + side of the power supply)
Furthermore, I have connected the Step/Direction Connector, pin 1 to the +5V op the arduino mega 2560, pin 3 (step) to pin 2 of the arduino board and pin 4 (direction) to pin 3 of the arduino.

When running the following program, absolutely nothing happens:

#include <AccelStepper.h>
#define STEPPER1_DIR_PIN 3
#define STEPPER1_STEP_PIN 2

AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);

void setup()
{
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(200.0);
stepper1.moveTo(1000);
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
}

Additional info: running the stepper motor on USB, the motor itself runs just fine.

Can someone see what I'm doing wrong?
Many thanks!!!!

Stefan

Try the first example in this Simple Stepper Code - it is the simplest thing possible to get a motor moving. Make sure your program matches the pin connections :slight_smile:

Once you know that the Arduino can control the motor it is easier to debug a more complex program.

...R
Stepper Motor Basics

I modified the program a bit (I have no buttons or leds), to:

byte directionPin = 3;
byte stepPin = 2;

boolean buttonCWpressed = false;

unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 25; // milliseconds

void setup() { 
  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with millis()");
  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
}

void loop() { 
 curMillis = millis();
 readButtons();
 actOnButtons();
}

void readButtons() {
 buttonCWpressed = true;
}

void actOnButtons() {
 if (buttonCWpressed == true) {
 digitalWrite(directionPin, LOW);
 singleStep();
 }
}

void singleStep() {
 if (curMillis - prevStepMillis >= millisBetweenSteps) {
 prevStepMillis += millisBetweenSteps;
 digitalWrite(stepPin, HIGH);
 digitalWrite(stepPin, LOW);
 }
}

I've checked the wirering, pins 2 and 3 of arduino are connected the right way.
The +5V of the arduino is connected to the Common, as discribed earlier.
The manual doesn't say anything about the ground, should I connect the ground of the arduino to somehing as well? If so, to what should I connect it to?

sfir184:
I modified the program a bit (I have no buttons or leds), to:

Start with the simpler first example in the link I posted. It does not need buttons.

It is much easier to help by remote control if there are as few changes as possible - preferably none.

I don't think your driver needs a GND connection - the +5v seems to be sufficient.

Have you a connection to Enable some drivers need it, others don't. Try it with both HIGH and LOW.

...R

I missed the simpler program in your example, my mistake.

I now tested it with:

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 3;
byte stepPin = 2;
byte enablePin = 7;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps


void setup() { 


  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  digitalWrite(enablePin, LOW);
  
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
  delay(3000);
  

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  Serial.println("StepperTest Stopped");
}

void loop() { 
}

The program itself seems to run fine: On the serial monitor I get a message saying "Starting StepperTest" and after a while, the message "StepperTest Stopped" popped up.
The stepper itself doesn't move a bit :frowning:

EDIT: Forgot to mention: I tried 3 different settings:

  1. digitalWrite(enablePin, LOW);
  2. digitalWrite(enablePin, HIGH);
  3. //digitalWrite(enablePin, LOW);

You don't seem to have

pinMode(enablePin, OUTPUT);

Also you have drawn my attention to an error in my program. The pinMode() lines should come before any digitalWrite() to that pin. It would have made little difference with the LED which changes regularly but your enable is only set once.

Try this version

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing
// this version uses enablePin

byte directionPin = 3;
byte stepPin = 2;
byte enablePin = 7;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps


void setup() {


  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(enablePin, OUTPUT);

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  digitalWrite(enablePin, LOW);
 
  delay(2000);

 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  Serial.println("StepperTest Stopped");
}

void loop() {
}

...R

Just tried your version but still no luck.
I again tried it with the enablePin HIGH, LOW and with the enablePin commented out.

Also, I tried hooking up the USB to a computer while running the arduino. When I try to directly run the stepper over the usb while the arduino is sending commands, it won't let me. When disconnecting the arduino, the stepper runs on usb just fine. This must mean that the stepper is getting some signal from the arduino, but just isn't running :frowning:

Hi,
The fact that
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

I agree with @TomGeorge - time for a circuit diagram.

And, just a thought, is there some switch on the driver that needs to be set to tell it how it is to be controlled?

And, have you read EVERY word of the instructions at least 4 times?

...R

Figure 3.8 in the instructions tells you exactly how to connect, and also says that the enable pin
function depends on the firmware - that means you will need to try both possibilities.

To send a step pulse don't do this:

  digitalWrite(stepPin, HIGH);
  digitalWrite(stepPin, LOW);

but rather do this:

  digitalWrite(stepPin, HIGH);
  delayMicroseconds (10) ;
  digitalWrite(stepPin, LOW);

the delay is required otherwise the step pulses will get swallowed up in the slow rise/fall times of the opto-isolator.

@MarkT: in the code, I tried both: both with a delaymicrosoconds (20) and without (See first part of the code (with delay) then second part of the code (without delay)).

@Robin2: There is no switch :frowning: And yes, i've read the instructions many times over. I think I'm doing everything as it is described in the instructions, but there is obviously something wrong, since the motor isn't running :wink:

@TomGeorge: I don't have CAD unfortunatly, but I did the best I could with an mobile camera, MS Word and some creativity :wink:

Let me know what you think.

Because that controller uses opto isolators the delay of 10us is almost certainly required, unless you
can put an oscilloscope on the output of the isolator and check, assume it is needed.

Hi,
You have the socket from the arduino miswired.


Pin 1 is 5V.
Pin2 is Enable
Pin3 is Step
Pin4 is Direction.
The arduino output needs to go LOW to activate the appropriate drive input.
The optocouplers in the driver are common to 5V.

Tom... :slight_smile:

Hi,
OP's diagram.

Tom... :slight_smile:

I'm trying to undestand what you are saying, but I don't see how I miswired the arduino socket:
I connected Pin 1 to the +5V
Connected Pin 2 to socket 7
Connected pin 3 to socket 2
and connected pin 4 to socket 3.

If this is not correct, how should I wire it instead?

Hi,
Sorry you have got it correctly wired, check that you have 5V on Pin 1.

I've checked with a volt meter and the volt meter says 4,5V.
This raises two questions:

  1. Why does the arduino only have 4,5V out? (or is my voltmeter off by half a volt?)
  2. Is 4,5V enough for the steppermotor?

Hi,

  • Now measure the volts on the two control outputs of the arduino when you have the code running.
  • If you have the arduino on its own, what is your 5V pin?
  • If you plug the USB into the driver and PC, but don't run the application, do you get any response when the arduino runs?

Tom... :slight_smile:

Little correction --> I've measure the 5V arduino pin again and my multimeter now gives 4,88V (While the program is running, and while the program is not running)

The Enable pin returns 3,46V whin "HIGH"
The directionPin measures 4,89V when "HIGH" and 0,12V when "LOW"
The StepPin gives a weared value: 0,12V Could be because my multimeter is not fast enough to pick up the high signal?
So I changed:

int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps

to:

int pulseWidthMicros = 2000; // microseconds
int millisbetweenSteps = 2000; //milliseconds - or try 1000 for slower steps

Now the value of the steppin voltage changes from 0,12V to 0,14V very briefly, but changes back to 0,12 almost directly.

So I made a new program:

byte directionPin = 3;
byte stepPin = 2;
byte enablePin = 7;
byte ledPin = 13;


void setup() {


  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(enablePin, OUTPUT);

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(1000);

  digitalWrite(enablePin, HIGH);
  digitalWrite(directionPin, HIGH);
  digitalWrite(stepPin, HIGH);
  digitalWrite(ledPin, HIGH);

  delay(4000);

  digitalWrite(enablePin, LOW);
  digitalWrite(directionPin, LOW);
  digitalWrite(stepPin, LOW);
  digitalWrite(ledPin, LOW);
  
  delay(4000);

  digitalWrite(enablePin, HIGH);
  digitalWrite(directionPin, HIGH);
  digitalWrite(stepPin, HIGH);
  digitalWrite(ledPin, HIGH);

  delay(4000);

  digitalWrite(enablePin, LOW);
  digitalWrite(directionPin, LOW);
  digitalWrite(stepPin, LOW);
  digitalWrite(ledPin, LOW);
 
}

void loop() {
}

Now I do get a readout of 4,95V on the stepPin when signal is HIGH. and 0,12V when LOW

What strikes me as odd, is that the readout of the steppin is different as I expected.

To your point 3: No other response

That looks like an expensive motor/driver. Have you emailed the manufacturers for advice?

...R