Hi Bill,
Same code. When I run it, it will slow down with the turn if the potentiometer but then wont start again and just jitters. I test it out using only the arduino using the 8,9,10,11 as stated in the example code in arduino and works fine. So it seems something is not translating well in the code to the ports on the motor sheild
Motor Shield V2 for Arduino +Stepper+Potentiometer
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
- adafruit_support_bill
- Posts: 88037
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
Code: Select all
if (motorSpeed > 0) {
myMotor->setSpeed(motorSpeed);
myMotor->step(100, FORWARD, SINGLE);
Better to time it one step at a time by yourself:
Code: Select all
void loop()
{
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 100 to 0 milliseconds
int stepInterval = map(sensorReading, 0, 1023, 100, 0);
delay (stepInterval);
myMotor->onestep( FORWARD, DOUBLE);
}
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
That closer. it works well except it wont stop, it only goes down to 1 step at a time
- adafruit_support_bill
- Posts: 88037
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
So add an 'if' statement and don't step if the sensor reading is below some threshold.
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
I actually got it going by putting it back and changing the 100 to 1
to
Seemed to do the trick
Code: Select all
if (motorSpeed > 0) {
myMotor->setSpeed(motorSpeed);
myMotor->step(100, FORWARD, SINGLE);
Code: Select all
if (motorSpeed > 0) {
myMotor->setSpeed(motorSpeed);
myMotor->step(1, FORWARD, SINGLE);
- chevron694
- Posts: 3
- Joined: Wed Feb 11, 2015 3:33 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
I used your code and got it to work. How would I make a button to change the direction? I understand the code BACKWARD will do that. BUT a code that switches the direction and you can still control the speed.
Please be positive and constructive with your questions and comments.