AF motor shield v2 | class AccelStepper has no member named

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
effra030
 
Posts: 16
Joined: Tue Nov 19, 2013 8:52 am

AF motor shield v2 | class AccelStepper has no member named

Post by effra030 »

Hello,
I'm using the Adafruit Motor Shield V2 for Arduino.
I would like to start and stop my stepper motors when a button is pressed/released. Running the motors has been easy, but I struggle with stopping them. This tutorial (https://learn.adafruit.com/adafruit-mot ... per-motors) mentions "release()" as method to stop motors. But I just get the following error message:
class 'AccelStepper' has no member named 'release'
Any ideas what might be wrong?

Thank you!

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: AF motor shield v2 | class AccelStepper has no member na

Post by Franklin97355 »

Do you have all the libraries installed in "install software"?
Could you post your code and a description or drawing of your connections between it all?
Please use the code button as shown below.
Code Button.jpg
Code Button.jpg (4.49 KiB) Viewed 1404 times

effra030
 
Posts: 16
Joined: Tue Nov 19, 2013 8:52 am

Re: AF motor shield v2 | class AccelStepper has no member na

Post by effra030 »

This is my code.

Code: Select all

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers

Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(100, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(100, 2);

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;        // the number of the LED pin
int buttonState = 0;          // variable for reading the pushbutton status

// wrappers for the first motor!
void forwardstep1() {  
  myStepper1->onestep(FORWARD, DOUBLE);
}
void backwardstep1() {  
  myStepper1->onestep(BACKWARD, DOUBLE);
}


//wrappers for the second motor!
void forwardstep2() {  
myStepper2->onestep(FORWARD, DOUBLE);
}
void backwardstep2() {  
myStepper2->onestep(BACKWARD, DOUBLE);
}

AccelStepper stepper1(forwardstep1,backwardstep1);
AccelStepper stepper2(backwardstep2,forwardstep2);


void setup()
{  
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT);     
  
  AFMSbot.begin(); // Start the shield

  stepper1.setMaxSpeed(50.0);
  stepper1.setAcceleration(100.0);
  stepper1.moveTo(300);

  stepper2.setMaxSpeed(50.0);
  stepper2.setAcceleration(100.0);
  stepper2.moveTo(300);
}

void loop()
{
    buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {     
     digitalWrite(ledPin, HIGH); 
     stepper1.run();
     stepper2.run();
  } 
  
  else {
     digitalWrite(ledPin, LOW); // control LED off
     stepper1.release(); // stop rotation and turn off holding torque.  The code works well when these 2 lines are in comment 
     stepper2.release(); // stop rotation and turn off holding torque.
  }

     
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
	stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
	stepper2.moveTo(-stepper2.currentPosition());
}


User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: AF motor shield v2 | class AccelStepper has no member na

Post by adafruit_support_mike »

The AccelStepper class works as a wrapper around the Adafruit_StepperMotor class. The accel object tells the stepper object what to do, but doesn't control the motor directly.

Try changing these lines:

Code: Select all

  else {
     digitalWrite(ledPin, LOW); // control LED off
     stepper1.release(); // stop rotation and turn off holding torque.  The code works well when these 2 lines are in comment 
     stepper2.release(); // stop rotation and turn off holding torque.
  }
to this:

Code: Select all

  else {
     digitalWrite(ledPin, LOW); // control LED off
     myStepper1.release(); // stop rotation and turn off holding torque.  The code works well when these 2 lines are in comment 
     myStepper2.release(); // stop rotation and turn off holding torque.
  }

effra030
 
Posts: 16
Joined: Tue Nov 19, 2013 8:52 am

Re: AF motor shield v2 | class AccelStepper has no member na

Post by effra030 »

Thank you. It seems though that something is still missing. If I change that bit of code as you suggest, I get the following error message:

"request for member 'release' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'

Any suggestions?

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

Re: AF motor shield v2 | class AccelStepper has no member na

Post by adafruit_support_bill »

Post your complete code as it is now.

effra030
 
Posts: 16
Joined: Tue Nov 19, 2013 8:52 am

Re: AF motor shield v2 | class AccelStepper has no member na

Post by effra030 »

Code: Select all

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers

// Connect two steppers with 200 steps per revolution (1.8 degree)
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(100, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(100, 2);

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
int buttonState = 0;         // variable for reading the pushbutton status

// wrappers for the first motor!
void forwardstep1() {  
  myStepper1->onestep(FORWARD, DOUBLE);
}
void backwardstep1() {  
  myStepper1->onestep(BACKWARD, DOUBLE);
}


//wrappers for the second motor!
void forwardstep2() {  
myStepper2->onestep(FORWARD, DOUBLE);
}
void backwardstep2() {  
myStepper2->onestep(BACKWARD, DOUBLE);

}

AccelStepper stepper1(forwardstep1,backwardstep1);
AccelStepper stepper2(backwardstep2,forwardstep2);


void setup()
{  
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
  
  AFMSbot.begin(); // Start the shield

  stepper1.setMaxSpeed(50.0);
  stepper1.setAcceleration(100.0);
  stepper1.moveTo(300);

  stepper2.setMaxSpeed(50.0);
  stepper2.setAcceleration(100.0);
  stepper2.moveTo(300);

}

void loop()
{
    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // Motors on :     
     digitalWrite(ledPin, HIGH);  // control LED on
     stepper1.run();
     stepper2.run();
     }
  
  else {
     digitalWrite(ledPin, LOW); // control LED off
     myStepper1.release(); // stop rotation and turn off holding torque.
     myStepper2.release(); // stop rotation and turn off holding torque.
     digitalWrite(ledPin, LOW); // control LED off
  }

     
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
	stepper1.moveTo(-stepper1.currentPosition());

    if (stepper2.distanceToGo() == 0)
	stepper2.moveTo(-stepper2.currentPosition());

}

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

Re: AF motor shield v2 | class AccelStepper has no member na

Post by adafruit_support_bill »

myStepper1 and myStepper2 are defined as pointers to Adafruit_StepperMotor.

Code: Select all

Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(100, 1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(100, 2);
So, to call a function on that motor, you need to dereference the pointer. This means using "->" instead of ".".

Code: Select all

     myStepper1->release(); // stop rotation and turn off holding torque.
     myStepper2->release(); // stop rotation and turn off holding torque.

effra030
 
Posts: 16
Joined: Tue Nov 19, 2013 8:52 am

Re: AF motor shield v2 | class AccelStepper has no member na

Post by effra030 »

Fantastic!
Now it's fine. Thank you.

hideyourcables
 
Posts: 3
Joined: Fri Nov 25, 2016 6:36 am

Re: AF motor shield v2 | class AccelStepper has no member na

Post by hideyourcables »

An old post I know, but it's the closest thing I've found to my problem so far.

When I change my code within void loop() from:

Code: Select all

stepper.release();
to

Code: Select all

stepper->release();
I get the error: base operand of '->' has non-pointer type 'AccelStepper'

What on earth does that mean??!?!? Newbie here, so I have no idea what these "wrappers" and such are doing.

Thanks in advance. P

hideyourcables
 
Posts: 3
Joined: Fri Nov 25, 2016 6:36 am

Re: AF motor shield v2 | class AccelStepper has no member na

Post by hideyourcables »

Found this and it all now works. Brilliant forum!

viewtopic.php?f=31&t=44450

The release function isn't part of the accelstepper library but the AFmotorshield library.

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

Return to “Other Arduino products from Adafruit”