:: 1/16 stepping code ? ::
October 21, 2012 05:26PM
hi all, ive just been tinkering around with arduino without any proper guide source.

i want to modify this bit of code so that it fires a stream to arduino telling attached steppers to move very slowly. the original code was used for testing arduino outputs. can it be done?

if (micros() %9999999 <4999999) {
digitalWrite(X_DIR_PIN , HIGH);
digitalWrite(Y_DIR_PIN , HIGH);
digitalWrite(Z_DIR_PIN , HIGH);
digitalWrite(E_DIR_PIN , HIGH);
digitalWrite(Q_DIR_PIN , HIGH);
digitalWrite(HEATER_0_PIN, LOW); digitalWrite(FAN_PIN, HIGH); digitalWrite(HEATER_1_PIN, LOW); digitalWrite(LED_PIN, HIGH);

}
else {
digitalWrite(X_DIR_PIN , LOW);
digitalWrite(Y_DIR_PIN , LOW);
digitalWrite(Z_DIR_PIN , LOW);
digitalWrite(E_DIR_PIN , LOW);
digitalWrite(Q_DIR_PIN , LOW);
digitalWrite(HEATER_0_PIN, HIGH); digitalWrite(FAN_PIN, LOW); digitalWrite(HEATER_1_PIN, HIGH); digitalWrite(LED_PIN, LOW);

}

digitalWrite(X_STEP_PIN , LOW);
digitalWrite(Y_STEP_PIN , LOW);
digitalWrite(Z_STEP_PIN , LOW);
digitalWrite(E_STEP_PIN , LOW);
digitalWrite(Q_STEP_PIN , LOW);

delayMicroseconds (160);

digitalWrite(X_STEP_PIN , HIGH);
digitalWrite(Y_STEP_PIN , HIGH);
digitalWrite(Z_STEP_PIN , HIGH);
digitalWrite(E_STEP_PIN , HIGH);
digitalWrite(Q_STEP_PIN , HIGH);

delayMicroseconds (160);
}
Re: :: 1/16 stepping code ? ::
October 22, 2012 12:50PM
looks like i may have found an answer

//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Using the easy stepper with your arduino
//use rotate and/or rotateDeg to controll stepper motor
//speed is any number from .01 -> 1 with 1 being fastest -
//Slower Speed == Stronger movement
/////////////////////////////////////////////////////////////////

#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);
}
}
Sorry, only registered users may post in this forum.

Click here to login