Need me for easy stepper driver code for this schematich:
to follow direction of potentiometer left and right side? Please help me, i am find code bt stepper no follow potentiometer, only turn on left isde, or fight.
Need me for easy stepper driver code for this schematich:
to follow direction of potentiometer left and right side? Please help me, i am find code bt stepper no follow potentiometer, only turn on left isde, or fight.
What have you tried? Can you read from the potentiometer? Can you make the stepper move in one direction? In the other direction? If the potentiometer reading changes value by +1, how many steps do you want to take? If the potentiometer reading changes value by -3, how many steps do you want to take?
A im using this code:
#include <Stepper.h>
int current_position = 0;
const char direction_pin = 3;
const char step_pin = 2;
const char pot_pin = 0; //analog input 1
#define Limit01 7
#define Limit02 8
void setup()
{
pinMode(Limit01, INPUT);
pinMode(Limit02, INPUT);
pinMode(direction_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(pot_pin, INPUT);
}
void loop()
{
int readvalue = analogRead(pot_pin);
readvalue = map(readvalue,0,1023,0,1151);
if (readvalue > current_position+20)
{
step_motor_forward();
current_position += 1;
}
else if (readvalue < current_position-20)
{
step_motor_back();
current_position -= 1;
}
}//end of loop
void step_motor_forward()
{
if (digitalRead(Limit02)) {}
else {
digitalWrite(direction_pin, LOW); // control in one side
digitalWrite(step_pin, HIGH);
digitalWrite(step_pin, LOW);
}
}
void step_motor_back()
{
if (digitalRead(Limit01)) {}
else {
digitalWrite(direction_pin, HIGH); // controll in revers side, no working, only working in one side!
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, HIGH);
}
}
This code turn stepper only left side.
void step_motor_forward()
{
if (digitalRead(Limit02)) {}
else {
digitalWrite(direction_pin, LOW); // control in one side
digitalWrite(step_pin, HIGH);
digitalWrite(step_pin, LOW);
}
}
void step_motor_back()
{
if (digitalRead(Limit01)) {}
else {
digitalWrite(direction_pin, HIGH); // controll in revers side, no working, only working in one side!
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, HIGH);
}
}
I need direction change control by potentiometer, example . When the knob of pot. Turn right motor turn right. And when its left motor turn left . All thath with the same speed of motor or same steps. Some thing like that
These links may be helpful.
Stepper Motor Basics
Simple Stepper Code
Are you sure the Easydriver can provide enough current for your motor?
And AFAIK the Easydriver (and BigEasydriver) default to microstepping whereas the Pololu A4988 defaults to single stepping.
...R
djgorandj:
I need direction change control by potentiometer, example . When the knob of pot. Turn right motor turn right. And when its left motor turn left . All thath with the same speed of motor or same steps. Some thing like that
Assuming the potentiometer produces an analogRead() value of 1023 when turned fully then the following will give you direction and speed
int potVal;
potVal = analogRead(potPin); // 0 to 1023
potVal = potVal = potVal - 512; // range is now -512 to +511
if (potVal < 0) {
direction = 1;
}
else {
direction = 0;
}
...R