Connectiong Arduino DUE to pul/dir driver.

Hello guys.

I have a scheme of the stepper motor driver, but have no idea how to connect it to arduino due.

PLS stands for pulse (aka step)
DIR stands for direction

I see that 3 additional transistors are needed to use arduino with this drive.. Am I right? Could someone explain this a little for me please.

There is time diagram on the right. Tells me nothing as well...

P.S. the image is from the aliexpress store. Sorry for quality.

The diagram seems to suggest that all the + pins (pls+, dir+ etc) are connected to VCC and the - pins are connected to whatever I/O pins you wish to use for step, direction and enable. I presume, then, that a pulse is generated by bringing the I/O pin LOW.

The transistors in the diagram are inside the Atmega chip - they are not something you need to worry about. I suspect you can completely ignore the timing diagram. It seems to say that the minimum length for a step pulse is 1 microsec. If you ensure that all your transitions are longer than 10µsecs you should not run foul of the timing requirements.

...R

Your driver is a "common anode" type driver.

Means, that the controller (in your case you will be using the Arduino for that) will switch ON/OFF the optocouplers of your driver to control it, thus

  • ENABLING your driver, so that can listen to the Arduino's commands (STEP/DIR)
  • controlling the direction of the motor turn (left/right) by switching the DIR input HIGH or LOW
  • sending STEP pulses to make the motor move at a certain speed, depending on the frequency of the pulses being sent

Before you continue reading -> 2 warnings:
a) get acquainted to setting the stepper motor's max. current (have a look at the data sheet of your motor and the instructions of your driver, how to limit the motor's coil current) and do this before starting any testing.
b) NEVER connect/disconnect your motor when power is ON (regardless if it is turning or not).
If you don't obey these two rules you might fry your motor or kill your driver.

Let's go on with something that is not that frightening :slight_smile:

Wiring:

  1. you don't need addt'l transistors as I assume that the Arduino is able to switch the optocouplers ON/OFF without any further assistance by transistors - but pls check, what the datasheet says, how much current is needed by your driver to switch an optocoupler on -if that value exceeds 20mA, then come back and we have to talk about transistors indeed

  2. connect the NEGATIVE inputs "PUL", "DIR" and "ERC" with any digital I/Os of your Arduino. (e.g.:
    PUL- <-> Due "8"
    DIR- <-> Due "9"
    ERC- <-> Due "10"

  3. connect Arduino's Vcc (5V-Pin) with "PLS+" AND "DIR+" AND "ENA+"

  4. DON'T CONNECT the GNDs !!!!!!! of the Arduino and driver !!!!!!

Code:
You can use / test with any code which is able to drive a bipolar stepper through a dedicated driver.

Make sure that the code only works with STEP and DIR commands. Here you will find a simple example to get first moves. You can use different pins, but I adjusted my example of the wiring with @Robin2's simple stepper program.

But, before the motor moves, it needs to be enabled by setting the "ERC" pin (=ENA-) of the driver to "LOW".

There are 2 alternatives for that:
a) you declare pinEnable as pin#10 in the declaration section, set it up as OUTPUT in setup() and HIGH as initial value first; after that set it LOW whenever you want that the motor moves when it receives STEP pulses.
b) To ease your test you could connect the ERC instead to pin 10 of the Due (in my example above) to GND.
This will permanently enable the driver and the driver will continuously drive the max. current (which you hopefully have limited at the VERY FIRST STEP of your experiment to the max. current of your stepper motor !!!) through the motor - regardless if it stands still (no pulses coming in to STEP-) or if it is turning.

The timing diagram on the right of your image shows the interdependencies of the signals. It says that there are some (internal) delays which happen when you change either ENABLE status or DIR status.

If you immediately send step pulses after you have sent either ENABLE or new DIR command, you will lose the first steps until the commands take effect.

In the operational environment this will mean that you will have to wait some us until the driver has realized/processed the change - but we are talking about us-range - might be that due to the slowness of the Arduino Due you might not have to consider this in your code. If it becomes critical, just insert 1ms delay after each change of either direction or enabling. Nobody will notice it and your stepper won't miss any steps.

Good luck.

EDIT:
@Robin2 was quicker (I had to finish the novel first ..)
It would be nice if you could provide an exact link to your driver or it's data sheet so we could look it up for either confirming the "external transistor non-issue" or not.

Be careful - some of the Due pins cannot drive standard opto-couplers directly as they have very
small current ratings (some as little as 3mA I think). You should probably use some sort of buffer
to boost the output drive, or at least check the pins ratings.

In addition to what @MarkT said, the Due is a 3.3V board!
See: https://www.arduino.cc/en/Main/ArduinoBoardDue

All inputs have to be 3.3V -> 5V input will fry that baby!

On top some I/O pins can deliver a max. output of 3mA, some others up to 15mA - so you are not free what pin to use and my example might fail using those pins. Mightbe the 15mA are not sufficient to switch the optocouplers on the driver board - so it is important to get to know the specification/data sheet of that driver.

If you are planning to extend your initial project with devices which come with 5V outputs to be connected to the Due's inputs, you will need a 5V/3.3V converter in between for each I/O to be used.

If I were in your shoes I would go for a standard 5V Arduino (UNO, Mega etc.) and go on with that.
The Due will cause a lot of add'tl efforts along your project road, although it will be technically do-able without any doubts.

rpt007:
On top some I/O pins can deliver a max. output of 3mA, some others up to 15mA

Wow... I will resist the temptation to comment on DUEs in the future.

...R

I will resist the temptation to comment on DUEs in the future

Please don't do that; I always learn something when reading your comments :slight_smile:

Just give the user(s) a warning about the specialities of the Due, like so:

Each of the 54 digital pins on the Due can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 3.3 volts. Each pin can provide (source) a current of 3 mA or 15 mA, depending on the pin, or receive (sink) a current of 6 mA or 9 mA, depending on the pin. They also have an internal pull-up resistor (disconnected by default) of 100 KOhm.

Quoted from here:
https://www.arduino.cc/en/Main/ArduinoBoardDue

rpt007, thanks for such a detailed response!

Considering 3.3v issue I'm going to use Mega isntead of Due.

  1. DON'T CONNECT the GNDs !!!!!!! of the Arduino and driver !!!!!!

can you explain this a bit, just wondering

Code

I'm going to receive my motor/driver set soon, so I'll update this thread, if someone is ineterested =)

It would be nice if you could provide an exact link to your driver or it's data sheet so we could look it up for either confirming the "external transistor non-issue" or not.

As soon as I'll receive my set, I'll post datasheet here.

Thanks everybody for help!

can you explain this a bit, just wondering

GND will be "automatically" delivered by the Arduino switching the "GND-Pin" of the optocoupler to GND.
To isolate Arduino and driver completely it is needed to just power the optocouplers. In your case with common anode it is sufficient to switch the optocouplers by digital LOW on the adequate pins of the driver.

Connecting GNDs will really bypass the optical isolation as it will be a physical connection to the driver board "behind" the optocouplers, whereas just powering the optocouplers still isolates the two devices and only connects "optically".

I know it might look a bit strange while in most cases you will find a common GND to get a refernce point for two or more devices to be connected. In your case common GND is replaced by common Anode (=Vcc) and by just "reverse thinking" it's just the same as "common GND" thinking - which is more common for most of us.

If you don't need the isolation -> looking at the first image which you provided, it might not hurt and it could be that you need a common GND later if you decide to use the driver's encoder (whatever that is -> this is why we need to get a precise data sheet of your driver). But for the moment you don't need a common GND.