0

adafruit-vs1053
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: adafruit-vs1053

by adafruit_support_bill on Wed Apr 18, 2018 6:28 am

What does the black horizontal line represent? It that connected somehow to the carriage?

s I am thinking of mounting the bug directly to the switch I think a lot of impact will be absorbed by the switch itself.

I don't know how big your bug mallet is. But I'd be concerned about ripping the lever out of the switch. I'd attach the bug to the plate via a flexible 'hinge' (like a piece of PET cut from the wall of a soft-drink bottle) and put the switch inside the fold of the hinge.

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Wed Apr 18, 2018 7:00 am

Sorry Bill, the black line represents the level of the board. The servo sits on the carriage. I am sure my testing with the mallet will certainly work out all the 'bugs' in the system:) I was actually thinking about using one of the larger arcade buttons (25mm) but I could not think of how to stop the bug moving around on top of the switch/button as the switch button can move 360 degrees.
Is this what you mean by Add additional initialization here? If so, Does this,
Code: Select all | TOGGLE FULL SIZE
#include <AccelStepper.h>

AccelStepper BugStepper1(28,29,30,31);
AccelStepper BugStepper2(32,33,34,35);
AccelStepper BugStepper3(36,37,38,39);
AccelStepper BugStepper4(40,41,42,43);
AccelStepper BugStepper5(44,45,46,47);

mean the same as this?
Code: Select all | TOGGLE FULL SIZE
AccelStepper bugStepper1(AccelStepper::FULL4WIRE, 28, 29, 30, 31);
AccelStepper bugStepper2(AccelStepper::FULL4WIRE, 32, 33, 34, 35);
AccelStepper bugStepper3(AccelStepper::FULL4WIRE, 36, 37, 38, 39);
AccelStepper bugStepper4(AccelStepper::FULL4WIRE, 40, 41, 42, 43);
AccelStepper bugStepper5(AccelStepper::FULL4WIRE, 44,45,46,47);

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by adafruit_support_bill on Wed Apr 18, 2018 9:39 am

Is this what you mean by Add additional initialization here?

No. Each instance of BugStepper corresponds to a single instance of AccelStepper. The AccelStepper initialization is taken care of when you instantiate the BugStepper:

Code: Select all | TOGGLE FULL SIZE
    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4)
    :AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)        // < ----- This is a call to the AccelStepper constructor
    {


Additional initialization would be for things like the servo channel and limit-switch pins.

Those will require some state variables as well as some additional constructor parameters:

Code: Select all | TOGGLE FULL SIZE
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here
   
   int ServoChannel;   // channel for the bug servo
   int LimitSwitchPin;   // pin for the limit switch
   
    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, servo, limit)
    :AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
        // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
      pinMode(LimitSwitchPin, INPUT_PULLUP); 
    }
   
    // Add additional functions here
}


Then - instead of declaring 5 instances of AccelStepper, you can declare 5 instances of your new class BugStepper:

Code: Select all | TOGGLE FULL SIZE
BugStepper BugStepper1(28,29,30,31,0,2);  // Bug Stepper using servo on channel 0 and a limit switch on pin 2
BugStepper BugStepper2(32,33,34,35,1,3);
BugStepper BugStepper3(36,37,38,39,2,4);
BugStepper BugStepper4(40,41,42,43,3,5);
BugStepper BugStepper5(44,45,46,47,4,6);

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Thu Apr 19, 2018 8:10 am

Would the
5 instances of your new class BugStepper:
be placed before the set up or in the set up. Here is the code so far (however when I compile I get the error exit status 1
'servo' has not been declared)
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_PWMServoDriver.h>
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <AccelStepper.h>
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin[] = {22, 23, 24, 25, 26};//22 on rail of  bugStepperMotor 1, 23 on rail of bugStepperMotor2, 24 on rail of bugStepperMotor3,
    //25 on rail of bugStepperMotor4, 26 on rail of bugStepperMotor5
    int LimitSwitchPinCount = 6;

    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, servo, limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
      for (int thisPin = 0; thisPin < LimitSwitchPinCount; thisPin++) {
       pinMode(LimitSwitchPin, INPUT_PULLUP);
    }

    // Add additional functions here
}
{
  // Add additional state variables here

  // BugStepper constructor - calls the base class AccelStepper constructor
  BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4)
    : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)       // < ----- This is a call to the AccelStepper constructor
  {
    {
      // Add additional initialization here
    }

    // Add additional functions here
  }




  void setup() {



    while (!Serial);
    Serial.begin(9600);

  }

  void loop() {
    // put your main code here, to run repeatedly:

  }

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by adafruit_support_bill on Thu Apr 19, 2018 8:26 am

Would the 5 instances of your new class BugStepper be placed before the set up or in the set up.

Before the setup.

when I compile I get the error exit status 1 'servo' has not been declared

