Micro Switch triggering stepper motors

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

Thank you for the response. That helps me understand it. Now to overcome the limitation.
The wires coming from the PSU has (like all I'm aware of) sets of wires grouped together. Some go to the GPU and some to hard drives and others to the motherboard.

I pulled both positive and GND wires from the same group.
Would it make any sense to use a positive and negative from an entirely different group?

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

If this is a multi-output power supply, then each section is going to have it's own current rating. You need to understand what those are.

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

each section is going to have it's own current rating. You need to understand what those are.
Current=amperage?
So I can use a max of 3amps and 12 volts?

I will research the PSU tonight.
In another post you mentioned 5V, tho I believe I am dealing with 12V.
The motors I am using are Stepper motor - 200 steps/rev, 12V 350mA
http://www.adafruit.com/products/324

The PSU
http://www.amazon.co.uk/Corsair-Series- ... B001A4WIBO

Guaranteed to deliver 1000W of continuous power
80%+ energy efficient under real world load conditions
True independent dual rail design for maximum compatibility
Combined 80A of power on +12V
Multiple GPU ready
105�C solid state capacitors
Active Power Factor Correction (PFC) with PF value of 0.99 to ensure clean reliable power


I'll double and triple check with one motor shield before torching the whole thing after I figure out the current question.

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

Combined 80A of power on +12V
The key word there is "combined". What is being combined and how many of them are there? The information in that link is not enough to work with. Without a complete spec and pinout diagram for your supply, it is impossible to say how much current you can get from any single pair of wires.

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

Mystery solved?????
BTW, Corsair's pinout diagram isn't available from the company and they dont return calls. The diagram is considered proprietary.

This system I am working on has a Corsair HX1000W PSU. The 12V wires are attached to four separate power distribution blocks where 2AMP fuses protect each shield from shorts. This system uses two of those blocks for the positive side and two for the ground. The following must have overcome a poor connection???)

My story-
I started learning the magic of the multimeter and at the same time the misery.
I was trying to decode the proprietary pinout diagram Corsair hides from consumers by coaxing the amperage from the grasp of the black box.......d@#* black box.
All I could measure while checking amperage in series was the draw from each board had an amperage range of 1.14-.99 millamps (same with one board or all 9 powered up).
Strike one-

I originally had 5 boards hooked up to one power dist block and 4 on another but for testing and protection I moved 9 to one block.
I hooked the tenth shield to the other dist block so it would be alone as I tried different wires from the PSU to see if I could find enough power to get 10 motor shields running.
After doing so I powered up the system expecting the same flash of 10 LED's flashing for a brief second and then going back to IGNORE.

They all lit up.
HOME RUN-

So all this for one loose wire attached to that tenth shield?
This is like a naked selfie of myself posted to a forum..and its COLD!

I could have sworn I checked all of my connections before but could have been blinded from all the face palming.

Something must have been loose because after doing the above I turned it on to check my work before playing with other 12V wires.
All 10 boards lit up.

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

Corsair's pinout diagram isn't available from the company and they dont return calls. The diagram is considered proprietary.
Guess I'll never be buying one of their products. How can they sell a power supply with no usable specifications?

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

Now that I've 'NOOB'D' this thread for four pages I'd love some help with the code.
When my system powers up for the first time I would like myMotor to move BACWARD until the micro switch http://www.adafruit.com/products/819(named : LimitSwitch) gets triggered at which point it will move FORWARD 2 steps and stop.

Code: Select all

//switch inititalization***********************
int LimitSwitch = 13;

