Control a DMC422C with Arduino

Robin2 has an excellent post on basic controls of stepper motors that require only pul and dir pulses. I need to run a Nema 17 42CMOB 1.8 degrees/2.5 A with a DMC422S (I have the pdf on this but it will not upload). Beautiful equipment and I'm afraid of hurting it. It seems I will need about 24 volts, I'm hoping to make do with 18 because that's the limit of my power source.

Robin2 describes how to address the pul and dir outputs. I need also to address the en, enable, output. It seems with a steady voltage. Can someone explain how to do that?

I would also like to know which pins to use on a Mega board to address pul, dir and en.

I am going to try to do this with no acceleration or deceleration, unless I hear it just won't work. The stepper has 0.8 Nm holding torque, and my application is something like 0.1, and I need only low speed, less than 2rps, and for my application the acceleration and deceleration would introduce a lot more work.

If anyone can help, thanks!

1 Like

Can you please post a link to the PDF datasheet ?

Oops, it is called a DM422S. Here's a link to the data sheet:http://www.leadshine.com/UploadFile/Down/DM422m.pdf

testitout:
Robin2 has an excellent post on basic controls of stepper motors that require only pul and dir pulses. I need to run a Nema 17 42CMOB 1.8 degrees/2.5 A with a DMC422S (I have the pdf on this but it will not upload). Beautiful equipment and I'm afraid of hurting it. It seems I will need about 24 volts, I'm hoping to make do with 18 because that's the limit of my power source.

The data sheet says it needs a minimum of 20V - you may need another power supply.

Robin2 describes how to address the pul and dir outputs. I need also to address the en, enable, output. It seems with a steady voltage. Can someone explain how to do that?

Just pull enable to ground. Or put it on a pin and use digitalWrite to control it if you want to be able to disable it.

I would also like to know which pins to use on a Mega board to address pul, dir and en.

Whichever you like. Again, they just need to be used with digitalWrite.

Note that you need to control the current too so you'll need to find out what your motor needs and set the dip switches accordingly.

"Just pull enable to ground": do you mean using a pullup or pulldown resistor?

No. Just connect it to ground.

If you were using more than 5V you would need a resistor as specified in figure two of the doc, but your Mega will only be providing 5V on the opto line, so it isn't needed.

Great then I'll do this thank you!

Regretfully this code does not control the stepper.

A multimeter on the output pins shows constant 5 v on the No. 9 pin, which is ok. But only 2.5 v on the no. 8 pin, which is not enough, the specs say they need minimum of 3.5 v on that pin.

Also, a question: the DM422S has input for BOTH PUL + and PUL -. I am just running these into PUL + and DIR +, I hope that's OK.

Nothing happens when I give the DM422S the 20 V it needs and put in the two wires going to PUL and DIR.

Like WildBill said, the EN pin is not important, in fact the specs say it's default is NC, not connected.

Any help available out there? Thanks so much!

Here's the sketch:

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int stepnumber = 0;
int pulseWidthMicros = 1000; // microseconds
int millisbetweenSteps = 1000; // milliseconds - or try 1000 for slower steps

void setup() {

Serial.begin(9600);
Serial.println("Starting StepperTest");
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(13, OUTPUT);
}

void loop(){
digitalWrite(directionPin, HIGH);

{for(int n = 0; n <3200; n++) {

stepnumber++;
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros); // this line is to delay before pulse
digitalWrite(stepPin, LOW);
delayMicroseconds(pulseWidthMicros); // this line is to delay before pulse

digitalWrite(ledPin, !digitalRead(ledPin));

}}}

Here's the sketch:

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

The issue is that you're using a DM422S. The manual you linked to is for a DM422. Surprisingly, they are rather different. You will need to ground all the signals like pulse-, dir-, ena-. Each input has a separate optoisolator so you need to use both lines for each signal

Hi,

Thanks Bill! UK HeliBob, I will always use AutoFormat in the future.

Bill, the program I wrote does not turn the pulse on and off. I wrote another program just to turn on and off, and it works fine, but it does not have a "for" counter so I cannot use it. Can you see anything obviously wrong with this code?

