V2 motor shield project assistance.....

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

V2 motor shield project assistance.....

Post by jakefreese »

Howdy,

Well I am attempting to build a automated brass annealer with my Arduino UNO and the V2 motor shield and stepper motor.

I initially had the code written before I got the V2, and in simplicity it compiled with the standard stepper library. Now with the V2 I can not seem to make it happy.

Thanks in advance ! I am a newbie to this.....

Code: Select all

/*
automated annealer
button 2 for 308
button 3 for 22-250
button 4 for 6XC
button 5 for 260

Jake Freese 
      3/10/14
EDIT  3/21/14

*/

#include <Stepper.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
#include <Adafruit_MotorShield.h>
#include <AccelStepper.h>
#include <Wire.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);

void forwardstep1() {  
  myStepper1->onestep(FORWARD, SINGLE);
}

AccelStepper Astepper1(forwardstep1);
 
// button 2 for 308 caliber
const int buttonPinA1 = A1;
// button 3 for 22-250 caliber
const int buttonPinA2 = A2;
// button 4 for 6XC caliber
const int buttonPinA3 = A3;
// button 5 for 260 caliber
const int buttonPinA4 = A4;





void setup() 
{
   Serial.begin(9600);
    pinMode (buttonPinA1, INPUT);
    pinMode (buttonPinA2, INPUT);
    AFMS.begin();
  // set the speed at 120 rpm:
  Mystepper1.setSpeed(120);
  // initialize the serial port:
 
}
  // 308 settings
void loop() {
    while (digitalRead(buttonPinA1) == HIGH)
  // loop while button pressed
   Serial.println("clockwise");
  // number of steps required to index
  myStepper1.step(400);
  // time in flame 
  delay(400);
  
  //22-250 settings
    while (digitalRead(buttonPinA2) == HIGH)
  // loop while button pressed
   Serial.println("clockwise");
  // number of steps required to index
  myStepper1.step(400);
  // time in flame 
  delay(300);
  
  //6XC settings
    while (digitalRead(buttonPinA3) == HIGH)
  // loop while button pressed
   Serial.println("clockwise");
  // number of steps required to index
  myStepper1.step(400);
  // time in flame 
  delay(325);
  
  //260 settings
    while (digitalRead(buttonPinA4) == HIGH)
  // loop while button pressed
   Serial.println("clockwise");
  // number of steps required to index
  myStepper1.step(400);
  // time in flame 
  delay(375);
  }
annealer21:32: error: invalid conversion from 'void (*)()' to 'uint8_t'
annealer21:32: error: initializing argument 1 of 'AccelStepper::AccelStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)'
annealer21.ino: In function 'void setup()':
annealer21:54: error: 'Mystepper1' was not declared in this scope
annealer21.ino: In function 'void loop()':
annealer21:64: error: request for member 'step' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'
annealer21:73: error: request for member 'step' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'
annealer21:82: error: request for member 'step' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'
annealer21:91: error: request for member 'step' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'



I eventually want to get the LCD to work with this also so when you have the button closed for the machine to run within the parameters it will show the caliber selected, programmed time, and countdown until the next move.

Thanks again in advance!!!

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

Re: V2 motor shield project assistance.....

Post by adafruit_support_bill »

I get different errors when I compile it here. Make sure you have the latest version of all the libraries. You should remove the reference to Stepper.h. It is not used.

You are missing the backwardstep definition for AccelStepper. The constructor requires 2 arguments. Please see the AccelStepper examples in the Adafruit_MotorShield library.

Be consistent with your capitalization. myStepper1 is not the same as Mystepper1.

User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

Re: V2 motor shield project assistance.....

Post by jakefreese »

Thanks Bill,

I have a bunch of it fixed now, but on the stepper speed I am back to having problems there .

Code: Select all

  mystepper1.setSpeed(120);
annealer21.ino: In function 'void setup()':
annealer21:56: error: 'mystepper1' was not declared in this scope
annealer21.ino: In function 'void loop()':
annealer21:66: error: request for member 'step' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'
annealer21:75: error: 'MyStepper1' was not declared in this scope


Thanks!

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

Re: V2 motor shield project assistance.....

Post by adafruit_support_bill »

Be consistent in your capitalization. I see 3 different versions of mystepper1 in the error messages:
annealer21.ino: In function 'void setup()':
annealer21:56: error: 'mystepper1' was not declared in this scope
annealer21.ino: In function 'void loop()':
annealer21:66: error: request for member 'step' in 'myStepper1', which is of non-class type 'Adafruit_StepperMotor*'
annealer21:75: error: 'MyStepper1' was not declared in this scope

User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

Re: V2 motor shield project assistance.....

Post by jakefreese »

THANKS AGAIN BILL!!!

Got it to compile finally!!!

Just need to get the rest of things assembled and go from there now.

Then on to getting the LCD to work!!

User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

Re: V2 motor shield project assistance.....

Post by jakefreese »

Code: Select all

