Confusion with Stepper Motor Controlling

I currently have a stepper motor wired through an Easydriver v4.2 controller board to my arduino Duelmilanove.

I have managed to get the motor wired correctly, and successfully working with the Arduino.

Although, unfortunately due to my limited coding ability I am struggling to get my head around how to get the motor to do exactly what I am after;

I require the motor to move 400 microsteps (1/4 of a rotation) over one minute (so rather slowly). Pause, and then reverse back to the original position.

The code I am using was found on lusarobotics, and has been edited by me, though at the moment, My motor is twiching quickly forwards, and then reverse.

If I change the “400” in my loop for “800” it behaves in a completely different manner, going

forward, backward, forward, forward, forward, foraward, forward, forward, backward, forward, backward, foward, backward, forward, backward, forward, forward, forward, forward, forward, backward, backward, backward, forward, forward, forward, forward, forward, backward,forward etc…

which seems borderline random to me… (all these steps are of the same distance.

The code Im using looks like:

int dirPin = 2;
int stepperPin = 3;

void setup() {
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);
}

void step(boolean dir,int steps){
  digitalWrite(dirPin,dir);
  delay(100);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepperPin, LOW);
    delayMicroseconds(100);
  }
}

void loop(){
  step(true,800);  // this is the first line I am editing
  delay(1000);
  step(false,800); //this is the second line I am editing
  delay(1000);
}

Any pointers would be greatly appreciated, and I understand that there are probably glaringly obvious reasons for this, but I am not a great coder :frowning:

I have managed to get the motor wired correctly, and successfully working with the Arduino.

I'm not sure how you know this as it sounds like the motor is not wired up correctly if it just twitches. Try reversing the connections on one of the coils and see if it starts working.

I'm not sure how you know this as it sounds like the motor is not wired up correctly if it just twitches. Try reversing the connections on one of the coils and see if it starts working.

Well the motor seems to work correctly, twitch may have been the wrong word, it does do full rotations if I change the numbers up to ~1600, which I assume it would not do if it was wired the wrong way round?

EDIT:

I think you may be correct, just referred back to a diagram and it does look like Ive wired the output for Coil A to coil B and vice versa, I will switch them around and cross my fingers!

Thanks!

OK just spotted you are probably trying to step the thing too fast.
Try this:-

for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepperPin, LOW);
    delay(10);
  }

If that works you can reduce the delay between steps.
It is the coil wires I said to swap, that is the way round just one coil is wired.

Ok… So I have rewired the coils to the correct outputs on the EasyDriver board, and replaced the existing for code with you’re code…

We now have what could definitely be called a twitch! ;D

The motor is going backwards and forwards, a miniscule amount for 10 seconds. Pausing, and repeating.

Just a bump really, I've been playing around, but having no success. :(

If it's a 4 wire motor then you have only 2 basic wiring options for rotation - correct and incorrect. If it even twitches then it's correct. More than 4 wires? then there are more options.

Have you got your step and dir wires the correct way round? Applying a step signal to the dir pin can be fun!!!

What V are you powering your motors with?

Hi, there are 6 contacts on the motor, though from what I have read, the outer two pins are not used. (I am getting this information from here, this is the motor I am using).

It's being supplied with 7.5V's...

I've tried wiring up the 4 central pins every which way possible, but not having much luck :(

Hmmm - there's a couple of things in your links that don't quite add up which make me not take anything as read but we'll leave that till later. If we call your pins 1 to 6 can you measure the resistance between:

1 and 2 2 and 3 1 and 3

4 and 5 5 and 6 4 and 6

and get back

You'll need to disconnect from your driver first (make sure you power off first or you'll let the smoke out)

Also - any info on the label about rated Voltage or current would be good

Cheers

With the multimeter set to 200 Ohms:

1 and 2 - No reading 2 and 3 - 7.6 1 and 3 - No Reading

4 and 5 - 7.5 5 and 6 - No Reading 4 and 6 - No Reading

