So far the unit is working well for me. The forum postings for speed improvements etc have been very helpful thanks.
I would now like to save some energy and 'Release' the stepper motor.
Could you give a code fragment to release 'mystepper1'. So far I've not been able to deduce how the library call function works and have not found an example in the code provided.. Thanks again.
Motorshield V2 Stepper Motor Control
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88149
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motorshield V2 Stepper Motor Control
Have you tried this?
http://learn.adafruit.com/adafruit-moto ... -reference
Code: Select all
mystepper1.release();
-
- Posts: 4
- Joined: Sun Aug 04, 2013 9:49 pm
Re: Motorshield V2 Stepper Motor Control
A new program...
stepper2.moveTo(mypos); / this line works OK
/ I add this code fragment
stepper2.release();
/* I get this error code
error: 'class AccelStepper' has no member named 'release'
The word release is in the brown tint indicating it is a valid reserved word just not in the stepper motor context */
stepper2.moveTo(mypos); / this line works OK
/ I add this code fragment
stepper2.release();
/* I get this error code
error: 'class AccelStepper' has no member named 'release'
The word release is in the brown tint indicating it is a valid reserved word just not in the stepper motor context */
- adafruit_support_bill
- Posts: 88149
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motorshield V2 Stepper Motor Control
It would help if you posted your entire code. Sounds like you are using the AccelStepper library. Release() is part of the Adafruit Motorshield library.
-
- Posts: 4
- Joined: Sun Aug 04, 2013 9:49 pm
Re: Motorshield V2 Stepper Motor Control
Yes I am trying to use the accelstepper library.
Your' requested the code... Thanks in advance for your help
Your' requested the code... Thanks in advance for your help
Code: Select all
// Shows how to run a Stepper with varying speeds
//
// Requires the Adafruit_Motorshield v2 library
// https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
// And AccelStepper with AFMotor support
// https://github.com/adafruit/AccelStepper
// This tutorial is for Adafruit Motorshield v2 only!
// Will not work with v1 shields
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#include <Adafruit_RGBLCDShield.h>
#include <Servo.h>
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers
// Connect stepper with 200 steps per revolution (1.8 degree)
// to the shield
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);
// Connect one stepper with 200 steps per revolution (1.8 degree)
// to the bottom shield
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
int buttons; //declares variable to hold the button number
int myspeed=300;
int mypos=100;
// wrappers for the motor!
void forwardstep2() {
myStepper2->onestep(FORWARD, SINGLE);
}
void backwardstep2() {
myStepper2->onestep(BACKWARD, SINGLE);
}
unsigned long microtime;
// wrap the steppers in an AccelStepper object
AccelStepper stepper2(forwardstep2, backwardstep2);
Servo servo1;
void setup()
{
lcd.begin(16, 2);
AFMStop.begin(); // Start the top shield
lcd.print("motor interface!");
stepper2.setMaxSpeed(myspeed);
stepper2.setAcceleration(100.0);
stepper2.moveTo(mypos);
servo1.attach(9);
}
void loop()
{
// Change direction at the limits
//if (stepper2.distanceToGo() == 0) stepper2.moveTo(-stepper2.currentPosition());
microtime= micros();
// will the run statement automatically reenable the outputs?
stepper2.run();
microtime= micros()-microtime;
buttons = lcd.readButtons();
if (buttons) { //start of button reading
lcd.clear();
lcd.setCursor(0,0);
switch(buttons) {
case 8:
lcd.print("UP ");
myspeed=myspeed+10;
stepper2.setMaxSpeed(myspeed);
lcd.print (myspeed);
break;
case 4:
lcd.print("DOWN ");
myspeed=myspeed-10;
stepper2.setMaxSpeed(myspeed);
lcd.print (myspeed);
break;
case 16:
lcd.print("LEFT ");
mypos=mypos-200;
stepper2.moveTo(mypos);
lcd.print (mypos);
break;
case 2:
lcd.print("RIGHT ");
mypos=mypos+200 ;
stepper2.moveTo(mypos);
lcd.print (mypos);
break;
case 1:
lcd.print("SELECT servo ");
stepper2.disableOutputs();
// stepper2.release(); // compile error 'class AccelStepper' has no member named release... commented out
delay(5000); //wait for 5 seconds to test for release of stepper output
break;
default:
break;
} // end of switch case
do { // wait for release of the button
buttons = lcd.readButtons();
}
while (buttons > 0);
// end do
} // end of buttons if
}
]
Last edited by adafruit_support_bill on Fri Oct 11, 2013 6:10 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code - click 'code' and paste your code between the tags.
Reason: Please use the 'code' button when submitting code - click 'code' and paste your code between the tags.
- adafruit_support_bill
- Posts: 88149
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motorshield V2 Stepper Motor Control
Your Adafruit_StepperMotor is created here as "myStepper2:
Then here it is 'wrapped' with some AccelStepper code and to create "stepper2". Note that the AccelStepper functions call the original myStepper2 to do their work.
You also can make calls to the underlying Adafruit library functions using "myStepper2" instead of "stepper2. So to "release" the motor, just call:
Code: Select all
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2);
Code: Select all
// wrappers for the motor!
void forwardstep2() {
myStepper2->onestep(FORWARD, SINGLE);
}
void backwardstep2() {
myStepper2->onestep(BACKWARD, SINGLE);
}
unsigned long microtime;
// wrap the steppers in an AccelStepper object
AccelStepper stepper2(forwardstep2, backwardstep2);
Code: Select all
myStepper2.release();
-
- Posts: 4
- Joined: Sun Aug 04, 2013 9:49 pm
Re: Motorshield V2 Stepper Motor Control
With your teaching how the wrappers worked I took a step backward to study the V1 motor shield codes..
I couldn't get myStepper2.release(); to compile correctly.
[myStepper2->release();]
compiled and worked just fine with the motor assembly.
Thanks.
I couldn't get myStepper2.release(); to compile correctly.
[myStepper2->release();]
compiled and worked just fine with the motor assembly.
Thanks.
- Adlmail
- Posts: 6
- Joined: Wed Aug 26, 2015 5:15 pm
Re: Motorshield V2 Stepper Motor Control
I had the opposite result
myStepper1->release(); compiled and turned off the stepper but
[myStepper1->release();] gave a compile error.
myStepper1->release(); compiled and turned off the stepper but
[myStepper1->release();] gave a compile error.
Please be positive and constructive with your questions and comments.