Since the axis are coming together, I wanted to be able to test the capability of the stepper motors without attaching a computer. The first test of the y axis included using Repetier host and an UNO using Teacup, which required hooking up the computer and sending G code to the UNO. Instead I wanted a pot to adjust the speed and direction of the movement. Here is what I came up with:
/*
Stepper Motor Control with Speed Direction outputs
This program will send step pulses out to a step/dir driver board
for testing
It is controlled by a potentiometer that will change the speed as it
changes from 2.5V. Below 2.5V is CCW: 0V is max speed, above 2.5V is CW:
5V is max speed
*/
//The lower the number the faster the speed
// stepMaxSpeed = 15 is 15 uS delay between step pulses
int stepMaxSpeed = 250;
//The higher the number the slower the speed
// stepMinSpeed = 100 is 100 uS delay between step pulses
int stepMinSpeed = 1000;
//Set pins for output to step/dir driver board
int stepPin = 2; //13 can be used for the LED
int stepDirection = 3;
int analogMotorControlPin = A0;
//Analog value Read
int MotorControlValue = 0;
void setup() {
// put your setup code here, to run once:
pinMode(stepPin, OUTPUT);
pinMode(stepDirection, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int stepDelay = 0;
MotorControlValue = analogRead(analogMotorControlPin);
//Set direction and speed using the analog input
// This has a dead band between 500-524. Here the motor will not move
if (MotorControlValue > 524) {
digitalWrite(stepDirection, 1);
stepDelay = map(MotorControlValue, 524, 1023, stepMinSpeed, stepMaxSpeed);
}else if (MotorControlValue < 500) {
digitalWrite(stepDirection, 0);
stepDelay = map(MotorControlValue, 0, 500, stepMaxSpeed, stepMinSpeed);
}else {
//if analog input is in deadband, don't allow for pulses to be sent out
stepDelay = 0;
}
if (stepDelay != 0) {
delayMicroseconds(stepDelay);
digitalWrite(stepPin,1); //step driver board
}
//Delay microseconds for the driver board to recognize change
// may need to be altered for the driver boarxd selected.
delayMicroseconds(5);
digitalWrite(stepPin,0);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.