void loop()
{
//switch setup*********************************
pinMode(LimitSwitch, INPUT);
//Send myMotor to it's HOME position when waiting for input
  if (digitalRead(LimitSwitch) == LOW)
  {
    myMotor->step(BACKWARD, SINGLE);
  }
  if (digitalRead(LimitSwitch) == HIGH)
  {
    myMotor->step(2, FORWARD, SINGLE);
  }
This will put myMotor in it's HOME position.

The switch is connected to the Adafruit Motor shields pin 13.
I've tried swapping 'HIGH' and 'LOW' in the code as well as changing the wiring on the switch (GND stayed on COM)

I tried reading this tutorial http://learn.adafruit.com/adafruit-ardu ... s/overview which helped. But the spoon it fed me with didn't quite fill me up.

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

How do you have the switch wired? Do you have a pulldown resistor? (Actually, it is simpler to use the internal pullups and invert your logic) http://learn.adafruit.com/adafruit-ardu ... duino-code

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

How do you have the switch wired? Do you have a pulldown resistor?
No resisters added. I wired the switch directly to pin 13 on the prototype area of the motor shield. Wires from the shield are attached directly to the sensor.

I had the pullup comment in my sketch but thought it was a naming scheme kind of thing.

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

You do need a pullup or pulldown or the unconnected line when the switch is open will 'float' giving you unpredictable results. There are built-in pullups, eliminating the need for external components. The tutorial linked in my previous post explains how to use them.

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

I can change the motors direction when reversing my logic but getting the switch to to it is another mater.

Code: Select all

//switch inititalization***********************
int LimitSwitch = 13;

void loop()
{
//switch setup*********************************

pinMode(LimitSwitch, INPUT_PULLUP);


//Send myMotor to it's HOME position when waiting for input
  if (digitalRead(LimitSwitch) == HIGH)
  {
    myMotor->step(10, BACKWARD, SINGLE);
  }
  if (digitalRead(LimitSwitch) == LOW)
  {
    myMotor->step(2, FORWARD, SINGLE);
  }

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

I can change the motors direction when reversing my logic but getting the switch to to it is another mater.
What does it do?

When stepping backward, I'd go 1 step at a time instead of 10. Otherwise you are likely to run past your limit switch.

Code: Select all

//Send myMotor to it's HOME position when waiting for input
  if (digitalRead(LimitSwitch) == HIGH)
  {
    myMotor->step(10, BACKWARD, SINGLE);
  }
  if (digitalRead(LimitSwitch) == LOW)
  {
    myMotor->step(2, FORWARD, SINGLE);
  }

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

I can change the motors direction when reversing my logic but getting the switch to to it is another mater.

What does it do?
I mean to say I can change the code from:

Code: Select all

if (digitalRead(LimitSwitch) == HIGH)
To:

Code: Select all

if (digitalRead(LimitSwitch) == LOW)
then my motor goes in the other direction.

Basically my sensor is being ignored.

Is there a library I need to include that tells the Uno I have a switch attached?
Like the way I include the motor library?:

Code: Select all

#include <Adafruit_MotorShield.h>
When stepping backward, I'd go 1 step at a time instead of 10. Otherwise you are likely to run past your limit switch.
That did not work. I dont think my system knows I have a switch attached.
Here is my complete sketch:

Code: Select all

#include <AccelStepper.h>
// Requires the Adafruit Motor Shield V2 library (https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library)
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // default board ID
Adafruit_MotorShield AFMS1 = Adafruit_MotorShield(0x61); // board ID + 1
Adafruit_MotorShield AFMS2 = Adafruit_MotorShield(0x62); // board ID + 2
Adafruit_MotorShield AFMS3 = Adafruit_MotorShield(0x63); // board ID + 3
Adafruit_MotorShield AFMS4 = Adafruit_MotorShield(0x64); // board ID + 4
Adafruit_MotorShield AFMS5 = Adafruit_MotorShield(0x65); // board ID + 5
Adafruit_MotorShield AFMS6 = Adafruit_MotorShield(0x66); // board ID + 6
Adafruit_MotorShield AFMS7 = Adafruit_MotorShield(0x67); // board ID + 7
Adafruit_MotorShield AFMS8 = Adafruit_MotorShield(0x68); // board ID + 8
Adafruit_MotorShield AFMS9 = Adafruit_MotorShield(0x69); // board ID + 9 (10th board)


// Connect a stepper motors with 200 steps per revolution (1.8 degree)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(200, 2);
Adafruit_StepperMotor *myMotor2 = AFMS1.getStepper(200, 1);
Adafruit_StepperMotor *myMotor3 = AFMS1.getStepper(200, 2);
Adafruit_StepperMotor *myMotor4 = AFMS2.getStepper(200, 1);
Adafruit_StepperMotor *myMotor5 = AFMS2.getStepper(200, 2);
Adafruit_StepperMotor *myMotor6 = AFMS3.getStepper(200, 1);
Adafruit_StepperMotor *myMotor7 = AFMS3.getStepper(200, 2);
Adafruit_StepperMotor *myMotor8 = AFMS4.getStepper(200, 1);
Adafruit_StepperMotor *myMotor9 = AFMS4.getStepper(200, 2);
Adafruit_StepperMotor *myMotor10 = AFMS5.getStepper(200, 1);
Adafruit_StepperMotor *myMotor11 = AFMS5.getStepper(200, 2);
Adafruit_StepperMotor *myMotor12 = AFMS6.getStepper(200, 1);
Adafruit_StepperMotor *myMotor13 = AFMS6.getStepper(200, 2);
Adafruit_StepperMotor *myMotor14 = AFMS7.getStepper(200, 1);
Adafruit_StepperMotor *myMotor15 = AFMS7.getStepper(200, 2);
Adafruit_StepperMotor *myMotor16 = AFMS8.getStepper(200, 1);
Adafruit_StepperMotor *myMotor17 = AFMS8.getStepper(200, 2);
Adafruit_StepperMotor *myMotor18 = AFMS9.getStepper(200, 1);
Adafruit_StepperMotor *myMotor19 = AFMS9.getStepper(200, 2);


char val;

void setup()
{

  Serial.begin(57600); 

  AFMS.begin();
  AFMS1.begin(); 
  AFMS2.begin(); 
  AFMS3.begin(); 
  AFMS4.begin(); 
  AFMS5.begin();
  AFMS6.begin(); 
  AFMS7.begin(); 
  AFMS8.begin(); 
  AFMS9.begin(); 

  myMotor->setSpeed(50);
  myMotor1->setSpeed(1000);
  myMotor2->setSpeed(500);
  myMotor3->setSpeed(1000);
  myMotor4->setSpeed(100);
  myMotor5->setSpeed(1000);
  myMotor6->setSpeed(100);
  myMotor7->setSpeed(1000);
  myMotor8->setSpeed(100);
  myMotor9->setSpeed(1000);
  myMotor10->setSpeed(100);
  myMotor11->setSpeed(1000);
  myMotor12->setSpeed(100);
  myMotor13->setSpeed(1000);
  myMotor14->setSpeed(1000);
  myMotor15->setSpeed(1000);
  myMotor16->setSpeed(1000);
  myMotor17->setSpeed(1000);
  myMotor18->setSpeed(1000);
  myMotor19->setSpeed(1000);
}


//switch inititalization***********************
int LimitSwitch = 13;


void loop()
{
  
  //switch setup*********************************

pinMode(LimitSwitch, INPUT_PULLUP);


//Send myMotor to it's HOME position when waiting for input
  if (digitalRead(LimitSwitch) == HIGH)
  {
    myMotor->step(1, BACKWARD, SINGLE);
  }
  if (digitalRead(LimitSwitch) == LOW)
  {
    myMotor->step(2, FORWARD, SINGLE);
  }
  
  
 //everything below this works as intended.////////////////////
  if(Serial.available())
  {
    val = Serial.read();
  }
  
  if(val == 'U'){
    myMotor->step(50, FORWARD, DOUBLE); 
    myMotor2->step(100, FORWARD, DOUBLE);
    delay(300);
    myMotor->step(60, BACKWARD, DOUBLE); 
    myMotor1->step(600, FORWARD, DOUBLE);
    myMotor->step(20, FORWARD, DOUBLE); 
    myMotor3->step(600, BACKWARD, DOUBLE);
    myMotor->step(95, FORWARD, DOUBLE); 
    myMotor5->step(500, FORWARD, DOUBLE);
    myMotor->step(20, BACKWARD, DOUBLE);  
    myMotor7->step(500, FORWARD, DOUBLE); 
    myMotor->step(34, BACKWARD, DOUBLE);
    delay(300);
    myMotor2->step(102, BACKWARD, DOUBLE); 
    myMotor4->step(80, FORWARD, DOUBLE);
    myMotor->step(50, BACKWARD, DOUBLE);
    delay(1000);

    val== 'STOP';
    
  } else if(val == 'D'){
    myMotor->step(100, BACKWARD, DOUBLE);
    
  }
    myMotor->release();
    myMotor1->release();
    myMotor2->release();
    myMotor3->release();
    myMotor4->release();
    myMotor5->release();
    myMotor6->release();
    myMotor7->release();
    myMotor8->release();
    myMotor9->release();
    myMotor10->release();
    myMotor11->release();
    myMotor12->release();
    myMotor13->release();
    myMotor14->release();
    myMotor15->release();
    myMotor16->release();
    myMotor17->release();
    myMotor18->release();
    myMotor19->release();
 
} ]

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

Re: Micro Switch triggering stepper motors

Post by adafruit_support_bill »

Basically my sensor is being ignored.

Is there a library I need to include that tells the Uno I have a switch attached?
There is no library needed for simple digital inputs. Are you sure you have the switch connected properly? Follow the tutorial linked above and debug your switch connections.

User avatar
jbc
 
Posts: 159
Joined: Wed Aug 14, 2013 7:18 pm

Re: Micro Switch triggering stepper motors

Post by jbc »

Thanks again for the quick reply.
Let me go through this after I take a break.
I don't think I can see the forest for the trees.

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

Return to “Microcontrollers”