void loop() {
  // 308 settings
    while (digitalRead(buttonPinA1) == HIGH)
  // loop while button pressed
   Serial.println("308");
  // number of steps required to index
  myStepper1->step(400, FORWARD, SINGLE);
  // time in flame 
  delay(400);
OK it compiles!! but now when you power up it makes the 400 steps, stops, then that is it.

How do I need to approach this to get it to step the 400 steps, wait 4 seconds, and do it again when the button is depressed?

Thanks!
Last edited by adafruit_support_bill on Sat Mar 22, 2014 6:55 am, edited 1 time in total.
Reason: Fixed the [code] tags

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

Re: V2 motor shield project assistance.....

Post by adafruit_support_bill »

Post the complete code.

User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

Re: V2 motor shield project assistance.....

Post by jakefreese »

Code: Select all


/*
automated annealer
button 14 for 308
button 15 for 22-250
button 16 for 6XC
button 17 for 260

Jake Freese 
      3/10/14
EDIT  3/22/14

*/

#include <Adafruit_Sensor.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
#include <Adafruit_MotorShield.h>
#include <AccelStepper.h>
#include <Wire.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);

void forwardstep1() {  
  myStepper1->onestep(FORWARD, SINGLE);
}
void backwardstep1() {  
  myStepper1->onestep(BACKWARD, SINGLE);
}
AccelStepper AStepper1(forwardstep1, backwardstep1);

 
// button 2 for 308 caliber
const int buttonPin14 = 14;
// button 3 for 22-250 caliber
const int buttonPin15 = 15;
// button 4 for 6XC caliber
const int buttonPin16 = 16;
// button 5 for 260 caliber
const int buttonPin17 = 17;

void setup() 
{
   Serial.begin(9600);
    pinMode (14, INPUT);
    pinMode (15, INPUT);
    pinMode (16, INPUT);
    pinMode (17, INPUT);
 
    AFMS.begin();
  // set the speed at 120 rpm:
 myStepper1->setSpeed(120);
}
  
void loop() {
  {// 308 settings
    while (digitalRead(14) == HIGH)
  // loop while button pressed
   Serial.println("308");
  // number of steps required to index
  myStepper1->step(400, FORWARD, SINGLE);
  // time in flame 
  delay(4000);
  }
  {//22-250 settings
    while (digitalRead(15) == HIGH)
  // loop while button pressed
   Serial.println("22-250");
  // number of steps required to index
  myStepper1->step(400, FORWARD, SINGLE);
  // time in flame 
  delay(3000);
  }
  {//6XC settings
    while (digitalRead(16) == HIGH)
  // loop while button pressed
   Serial.println("6XC");
  // number of steps required to index
  myStepper1->step(400, FORWARD, SINGLE);
  // time in flame 
  delay(3250);
  }
  {//260 settings
    while (digitalRead(17) == HIGH)
  // loop while button pressed
   Serial.println("260");
  // number of steps required to index
  myStepper1->step(400, FORWARD, SINGLE);
  // time in flame 
  delay(3750);
  }
  }

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: V2 motor shield project assistance.....

Post by adafruit_support_rick »

How are your buttons wired? They should be wired to connect the pin to ground when pressed. Your pinMode calls should then enable the internal pullups on the pins:

Code: Select all

  pinMode (14, INPUT_PULLUP);
  pinMode (15, INPUT_PULLUP);
  pinMode (16, INPUT_PULLUP);
  pinMode (17, INPUT_PULLUP);
Now, change your code to detect the button press for when the pin is LOW:

Code: Select all

    while (digitalRead(14) == LOW)
      // loop while button pressed
      Serial.println("308");
    // number of steps required to index
    myStepper1->step(400, FORWARD, SINGLE);
    // time in flame 
    delay(4000);

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

Re: V2 motor shield project assistance.....

Post by adafruit_support_bill »

How do you have your buttons wired?
Your 'while' loops only control the print statements that follow them. They will print the text over and over as long as the button is pressed.

Code: Select all

    while (digitalRead(15) == HIGH)
       // loop while button pressed
       Serial.println("22-250");
The lines following the print statements will execute regardless of the button state. I don't think that is what you want.

If you want a button press to print the text and move the motor, you want something more like:

Code: Select all


    if(digitalRead(15) == HIGH)
    {
       Serial.println("22-250");
      // number of steps required to index
      myStepper1->step(400, FORWARD, SINGLE);
      // time in flame 
      delay(3000);
   }
Wiring as Rick recommends is even better. In that case you should be testing for the button LOW.

User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

Re: V2 motor shield project assistance.....

Post by jakefreese »

ok I will give that a shot! THANKS GUYS!!

User avatar
jakefreese
 
Posts: 20
Joined: Sun Jan 12, 2014 10:23 am

Re: V2 motor shield project assistance.....

Post by jakefreese »

ITS ALIVE !!

Thanks guys!

Now to go make some chips on the mill and finish this up and get it annealing some brass.

The LCD section of things was very very easy ! Thanks to the excellent LCD tutorial on it.

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

Return to “Arduino Shields from Adafruit”