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
Motor Shield V2 for Arduino +Stepper+Potentiometer
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 :(
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
[Moved topic to Arduino Shields]
See this post: http://forums.adafruit.com/viewtopic.ph ... ot#p293258
See this post: http://forums.adafruit.com/viewtopic.ph ... ot#p293258
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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);
}
}
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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
https://learn.adafruit.com/adafruit-mot ... -reference
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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);
}
}
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
What motor and power supply are you using? Does it work with the StepperTest example code?
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.
Code: Select all
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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
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
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
And I should mention the pod is a 10K
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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
https://learn.adafruit.com/all-about-st ... he-stepper
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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?
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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.
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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
Brian
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
I'm a bit confused by that. If it is working correctly, what is the problem?I hooked it up to your adafruit stepper and still now working correctly, any idea where the code is going wrong?
- brian33433
- Posts: 36
- Joined: Tue Jul 22, 2014 9:49 pm
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
Oops sorry i meant "not working" not now working.
- adafruit_support_bill
- Posts: 88155
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 for Arduino +Stepper+Potentiometer
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.
Please be positive and constructive with your questions and comments.