Sorry, I forgot to add the type specifiers to the constructor parameter list:
Code: Select all | TOGGLE FULL SIZE
    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8 servo, uint8 limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
 

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Thu Apr 19, 2018 8:42 am

Should this
uint8 servo, uint8 limit
be uint8_t servo and uint8_t limit
Also I added this
Code: Select all | TOGGLE FULL SIZE
for (int thisPin = 0; thisPin < LimitSwitchPinCount; thisPin++) {
       pinMode(LimitSwitchPin, INPUT_PULLUP);
but is this needed as I already saw that you have indicated the limit pins are on Pins 2,3,4,5,6 ?
Code: Select all | TOGGLE FULL SIZE
BugStepper BugStepper1(28,29,30,31,0,2);  // Bug Stepper using servo on channel 0 and a limit switch on pin 2
I was using pins 22 -26 as I/O pins for the limit switch sensors.

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by adafruit_support_bill on Thu Apr 19, 2018 9:21 am

Should this
uint8 servo, uint8 limit
be uint8_t servo and uint8_t limit

Yes, it should. Sorry, I should have brewed the coffee a bit stronger this morning.

Also I added this
CODE: SELECT ALL | TOGGLE FULL SIZE
for (int thisPin = 0; thisPin < LimitSwitchPinCount; thisPin++) {
pinMode(LimitSwitchPin, INPUT_PULLUP);
but is this needed as I already saw that you have indicated the limit pins are on Pins 1, 2,3,4,5,?

Correct. It is not needed, since we specify the limit switch and set the pinMode for it in the BugStepper constructor.

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Thu Apr 19, 2018 9:41 am

On my wiring diagram do I now relocate the limit sensor pins from pins 22 - 26 to 1 to 5?

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by roadshark on Thu Apr 19, 2018 9:52 am

When I compile this code
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_PWMServoDriver.h>
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <AccelStepper.h>
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin;
   
}
    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
     
       pinMode(LimitSwitchPin, INPUT_PULLUP);
   
    }
{
    // Add additional functions here

}
   

BugStepper BugStepper1(28,29,30,31,0,2);  // Bug Stepper using servo on channel 0 and a limit switch on pin 2
BugStepper BugStepper2(32,33,34,35,1,3);
BugStepper BugStepper3(36,37,38,39,2,4);
BugStepper BugStepper4(40,41,42,43,3,5);
BugStepper BugStepper5(44,45,46,47,4,6);


  void setup() {



    while (!Serial);
    Serial.begin(9600);

  }

  void loop() {
    // put your main code here, to run repeatedly:

  }

I get this error: Arduino: 1.6.13 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

bug_wak_Slave_1:5: error: new types may not be defined in a return type

class BugStepper: public AccelStepper

^

C:\Users\01725568\Documents\Arduino\bug_wak_Slave_1\bug_wak_Slave_1.ino:5:1: note: (perhaps a semicolon is missing after the definition of 'BugStepper')

C:\Users\01725568\Documents\Arduino\bug_wak_Slave_1\bug_wak_Slave_1.ino:14:100: warning: ISO C++ forbids declaration of 'BugStepper' with no type [-fpermissive]

BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)

^

C:\Users\01725568\Documents\Arduino\bug_wak_Slave_1\bug_wak_Slave_1.ino: In function 'int BugStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)':

bug_wak_Slave_1:14: error: ambiguating new declaration of 'int BugStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)'

C:\Users\01725568\Documents\Arduino\bug_wak_Slave_1\bug_wak_Slave_1.ino:14:2: note: old declaration 'BugStepper BugStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)'

BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)

^

bug_wak_Slave_1:15: error: only constructors take member initializers

: AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)

^

bug_wak_Slave_1:19: error: 'ServoChannel' was not declared in this scope

ServoChannel = servo; // remember the servo channel

^

bug_wak_Slave_1:20: error: 'LimitSwitchPin' was not declared in this scope

LimitSwitchPin = limit;// remember the limit switch pin

^

C:\Users\01725568\Documents\Arduino\bug_wak_Slave_1\bug_wak_Slave_1.ino: At global scope:

bug_wak_Slave_1:25: error: expected unqualified-id before '{' token

{

^

bug_wak_Slave_1:31: error: 'BugStepper' does not name a type

BugStepper BugStepper1(28,29,30,31,0,2); // Bug Stepper using servo on channel 0 and a limit switch on pin 2

^

bug_wak_Slave_1:32: error: 'BugStepper' does not name a type

BugStepper BugStepper2(32,33,34,35,1,3);

^

bug_wak_Slave_1:33: error: 'BugStepper' does not name a type

BugStepper BugStepper3(36,37,38,39,2,4);

^

bug_wak_Slave_1:34: error: 'BugStepper' does not name a type

BugStepper BugStepper4(40,41,42,43,3,5);

^

bug_wak_Slave_1:35: error: 'BugStepper' does not name a type

BugStepper BugStepper5(44,45,46,47,4,6);

^

exit status 1
new types may not be defined in a return type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by adafruit_support_bill on Thu Apr 19, 2018 10:00 am

Somehow you have accumulated a couple of redundant brackets in the code that are messing up the scope. The ones indicated below need to be removed.

Code: Select all | TOGGLE FULL SIZE
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin;
   
}  <<<<<<<<<<<<<<----------------------  remove
    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
     
       pinMode(LimitSwitchPin, INPUT_PULLUP);
   
    }
{   <<<<<<<<<<<<<<---------------------- Remove
    // Add additional functions here

}

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Fri Apr 20, 2018 5:22 am

