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 Fri Aug 10, 2018 7:50 am

How are the limit switches connected? From the pin to GND?

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

Re: adafruit-vs1053

by roadshark on Fri Aug 10, 2018 9:48 am

From the pin to the switch then form the switch to common ground shared with the mega.

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

Re: adafruit-vs1053

by adafruit_support_bill on Fri Aug 10, 2018 10:06 am

Does manually activating one or both limit switches result in any motor movement?

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

Re: adafruit-vs1053

by roadshark on Fri Aug 10, 2018 9:16 pm

Does manually activating one or both limit switches result in any motor movement?

No. When powered up the motors can not be moved manually along the rail so they are getting power. It is like they think they are at home already even when in the middle of the slide. lf I remember correctly, because I am using the pull up resistors of the itsy, the switch when pressed goes low as when it is opened it goes high?

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

Re: adafruit-vs1053

by adafruit_support_bill on Sat Aug 11, 2018 6:23 am

So the motors are wired correctly. The problem is in the home/limit switches.

You have them defined as "A0, A1"
Code: Select all | TOGGLE FULL SIZE
BugStepper BugStepper1(5, 7, A0, A1);

Try a simple sketch to read the state of these and see if they react to operating the switch:

something like . . .
Code: Select all | TOGGLE FULL SIZE
void setup()
{
    Serial.begin(9600);
    pinMode(A0, INPUT_PULLUP);
    pinMode(A1, INPUT_PULLUP);
}

