I used the example codes from Arduino and others, being the latest one
#define DIR_PIN 2
#define STEP_PIN 3
void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
}
void loop(){
//rotate a specific number of degrees
rotateDeg(360, 1);
delay(1000);
rotateDeg(-360, .1); //reverse
delay(1000);
//rotate a specific number of microsteps (8 microsteps per step)
//a 200 step stepper would take 1600 micro steps for one full revolution
rotate(1600, .5);
delay(1000);
rotate(-1600, .25); //reverse
delay(1000);
}
void rotate(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);
digitalWrite(DIR_PIN,dir);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}
void rotateDeg(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN,dir);
int steps = abs(deg)*(1/0.225);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}
just to make the motor move, but nothing happens. It's like no energy is going to the motor.
I have no more ideas in what to try more. Any suggestion?
(And yes, I am new in this, so it might be something really really simple)
If you have the motor M42SP-4NK, it has 5.5 ohm windings and a current limit of 400 mA/winding. You need to set the motor current in the EasyDriver properly, or the motor will overload the power supply and motor driver, which shuts everything down.
I tried that one and it's not working either. Actually that was the first set of code I tried.
jremington: That might be an option, precisely because I didn't really understand that :x I just went for the voltage and maximum mA on the charger. And I don't understand what you are saying, sorry.
MarkT: I'm quite sure it is. Followed the diagrams and when it didn't work, I started to switch them in hope that there could be some difference to the diagram.
Edit: I have another motor (Pololu 1207), and I also can't make it work.
I'm wondering if it's something with the easy driver.
picolero:
JimboZA hit the nail on the head. You have motor voltage on the driver but no logic voltage. Two more jumper wires and you should be in business.
Actually no. Check the data sheet - that's a supply you can use for other things.
I've been trying the first and second examples. Stepper motor steps but doesn't stop. Tried increasing "delayMicroseconds(100);" values to 1000 and changing the "if (Distance == 3600)" all the way down 4. No effect on the motor. Motor turns continuously until easy driver power supply is terminated. "L" and "on" light on arduino uno still on after easy drive powers down.
Bpgoss1:
This is my first project with an arduino.
I've tried two ways to get my Arduino uno working with this easy driver and stepper motor:
Did you read all the earlier posts in this Thread about wiring your motor?
Did you try the very simple the code I posted in Reply #8?
Do you have a real sparkfun Easydriver - if not post a link to the datasheet for the driver you do have?
Post a link to the datasheet for your motor.
Post a photo of a drawing showing exactly how you have everything connected - not a photo of your project
digitalWrite(directionPin, HIGH);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros);
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);
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
}
void loop()
{
}
The digitalWrite on ledPin will add delay to the frequency. On my 200 step stepper through a4988 module I must use a longer delay or I get no motor response.
Try removing the led digitalWrite line of code and set pulesWidthMicros to 445 and change delay(millsbetweenSteps) to delayMicroseconds(millsbetweenSteps) and set to 880. For me it moves the motor. Changing the delay between pin HIGH and pin LOW will change the motors efficiency and direction. (No dir pin required.)
This issue may be related to power input. I am using 12v @ 350mh and the digitalWrite moves the motor but the step function doesnt.