OK so it really is a 4 wire motor. So just wire your easydriver A to 2 and 3 (doesn't matter which way round) and B to 4 and 5 (doesn't matter which way round). Now: check you have the step and dir pins correct. i.e. you're not stepping the dir pin or visa virsa. change both delays to 20 MILLI seconds in your step function.(just for now)

See how you go.

Ok, so I have updated my code…

(20milliseconds = 20,000 microseconds) to this:

int dirPin = 2;
int stepperPin = 3;

void setup() {
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);
}

void step(boolean dir,int steps){
  digitalWrite(dirPin,dir);
  delay(100);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(20000);
    digitalWrite(stepperPin, LOW);
    delay(10);
  }

}

void loop(){
  step(true,800);  // this is the first line I am editing
  delay(1000);
  step(false,800); //this is the second line I am editing
  delay(1000);
}

I uploaded a video, just to clarify what the motor is doing (slightly blurry due to using my phone camera, but demonstrates what the motor is doing adequately).

And as a second example, using the following code:

/********************************************************
**         More info about the project at:             **
**  http://lusorobotica.com/viewtopic.php?t=103&f=106  **
**   by TigPT         at         [url=http://www.LusoRobotica.com]www.LusoRobotica.com[/url]  **
*********************************************************/
int dirPin = 2;
int stepperPin = 3;

void setup() {
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);
}

void step(boolean dir,int steps){
  digitalWrite(dirPin,dir);
  delay(50);
  for(int i=0;i<steps;i++){
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(100);
    digitalWrite(stepperPin, LOW);
    delayMicroseconds(100);
  }
}

void loop(){
  step(true,500);
  delay(5000);
  step(false,500*5);
  delay(500);
}

So, altering the code, does modify the behaviour of the motor. This is what is leading me to believe that it’s my limited knowledge of the coding which is the issue :-[

I think we're getting there. The timings I asked you to put in should have given a step frequency of just 25Hz - pretty slow. You only tweaked one of them rather than both but near enough. The code that works has a step frequency of 5000 Hz. So faster works - slower doesn't - Both "should". I'm thinking you have a resonance problem caused by "over currenting". Have you got the current set pot turned right down? If not, do so please and try both sets of code again.

I'm going to show off my limited knowledge of electronics now...

I'm unsure what "current step pot" means exactly... So I'm not exactly sure what you're asking me to adjust!

If you look at your easydriver board there should be a little trim pot (trim potentiometer) called "CUR ADJ" (current adjust) - turn it to min.

Ah, I thought it could be this, yes it has always been set to minimum.

One last attempt at finding an issue, a photo of the wiring on my easydriver board:

So, the top left, is wired from the "GRND" to the ground on the digital side of the arduino (I have tried switching this to the ground on the breadboard, which does result in... odd behaviour - the motor seems to change speed randomly when wired to here). I have also wired it from the GRND next to the "Step" and "Dir", which results in the same situation as always.

The "STEP" is wired to pin 3, and "Dir" is wired to pin 2. "A" Is wired to pin 2 and 3 on my motor, and "B" is wired to pin 4 and 5. The bottom right "PWR IN" is wired to 7.5V live and ground.

Just for fun I wired my arduino into my cnc router and tried the software we've been using. I got similar results to you. I then realized I hadn't tied in the duino's gnd with my controller's. Once I'd done that all was well. You seem to be suspecting gnd issues also. I also read up on the ED and although it seems it's supposed to derive it's 5V supply from an on board reg - examples I see here and there specifically power it from the duino. So if you want to try this:

connect the duino's 5V to the +5V tab next to your gnd (top left). connect both your top left gnd and the gnd next to "step" to the duino's gnd. your motor supply +ve and "gnd" should be separate and unconnected to anything else.

EDIT: here's one example of what I've described http://danthompsonsblog.blogspot.com/2010/05/easydriver-42-tutorial.html

That’s encouraging at least!

I have had a go at this myself, but unfortunately it still doesn’t want to play ball… I’ve included a decent quality image of my circuit, incase you can spot any errors? Unfortunately I think it’s ok :frowning: