X25 stepper motor

Hi everybody…
I’m very new in the arduino world and already in trouble :0
I got me couple of X25 motors, and connected them to the output 8,9,10,11…
the motor initialize perfectly generally does what I ask for, but… I’m trying to do a simple thing, once the board is activated, I got the motor to home, then I wish (but as of now is just a wish) to do a sweep to the end of the stroke and back to zero, but I’m not able to do such a thing.
Funny thing is that if the command: Serial.println(jmax); is active, then I got the sweep even if very slow, but if I remove that line, the software ignore everything and behave as jmax is already passed 3000.
Any help would be greatly appreciated.

here is the code that I wrote:

#include “SwitecX25.h”

SwitecX25 motor2(315*3, 8,9,10,11);
int jmax=0;

void setup(void) {
Serial.begin(9600);
motor2.zero();
}

void loop() {
int pos;
if (jmax>=0 && jmax<900) motor2.setPosition(900);
if (jmax>=950 && jmax<2000) motor2.setPosition(0);
if (jmax>3000)
{
pos=random(350,550);
motor2.setPosition(pos);
}

// Serial.println(jmax);
motor2.update();
jmax=jmax++;
}

For completeness is this the motor you mean?

http://guy.carpenter.id.au/gaugette/resources/switec/X25_xxx_01_SP_E-1.pdf (its very low current BTW)

How exactly did you wire it up? Flyback diodes?

Clearly your code cannot work as is as there is no delay between calls to setPosition and thus it will be called perhaps 100,000 to 1,000,000 times a second, far too fast for a mechanical system to respond. Perhaps just a delay (1) will suffice? Though check out the BlinkWithoutDelay sketch for a better approach to timing.

Hi Mark, the motor is exactly the one that you mentioned, and I connected it brutally to the board without diodes... but those should be only for protection am I right?

Thanks for the hint about the timing... I modified the code according the sketch that you gave me, and now it does what I meant very smoothly. as of now after the inizialization I just got random position, but as soon as I have a sensor, I can use this as a gauge (hopefully) :) probably is not of interest but here is the code:

include "SwitecX25.h"

SwitecX25 motor2(315*3, 8,9,10,11); long previousMillis = 0; long interval = 1000; int cw = 0; int ccw = 0;

void setup(void) { Serial.begin(9600); motor2.zero(); }

void loop() { unsigned long currentMillis = millis(); if (currentMillis-previousMillis>interval && cw==0 && ccw==0) { motor2.setPosition(900); cw=cw++; previousMillis = currentMillis; }

if (currentMillis-previousMillis>interval && cw>0 && ccw==0) { motor2.setPosition(0); ccw=ccw++; previousMillis = currentMillis; }

if (currentMillis-previousMillis>interval/2 && cw>0 && ccw>0) { int pos; pos=random(100,800); motor2.setPosition(pos); previousMillis = currentMillis; } motor2.update(); }

katanensis: Hi Mark, the motor is exactly the one that you mentioned, and I connected it brutally to the board without diodes... but those should be only for protection am I right?

Vital, since this isn't a rare event you protect against, but every time you switch an output pin... I would choose schottky diodes so they kick in before the puny little on-chip ones (which aren't designed for this task, although they certainly will be helping ATM)

I've been driving a couple of these motors directly from Arduino logic pins (without diodes) non-stop for a couple of years with no damage to the hardware, so I would argue (a posteriori) that the Arduino is capable of handling the flyback current. The motor data sheet says rather vaguely that these are designed to be driven directly from TTL logic pins, but certainly there is an induced reverse current when the winding field collapses, so diodes are the safe option.

If you do want to use diodes, you can see an example of how to do so on Adam Fabio's board here: https://www.tindie.com/products/TheRengineer/analog-gauge-stepper-breakout-board/

FWIW I am the author of the SwitecX25 library. I'm glad to see that you figured out that setPosition() is asynchronous. You need to call setPosition() once to set the destination position, then call update() repeatedly and as fast as possible to move the motor into that position. The library handles acceleration and deceleration of the motor for a smooth ride, and you ideally would not have any blocking calls like delay() or Serial.print() inside the loop that calls update(), at least not while the motor is moving.

guyc: I've been driving a couple of these motors directly from Arduino logic pins (without diodes) non-stop for a couple of years with no damage to the hardware, so I would argue (a posteriori) that the Arduino is capable of handling the flyback current.

I disagree, the on-chip protection diodes are not rated for 20mA. The fact you have one working for a while doesn't prove that damage isn't happening, that takes a concerted program of testing with each batch of chips out of the foundary, either that or you stick to the limits in the datasheet (which are tested against each batch).

The only thing the datasheet says is that pins must not go as low as -0.5V or as high as Vcc+0.5V - unless you've measured that you are comfortably inside these abs max parameters all bets are off. The protection diodes on most chips are good for 0.5 to 2mA or so when the data is provided, I wouldn't expect the ATmega to be any different. After all the diodes are solely to protect against static discharge in the standard ESD model.

Adding schottky flyback diodes will guarantee staying inside the specs. And yes you'd need 8 of them, so I can see why its a nuisance.

Incidentally the datasheet recommends using the specific driver chip for these motors: http://guy.carpenter.id.au/gaugette/resources/switec/X12_017.pdf

It can drive 4 motors from step/direction interface and does 1/12 microstepping.