Using an Arduino Uno, Adafruit V2 motor shield, potentiometer and stepper. Wish to control motor direction and position for moving and positioning a variable capacitor. Motor should be turned off when in desired position. Can you suggest a completed sketch or one that I can modify for this? Thanks!
The shield should have a demo on file. Check Adafruit. Normally, the stepper motor windings are left energized, if only partially. You’ll also want acceleration and deceleration ramps, otherwise the motor will stall.
Hi,
There is an Arduino example code in the User Manual of the Motor Shield Kit for Arduino v2 that might help you.
You can download the documentations for the Shield here.
Regards,
Trying the Adafruit code with their V2 motor shield and Arduino UNO:
[code] #include <Wire.h>
#include <Adafruit_MotorShield.h>
#include “utility/Adafruit_MS_PWMServoDriver.h”
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(400,2);
int previous;
void setup(){
Serial.begin(9600);
Serial.println(“Stepper test!”);
AFMS.begin(); // create with the default frequency 1.6KHz
myMotor->setSpeed(40); //40 rpm
previous = analogRead(0);
}
void loop()
{
// get sensor value
int val = analogRead(0);
// move number of steps equal to change in sensor value
int steps = val - previous;
if (steps > 0)
{
mymotor->step(steps,FORWARD,DOUBLE);
}
else if (steps<0)
{
mymotor->step(steps,BACKWARD,DOUBLE);
}
//remember previous value of sensor
previous = val;
}[/code]
Getting error message from compiler: “myMotor not declared in this scope” although steps(400) and port(2) have been specified.
Please advise what MY error is.
Hi,
Did you properly install the Motor Shield V2 Library ?
Here is a tutorial that explains how to do it.
Regards,