#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 200
#define directionPin 22
#define stepPin 24
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
// the previous reading from the analog input
int previous = 0;
void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}
void loop()
{
// get the sensor value
int val = analogRead(0);
// move a number of steps equal to the change in the
// sensor reading
stepper.step(val - previous);
// remember the previous value of the sensor
previous = val;
}
there it is I told you I am simple the error code it gives me is stepper was not declared in this scope motorknob.cpp: in function void loop
etc. it gets very angry at me
In order to tell the software what pins to use. Change the numbers to match the pins your hardware is using.
Without this line the software doesn't know what the word 'stepper' means and so it tells you it doesn't know with the error message "not declared in scope" which means "WTF no on told be about this word stepper, I don't know what to do with it.
ok now we're getting somewhere i have a pololu a4988 with the direction pin and step pin when i assigned those 2 pins numbers and gave it a go the motor wont move. i have everything set up right because it works with the code that goes forward then backward
No it won't. This is because that code uses the stepping motor library and this is designed to produce the on / off pattern for powering the coils.
The code is totally unsuitable for the hardware you have.
Try this code, I have just written it for you so I haven't tested it but it compiles:-
// change this to the number of steps on your motor
#define dirPin 10
#define stepPin 11
// the previous reading from the analog input
int previous = 0;
int val =0;
int dir = 0; // direction of movement
int steps = 0; // number of steps to take
void setup()
{
pinMode(stepPin, OUTPUT);
digitalWrite(stepPin, LOW);
pinMode(dirPin, OUTPUT);
}
void loop()
{
// get the sensor value
val = analogRead(0);
// move a number of steps equal to the change in the
// sensor reading
steps = (val - previous);
if(steps > 0){
dir = 0;
}
else {
dir = 1;
steps = -steps;
}
digitalWrite(dirPin, dir); // set up the direction
for(int i = 0; i< steps; i++){
digitalWrite(stepPin, HIGH); // pulse the step pin
digitalWrite(stepPin, LOW);
}
// remember the previous value of the sensor
previous = val;
}
Be sure to change the first two lines to match what you have.
In order to tell the software what pins to use. Change the numbers to match the pins your hardware is using.
Without this line the software doesn't know what the word 'stepper' means and so it tells you it doesn't know with the error message "not declared in scope" which means "WTF no on told be about this word stepper, I don't know what to do with it.
first thank you grumpy mike. good karma for you when i try the code and move the pot the motor does nothing. sorry it took so long to get back i have an 11 month old and work. my projects always get put on the back burner
Is the pot output connected to A0, maybe through a 1K resistor? And in that connect, a 10k or so resistor to ground as well? If you don't have that resistor to ground then you will always get saturated reads and wonder what's wrong.
Then analog read A0 and you have your turn pot sensed.
the delay got mad and said it expected a ; . maybe its the pot i have one wire to a ground middle wire to the a0 pin one wire to a 5 volt spot the green light lights up when i move it one way
zeroproskills:
the delay got mad and said it expected a ; . maybe its the pot i have one wire to a ground middle wire to the a0 pin one wire to a 5 volt spot the green light lights up when i move it one way
You want to attach to the middle wire, another wire with 10+k resistor to ground.
You want some resistors in there to limit current flow. One pin can handle 40 mA but you don't want to push the pins like that, 20 mA per pin is a nice 'limit' but you don't need that much current.
I have input pins being fed 0 - 5V through 2.2k resistors, 2.27 mA, works fine. Those same input pins connect to ground through 22k resistors, that's where the 2.27 mA goes. Maybe I should try 4.7k instead of 2.2k to use 1.06 mA.
ok i am back on this project life and frustration got in the way. now i am ready to try again. i also need to start from the point of what resistors do i need to install for the pot to work. i would like to have the pot control a stepper motor to move 200 steps forward and 200 backward. if pot stops so does the motor. thanks for helping everyone
OK so, as it has been a time and there has been several software versions used, can you post a schematic of what you have wired up along with the code you are trying to use.
been busy thanks for patients in advance i am using the simple program from before a polou a4988 driver and a 3 prong pot from radio shack i just bought a volt meter my power supply has an output of 24v and 6.5a i have the driver in the easiest setting with 1a and 2a connected and 1b and 2b connected no microstepping.i just need the motor to follow what the pot does 200 steps one way 200 steps the other
OK so, as it has been a time and there has been several software versions used, can you post a schematic of what you have wired up along with the code you are trying to use.