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

Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

Does anyone have a tutorial or code to use the Motor Shield V2 for Arduino with a stepper and the potentiometer controlling the speed? I've looked everywhere :(

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 »

[Moved topic to Arduino Shields]
See this post: http://forums.adafruit.com/viewtopic.ph ... ot#p293258

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 was trying something more like this, but no luck

Code: Select all

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(10);  // 10 rpm   
}

int stepCount = 0;  // number of steps the motor has taken

void setup();

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
        myMotor->setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myMotor->step(stepsPerRevolution/100);
  } 
}

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 »

That is even easier. You just need to specify the direction and stepping mode in your step command. I'd suggest FORWARD and DOUBLE.
https://learn.adafruit.com/adafruit-mot ... -reference

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

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

Well almost there, got it to semi work with the following code, but if I turn it all the way to stop, when I turn it back it just stutters, may be a bad pod or a noisy connection

Code: Select all

#include <Wire.h>
#include <Stepper.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(10);  // 30 rpm   
}

int stepCount = 0;  // number of steps the motor has taken

void setup();

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
        myMotor->setSpeed(motorSpeed);
   myMotor->step(100, FORWARD, SINGLE); 

  } 
}

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 »

What motor and power supply are you using? Does it work with the StepperTest example code?

Code: Select all

int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
You will not be able to achieve 100 RPM using a 200-step motor. But the low end of the pot range should still function.

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

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

Im using a 12vdc 1000ma power adapter and the stepper motor is as follows

NEMA 17 Stepper Motor | 4.5kg/cm | 1.2A | 1.8 Degree *Custom Winding*
Motor Length 40mm
Holding Torque: 4.5kg*cm
Rated Voltage: 7.2v
Step Angle: 1.8 Degrees
Resistance Per Phase 6Ohm
Inductance Per Phase 13mh
Current Per Phase 1.2A
Shaft Diameter: 5mm
4-Wire Red|Blue / Green|Black

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

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

And I should mention the pod is a 10K

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 »

Your motor is rated for 1.2A @ 7.2v. If you try to run it at 12v, it will try to pull 2A which is more than the shield is rated for.
https://learn.adafruit.com/all-about-st ... he-stepper

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

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

So basically best to go with a 7.5v 1200ma power supply? will that work if I put two of the steppers on the motor shield?

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 »

That is 1.2A per phase. Most stepping modes energize both phases simultaneously at some point, so you would need 2.4A (2400mA) per motor.

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

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

So still trying to get this working. I hooked it up to your adafruit stepper and still now working correctly, any idea where the code is going wrong?

Brian

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 »

I hooked it up to your adafruit stepper and still now working correctly, any idea where the code is going wrong?
I'm a bit confused by that. If it is working correctly, what is the problem?

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

Re: Motor Shield V2 for Arduino +Stepper+Potentiometer

Post by brian33433 »

Oops sorry i meant "not working" not now working.

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 »

Can you explain what it is doing wrong? If you have made changes to the code since you last posted it, post what you are using now.

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

Return to “Arduino Shields from Adafruit”