Motor Shield V2 for Arduino +Stepper+Potentiometer

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
brian33433
 
Posts: 36
Joined: Tue Jul 22, 2014 9:49 pm

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

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

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by adafruit_support_bill »

Code: Select all


  if (motorSpeed > 0) {
        myMotor->setSpeed(motorSpeed);
   myMotor->step(100, FORWARD, SINGLE); 

100 steps at nearly 0 RPM will take a very long time.

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); 
}

User avatar
brian33433
 
Posts: 36
Joined: Tue Jul 22, 2014 9:49 pm

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

That closer. it works well except it wont stop, it only goes down to 1 step at a time

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by adafruit_support_bill »

So add an 'if' statement and don't step if the sensor reading is below some threshold.

User avatar
brian33433
 
Posts: 36
Joined: Tue Jul 22, 2014 9:49 pm

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

I actually got it going by putting it back and changing the 100 to 1

Code: Select all

  if (motorSpeed > 0) {
        myMotor->setSpeed(motorSpeed);
   myMotor->step(100, FORWARD, SINGLE); 
to

Code: Select all

  if (motorSpeed > 0) {
        myMotor->setSpeed(motorSpeed);
   myMotor->step(1, FORWARD, SINGLE); 
Seemed to do the trick

User avatar
chevron694
 
Posts: 3
Joined: Wed Feb 11, 2015 3:33 pm

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by chevron694 »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”