Here is the revised code
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_PWMServoDriver.h>
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <AccelStepper.h>
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin;
   

    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
     
       pinMode(LimitSwitchPin, INPUT_PULLUP);
   
    }

    // Add additional functions here

}
   

BugStepper BugStepper1(28,29,30,31,0,2);  // Bug Stepper using servo on channel 0 and a limit switch on pin 2
BugStepper BugStepper2(32,33,34,35,1,3);
BugStepper BugStepper3(36,37,38,39,2,4);
BugStepper BugStepper4(40,41,42,43,3,5);
BugStepper BugStepper5(44,45,46,47,4,6);


  void setup() {



    while (!Serial);
    Serial.begin(9600);

  }

  void loop() {
    // put your main code here, to run repeatedly:

  }

However I get this error: expected initializer before 'BugStepper1'

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by adafruit_support_bill on Fri Apr 20, 2018 6:22 am

Ah, yes. C++ needs a semicolon to complete the class definition.

Code: Select all | TOGGLE FULL SIZE
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin;
   

    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
     
       pinMode(LimitSwitchPin, INPUT_PULLUP);
   
    }

    // Add additional functions here

} ;    <<<<<<-------------------------- Add semicolon here
   

BugStepper BugStepper1(28,29,30,31,0,2);  // Bug Stepper using servo on channel 0 and a limit switch on pin 2
BugStepper BugStepper2(32,33,34,35,1,3);
BugStepper BugStepper3(36,37,38,39,2,4);
BugStepper BugStepper4(40,41,42,43,3,5);
BugStepper BugStepper5(44,45,46,47,4,6);

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Fri Apr 20, 2018 7:11 am

The error message now tells me;

exit status 1
'BugStepper::BugStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)' is private
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_PWMServoDriver.h>
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <AccelStepper.h>
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin;
   

    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
     
       pinMode(LimitSwitchPin, INPUT_PULLUP);
   
    }

    // Add additional functions here

};
   

BugStepper BugStepper1(28,29,30,31,0,2);  // Bug Stepper using servo on channel 0 and a limit switch on pin 2
BugStepper BugStepper2(32,33,34,35,1,3);
BugStepper BugStepper3(36,37,38,39,2,4);
BugStepper BugStepper4(40,41,42,43,3,5);
BugStepper BugStepper5(44,45,46,47,4,6);


  void setup() {



    while (!Serial);
    Serial.begin(9600);

  }

  void loop() {
    // put your main code here, to run repeatedly:

  }

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

by adafruit_support_bill on Fri Apr 20, 2018 7:48 am

You can add a "public:" modifier to fix that - as below

Code: Select all | TOGGLE FULL SIZE
// BugStepper class - derived from the AccelStepper class
class BugStepper: public AccelStepper
{
 
    // Add additional state variables here

    int ServoChannel;   // channel for the bug servo
    int LimitSwitchPin;
   
    public:  // << -------- everything that follows is 'public'
   
    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pin4, uint8_t servo, uint8_t limit)
      : AccelStepper(AccelStepper::FULL4WIRE, pin1, pin2, pin3, pin4, true)
    {
      // Add additional initialization here

      ServoChannel = servo;  // remember the servo channel
      LimitSwitchPin = limit;// remember the limit switch pin
     
       pinMode(LimitSwitchPin, INPUT_PULLUP);
   
    }

    // Add additional functions here

};

adafruit_support_bill
 
Posts: 68652
Joined: Sat Feb 07, 2009 10:11 am

Re: adafruit-vs1053

by roadshark on Fri Apr 20, 2018 8:48 am

"Phew!" Code thus far compiles fine now. I have a 60 tooth pulley but it too big for the rail system I have developed but could be adapted if needed. If I can get the speed out of the stepper motor + using a 40 tooth it would be better. So I will focus on getting the motor and rail system engineered and seeing what the performance is like. I could just use a simple stepper motor program that will allow me to run a stepper up and back to see what speed I can actually get out of it. The stepper program in the Arduino example 'stepper' should do the job?
The students have had the first go at Jack-o-lantern game. They love it:)
The mounting holes in the stepper motor front. What size screws do they accept? Are they metric or imperial?

roadshark
 
Posts: 400
Joined: Sun Nov 29, 2015 5:53 am

Please be positive and constructive with your questions and comments.


cron