void loop()
{
    Serial.print("A0 =  ");
    Serial.print(digitalRead(A0);
    Serial.print("  A1 =  ");
    Serial.println(digitalRead(A1);
}

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

Re: adafruit-vs1053

by roadshark on Sat Aug 11, 2018 6:57 am

When i power up I get 1's and when I push the switches I get 0's.

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

Re: adafruit-vs1053

by adafruit_support_bill on Sat Aug 11, 2018 7:36 am

OK. That sounds right. So the problem is somewhere in the code then.

Try homing the motors one at a time:

Code: Select all | TOGGLE FULL SIZE
  while (!BugStepper1.IsHome())
  {
    BugStepper1.RunToHome();
  }
 
  while (!BugStepper2.IsHome())
  {
    BugStepper2.RunToHome();
  }

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

Re: adafruit-vs1053

by roadshark on Sat Aug 11, 2018 7:52 am

Motors get power but do not move.
Code: Select all | TOGGLE FULL SIZE
  #include <AccelStepper.h>
#include <Wire.h>


class BugStepper: public AccelStepper
{
    // Add additional state variables here


    int LimitSwitchPinHome; //Limit pin for start (home)
    int LimitSwitchPinEnd;//Limit pin for bug turn around.
  public:  // << -------- everything that follows is 'public'


    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t limitH, uint8_t limitE)
      : AccelStepper(AccelStepper::FULL2WIRE, pin1, pin2, true)
    {
      // Add additional initialization here


      LimitSwitchPinHome = limitH;// remember the limit switch pin
      LimitSwitchPinEnd = limitE;//remember the end limit switch pin

      pinMode(LimitSwitchPinHome, INPUT_PULLUP);
      pinMode(LimitSwitchPinEnd, INPUT_PULLUP);

    }

    // Add additional functions here


    bool IsHome()
    {
      return !digitalRead(LimitSwitchPinHome);  // Home switch is active LOW
    }

    void RunToHome()
    {
      if (!IsHome())
      {
        run();
      }
    }

};
BugStepper BugStepper1(5, 7, A0, A1); // BugStepper1 motor on pin 5 and 7 with a limit switch Home on pin A0 and limit switch End on pin A1
BugStepper BugStepper2(9, 10, A2, A3); //  BugStepper2 motor on pin 9 and 10 with a limit switch Home on pin A2 and limit switch End on pin A3
void setup() {
  Wire.begin(8);
  BugStepper1.setMaxSpeed(2000.0);
  BugStepper1.setAcceleration(2000.0);
  BugStepper1.moveTo(-5000);
  BugStepper2.setMaxSpeed(2000.0);
  BugStepper2.setAcceleration(2000.0);
  BugStepper2.moveTo(-5000);
    while (!BugStepper1.IsHome())
  {
    BugStepper1.RunToHome();
  }
 
  while (!BugStepper2.IsHome())
  {
    BugStepper2.RunToHome();
  }

}
  void loop() {

  }
 

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

Re: adafruit-vs1053

by adafruit_support_bill on Sat Aug 11, 2018 8:41 am

So there is something wrong in the Home logic. Seems simple enough. But somehow it is not working as expected.

Try changing the IsHome function to this and see what prints out.

Code: Select all | TOGGLE FULL SIZE
    bool IsHome()
    {
      bool home = (digitalRead(LimitSwitchPinHome) == 0);  // Home switch is active LOW
      if (home)
      {
        Serial.println("Home!");
      }
      return home; 
    }

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

Re: adafruit-vs1053

by roadshark on Sat Aug 11, 2018 9:15 am

When I press the home button the serial monitor reads
Home!
Home!
if I press the button again nothing appears.

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

Re: adafruit-vs1053

by adafruit_support_bill on Sat Aug 11, 2018 9:29 am

Fair warning. You are taking advice from someone that just sent a stepper driver up in smoke. Excuse my while I open a window and turn on a fan.

When I press the home button the serial monitor reads
Home!
Home!

So the IsHome function should be working.
if I press the button again nothing appears.

That implies that it has exited the 'while' loop - as it should.
The remaining question is: why is it not stepping the motor?

I think some more diagnostic output is in order. Try this:

Code: Select all | TOGGLE FULL SIZE
  #include <AccelStepper.h>
#include <Wire.h>


class BugStepper: public AccelStepper
{
    // Add additional state variables here


    int LimitSwitchPinHome; //Limit pin for start (home)
    int LimitSwitchPinEnd;//Limit pin for bug turn around.
  public:  // << -------- everything that follows is 'public'


    // BugStepper constructor - calls the base class AccelStepper constructor
    BugStepper(uint8_t pin1, uint8_t pin2, uint8_t limitH, uint8_t limitE)
      : AccelStepper(AccelStepper::FULL2WIRE, pin1, pin2, true)
    {
      // Add additional initialization here


      LimitSwitchPinHome = limitH;// remember the limit switch pin
      LimitSwitchPinEnd = limitE;//remember the end limit switch pin

      pinMode(LimitSwitchPinHome, INPUT_PULLUP);
      pinMode(LimitSwitchPinEnd, INPUT_PULLUP);

    }

    // Add additional functions here


    bool IsHome()
    {
      bool home = (digitalRead(LimitSwitchPinHome) == 0);  // Home switch is active LOW
      if (home)
      {
        Serial.println("Home!");
      }
      return home; 
    }

    void RunToHome()
    {
      if (!IsHome())
      {
        run();
      }
    }

};
BugStepper BugStepper1(5, 7, A0, A1); // BugStepper1 motor on pin 5 and 7 with a limit switch Home on pin A0 and limit switch End on pin A1
BugStepper BugStepper2(9, 10, A2, A3); //  BugStepper2 motor on pin 9 and 10 with a limit switch Home on pin A2 and limit switch End on pin A3
void setup() {
  Wire.begin(8);
  BugStepper1.setMaxSpeed(2000.0);
  BugStepper1.setAcceleration(2000.0);
  BugStepper1.moveTo(-5000);
  BugStepper2.setMaxSpeed(2000.0);
  BugStepper2.setAcceleration(2000.0);
  BugStepper2.moveTo(-5000);
    while (!BugStepper1.IsHome())
  {
    Serial.println("Motor 1 Running");
    BugStepper1.RunToHome();
  }
  Serial.println("Motor 1 Home");

 
  while (!BugStepper2.IsHome())
  {
    Serial.println("Motor 2 Running");
    BugStepper2.RunToHome();
  }
  Serial.println("Motor 2 Home");
}
  void loop() {

  }
 

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

Re: adafruit-vs1053

by roadshark on Sat Aug 11, 2018 9:51 am

When uploaded I get motor 1 running when I press the home switch of motor 1 I get motor 2 running. Mmmm I love the smell of Stepper motor smoke in the afternoon:)

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

Re: adafruit-vs1053

by adafruit_support_bill on Sat Aug 11, 2018 9:54 am

So the serial output says that it is running, but the motors do not move?

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

Re: adafruit-vs1053

by roadshark on Sat Aug 11, 2018 9:58 am

yes.

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

Re: adafruit-vs1053

by adafruit_support_bill on Sat Aug 11, 2018 10:02 am

OK. I must be missing something obvious here.

Try replacing BugStepper1.RunToHome(); with BugStepper1.Run();

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

Please be positive and constructive with your questions and comments.