Micro Switch triggering stepper motors
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Micro Switch triggering stepper motors
That looks OK., But it the switches are mounted remotely, you don't need to use the prototyping area. Just wire directly to GND and the arduino pin breakouts.
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
So one wire from ground to a row in the prototype area which would allow me to connect 14 micro switches (placing the other wire from the switch into pins 0-13).
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
I am unable to get the sensor recognized nor the code compiled.
I've taken out any (failed) reference to the micro switch/sensor.
I have the sensor attached to pin 13 on the adafruit motorshield with i2C address of 0x69.
Here is the code I am using to control my steppers.
I need help setting the switch up and could also use help in getting it to tell 'myMotor' on motor shield AFMS (0X060) that when switch is hit 'myMotor' is at position 0 (which will be named home).
I'm a hot mess.
I've taken out any (failed) reference to the micro switch/sensor.
I have the sensor attached to pin 13 on the adafruit motorshield with i2C address of 0x69.
Here is the code I am using to control my steppers.
I need help setting the switch up and could also use help in getting it to tell 'myMotor' on motor shield AFMS (0X060) that when switch is hit 'myMotor' is at position 0 (which will be named home).
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);
Adafruit_MotorShield AFMS2 = Adafruit_MotorShield(0x62);
Adafruit_MotorShield AFMS3 = Adafruit_MotorShield(0x63);
Adafruit_MotorShield AFMS4 = Adafruit_MotorShield(0x64);
Adafruit_MotorShield AFMS5 = Adafruit_MotorShield(0x65);
Adafruit_MotorShield AFMS6 = Adafruit_MotorShield(0x66);
Adafruit_MotorShield AFMS7 = Adafruit_MotorShield(0x67);
Adafruit_MotorShield AFMS8 = Adafruit_MotorShield(0x68);
Adafruit_MotorShield AFMS9 = Adafruit_MotorShield(0x69);
// 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(1000);
myMotor1->setSpeed(1000);
myMotor2->setSpeed(1000);
myMotor3->setSpeed(1000);
myMotor4->setSpeed(1000);
myMotor5->setSpeed(1000);
myMotor6->setSpeed(1000);
myMotor7->setSpeed(1000);
myMotor8->setSpeed(1000);
myMotor9->setSpeed(1000);
myMotor10->setSpeed(1000);
myMotor11->setSpeed(1000);
myMotor12->setSpeed(1000);
myMotor13->setSpeed(1000);
myMotor14->setSpeed(1000);
myMotor15->setSpeed(1000);
myMotor16->setSpeed(1000);
myMotor17->setSpeed(1000);
myMotor18->setSpeed(1000);
myMotor19->setSpeed(1000);
}
void loop()
{
if(Serial.available())
{
val = Serial.read();
}
if(val == 'U'){
myMotor->step(200, FORWARD, DOUBLE);
myMotor1->step(200, FORWARD, DOUBLE);
delay(2000);
myMotor10->step(100, FORWARD, DOUBLE);
myMotor11->step(100, FORWARD, DOUBLE);
myMotor->step(800, BACKWARD, DOUBLE);
val== 'STOP';
} else if(val == 'D'){
myMotor->step(100, BACKWARD, DOUBLE);
}
I'm a hot mess.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Micro Switch triggering stepper motors
Your code only needs a closing '}' to compile. Remember that for each '{' you need a matching '}'.
To connect your switches, first you need to define the PinMode in setup()" http://arduino.cc/en/Reference/pinMode
We use INPUT_PULLUP to set the pin as an input pin, and to enable the internal pullup resistor. This will force the input signal to be HIGH when the switch is open. It will go LOW when the switch closes and pulls the signal to ground.
To read teh state of the switch, you can use digitalRead(); http://arduino.cc/en/Reference/DigitalRead
To connect your switches, first you need to define the PinMode in setup()" http://arduino.cc/en/Reference/pinMode
Code: Select all
for (int i = 0; i <= 13; i++ // for all the digital input pins...
{
pinMode(i, INPUT_PULLUP);
}
To read teh state of the switch, you can use digitalRead(); http://arduino.cc/en/Reference/DigitalRead
Code: Select all
if (digitalRead(13) == LOW)
{
// switch is closed - do something
}
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
So the stacking shield i2C address does not some into play at all.To connect your switches, first you need to define the PinMode in setup()" http://arduino.cc/en/Reference/pinMode
CODE: SELECT ALL
for (int i = 0; i <= 13; i++ // for all the digital input pins...
{
pinMode(i, INPUT_PULLUP);
}
OK thank you now I know three things....my list is growing.
Code: Select all
if (digitalRead(13) == LOW)
{
// switch is closed - do something
}
What language do you use when working with Arduino?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Micro Switch triggering stepper motors
That is correct. You have a direct connection to those digital pins. (and the analog ones too).So the stacking shield i2C address does not some into play at all.
The "Arduino Language" is really just a thin layer over C++. Most of the C++ language is usable on the Arduino and that is what I write in.What language do you use when working with Arduino?
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
Thank you Bill.
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
Bill,
I wired the micro switch to the prototype area on the motor shield but my PSU run's a brief second before turning off (safety switch I guess). If I disconnect the power to this shield the PSU will stay on and power the other connected shields as intended.
Is my wiring on the micro switch wrong or do I have a shot motor shield?
Here's a picture of the soldered wires attached too pin 15 on to my motor shield.
Thoughts?
I wired the micro switch to the prototype area on the motor shield but my PSU run's a brief second before turning off (safety switch I guess). If I disconnect the power to this shield the PSU will stay on and power the other connected shields as intended.
Is my wiring on the micro switch wrong or do I have a shot motor shield?
Here's a picture of the soldered wires attached too pin 15 on to my motor shield.
Thoughts?
- Attachments
-
- Adafruit shield with one micro switch attached to Micro switch soldered to motor shield
- photo (1).JPG (158.03 KiB) Viewed 1667 times
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Micro Switch triggering stepper motors
I'd need to see where all those wires go. A photo showing everything or a wiring diagram would be good.
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
I tried to block those out in the previous picture so the wire colors wouldn't make things confusing.
I don't have access to more than four colors.
I hope this picture gives you what you need. (I rotated the picture but for some reason it stayed upside down)
jbc
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Micro Switch triggering stepper motors
Post a photo showing the soldering on the other side of the board.
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
I think I found my noob issue.
I soldered in the jumpers.
I am supplying power to the board through the PSU and I bet it see's that issue and turns off.
I soldered in the jumpers.
I am supplying power to the board through the PSU and I bet it see's that issue and turns off.
- Attachments
-
- Can't solder jumper and use a PSU!
- photo (3).JPG (154.16 KiB) Viewed 1651 times
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
hmmmm.... i have the jumper soldered in place but not bridged. I don't think that's the problem.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Micro Switch triggering stepper motors
That would prevent the switch from doint much, but it wouldn't cause the power supply problem. What are you using to power the shield? What are you using to power the Arduino? If you are using two different power supplies, did you remove the power jumper?hmmmm.... i have the jumper soldered in place but not bridged. I don't think that's the problem.
- jbc
- Posts: 159
- Joined: Wed Aug 14, 2013 7:18 pm
Re: Micro Switch triggering stepper motors
I am using a 1000 PSU. No other power source other than what the Uno gets from the USB.What are you using to power the shield? What are you using to power the Arduino? If you are using two different power supplies, did you remove the power jumper?
I have not used a power jumper- I have it soldered in place but was not used.
Before I soldered the switch onto the motor shield I had all 10 motor shields controlling 20 steppers.
Everything was great.
I added the wiring for the switch and now the PSU comes on for a brief split second-lighting up all of the motor shield's LED and then the PSU promptly stops.
All other shields along with the PSU preform again once I detach the PSU's power to the shield with the switch soldered on it.
I am tempted to cut the wires I soldered onto the shields prototype area to see if the board is ok. I wanted to ask you first.
(I get the same PSU powering down state whether I have a micro switch attached or not).
Please be positive and constructive with your questions and comments.