Thanks!

byte directionPin = 9;
byte stepPin = 8;
int n = 0;
byte ledPin = 13;
int stepnumber = 0;
int pulseWidthMicros = 1000; // microseconds
int millisbetweenSteps = 1000; // milliseconds - or try 1000 for slower steps

void setup() {

Serial.begin(9600);
Serial.println("Starting StepperTest");
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(directionPin, HIGH);

{ for (int n = 0; n < 3200; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros); // this line is to delay before pulse
digitalWrite(stepPin, LOW);
delayMicroseconds(pulseWidthMicros); // this line is to delay before pulse

digitalWrite(ledPin, !digitalRead(ledPin));

}
}
}

UK HeliBob, I will always use AutoFormat in the future.

But still not using code tags I see

Here is your code Auto formatted and in code tags

byte directionPin = 9;
byte stepPin = 8;
int n = 0;
byte ledPin = 13;
int stepnumber = 0;
int pulseWidthMicros = 1000;  // microseconds
int millisbetweenSteps = 1000; // milliseconds - or try 1000 for slower steps

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  digitalWrite(directionPin, HIGH);
  {
    for (int n = 0; n < 3200; n++)
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(pulseWidthMicros); // this line is to delay before pulse
      digitalWrite(stepPin, LOW);
      delayMicroseconds(pulseWidthMicros); // this line is to delay before pulse
      digitalWrite(ledPin, !digitalRead(ledPin));
    }
  }
}

Note how much easier it is to see the code blocks with each { and } is on its own line. Auto format can be configured to do this too

Bob, that's lovely. Where do I configure Autoformat?

testitout:
Bill, the program I wrote does not turn the pulse on and off. I wrote another program just to turn on and off, and it works fine, but it does not have a "for" counter so I cannot use it. Can you see anything obviously wrong with this code?

I don't see anything obviously wrong with your code (apart from the lack of auto format and code tags). How are you verifying that it works?

What does the code that does work look like?

Also, loop loops, so you can dispense with the for loop.

Autoformat is invoked with command-t or control-t in the IDE depending on your O/S.

testitout:
Bob, that's lovely. Where do I configure Autoformat?

In the IDE use File/Preferences and click on the link to preferences.txt and you may or may not see a file named formatter.conf in the folder that opens. If it is there open it in an editor and you will see the current formatter options and a URL to further instructions

If the file does not exist then create it and paste in the following and save it

# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style"
# http://astyle.sourceforge.net/astyle.html
#
# If you wish to change them, don't edit this file.
# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE
# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link

# 2 spaces indentation
indent=spaces=2

# also indent macros
indent-preprocessor

# indent classes, switches (and cases), comments starting at column 1
indent-classes
indent-switches
indent-cases
indent-col1-comments

# put a space around operators
# pad-oper

# put a space after if/for/while
 pad-header

# if you like one-liners, keep them
# keep-one-line-statements

# Move opening brackets onto new line
 --style=allman --style=bsd --style=break -A1

# delete empty lines in functions
 --delete-empty-lines 
 #--delete-empty-lines / -xe

# Insert space padding around operators. 
# --pad-oper / -p
 --pad-oper

That is what I have in my formatter.conf file but obviously feel free to change anything that does not suit you

Wow it powers the motor just great. But it does not go just 3200 counts and then stop.

What beautiful quality components, I love them.

Question, WildBill: I need to control this stepper to run a linear module a certain distance, then stop, then go back. How do I have it go a certain number of revolutions and then stop? I thought the "for" loop would do that, but it must be starting over and over again.

Also: if the module starts getting lost for some reason, I may use a proximity sensor instead. That's just an "if" statement, right? And it requires a pullup resistor? Is there one on the board?

Thanks your response time is measured in milliseconds!

Keep a variable that tells you how many steps to perform (3200?). Make it a global for now. In loop, if it's greater than zero, perform a step and decrement it. When you get to zero, set it back to 3200 and change direction.

Usually with steppers you need to go to a home position at startup. Your proximity sensor will help with that. The Arduino has internal pullup resistors that you enable in pinMode using INPUT_PULLUP.