Ok. So, I want to control the speed of a stepper motor with a potentiometer. I've got it working "somewhat" but it's really squirrelly and doesn't replicate the actual speed capabilities of the motor.
Basically all I'm doing is reading the sensorValue of the pot and making that the microsecond delay.
I'm basing some of the programming on Daniel Thompson's sketch for stepper w/ the Easy Driver:
////////////////////////////////////////////////////////
// Stepper Motor skecth for use with the EasyDriver 3.1
////////////////////////////////////////////////////////
// Dan Thompson 2008
//
// Inpired by the code and chat on this thread.
// http://forum.sparkfun.com/viewtopic.php?t=10378&highlight=easydriver
//
// Use this code at your own risk.
// For all the product details visit http://greta.dhs.org/EasyDriver/
// For the full tutorial visit http://danthompsonsblog.blogspot.com/
//
int dirpin = 3;
int steppin = 12;
void setup() {
Serial.begin(9600);
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop()
{
int i;
digitalWrite(dirpin, LOW); // Set the direction.
delay(100);
Serial.println(">>");
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps.
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
digitalWrite(dirpin, HIGH); // Change direction.
delay(100);
Serial.println("<<");
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(200); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}
Dan uses the "delayMicroseconds(200)" command to set the speed at 200 microsteps. I've replaced the "200" w/ "sensorValue" for the pot.
This kind of work, but it doesn't replicate the actual speed capabilities of the motor. What I think I want to do is multiply the sensor value by 0.195. This equates to the ratio between the default maximum value of the arduino's input (1023) and the approximate maximum speed of the motor (200).
So, what I think I want to do is somehow write after the "delayMicroseconds" command the ratio "sensorValue * 0.195" But I'm not sure exactly how to do that. I've tried a few different ways of writing the math, but to no avail.
Any advice on how to do this? Am I barking up the wrong tree?