Hallo,
I want to create a project, to drive 2 stepper motors using Adafruit Motor shield V2 + 2 button switch (start and stop) but I do not know to make the program and how to wiring button switch with Adafruit motor shield
My plan, when the switch button (start) is pressed motor ON and when the switch button (stop) is pressed again the motor does OFF.
Please help Me,
Regards,
BANNED.S
How To Make A Program Adafruit Motor Shield V2 With Button S
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
How To Make A Program Adafruit Motor Shield V2 With Button S
- Attachments
-
- This button switches which I will use
- images.jpg (5.52 KiB) Viewed 1925 times
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Do you have your motor connected and tested? That is the place to start.
Then connect your switch and make sure you can read the switch state reliably.
This tutorial explains how: https://learn.adafruit.com/adafruit-ard ... tal-inputs
Then connect your switch and make sure you can read the switch state reliably.
This tutorial explains how: https://learn.adafruit.com/adafruit-ard ... tal-inputs
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Yes
how to declare motor stepper in program, whether directly int myStepper1 or else
regards
BANNED.S
how to declare motor stepper in program, whether directly int myStepper1 or else
regards
BANNED.S
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Instructions for driving stepper motors are here: https://learn.adafruit.com/adafruit-mot ... per-motors
Use the StepperTest example from the library to make sure that your motor is connected properly and working.
Use the StepperTest example from the library to make sure that your motor is connected properly and working.
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Hallo I've tried it, but i dont know to declare motor stepper in program
example :
example :
Code: Select all
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
int buttonApin = 2 ;
int buttonBpin = 3 ;
int stepperMotor; // how to declare the motor
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
void setup() {
Serial.begin(9600);
Serial.println("Stepper test!");
pinMode(stepperMotor, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
AFMS.begin();
myMotor->setSpeed(10);
}
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Hallo,
can you make sample program to me about adafruit motor shield with button
can you make sample program to me about adafruit motor shield with button
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Just like in the example code:Hallo I've tried it, but i dont know to declare motor stepper in program
Code: Select all
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
Does the motor work with the example code?can you make sample program to me about adafruit motor shield with button
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
i use example code stepper test, but i dont know to combine the code with button switch,
Code: Select all
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control
For use with the Adafruit Motor Shield v2
----> http://www.adafruit.com/products/1438
*/
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
int buttonPin1 = 2 ;
int buttonPin2 = 3 ;
int myStepper ;
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
pinMode (buttonPin1, INPUT_PULLUP);
pinMode (buttonPin2, INPUT_PULLUP);
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
myMotor->setSpeed(10); // 10 rpm
}
void loop() {
if (digitalRead(buttonPin1) == HIGH)
{
digitalWrite(myStepper, HIGH);
}
if (digitalRead(buttonPin2) == LOW)
{
digitalWrite(myStepper, LOW);
}
}
How to declare Motor Stepper at Void Setup and Void Loop
i really not understand, please give me instruction step by step.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
You want the stepper to start running when you press button 1, and you want it to stop when you press button 2. So, you need to check both buttons in loop(). LOW means that the button is pressed. If button 1 is pressed, set a variable to say that the motor should be running. If button 2 is pressed, set the variable to say that the motor should be stopped:
Now, if the variable says that the motor should be running, advance the motor by one step:
Here's the entire sketch:
Code: Select all
if (digitalRead(buttonPin1) == LOW) //if start button is pressed
{
runState = true; //start running stepper
}
if (digitalRead(buttonPin2) == LOW) //if stop button is pressed
{
runState = false; //stop running stepper
}
Code: Select all
if (runState) //if the stepper should be running
{
myMotor->step(1, FORWARD, SINGLE); //advance it one step.
}
Code: Select all
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control
For use with the Adafruit Motor Shield v2
----> http://www.adafruit.com/products/1438
*/
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
int buttonPin1 = 2 ;
int buttonPin2 = 3 ;
bool runState = false;
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
pinMode (buttonPin1, INPUT_PULLUP);
pinMode (buttonPin2, INPUT_PULLUP);
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
myMotor->setSpeed(10); // 10 rpm
}
void loop() {
if (digitalRead(buttonPin1) == LOW) //if start button is pressed
{
runState = true; //start running stepper
}
if (digitalRead(buttonPin2) == LOW) //if stop button is pressed
{
runState = false; //stop running stepper
}
if (runState) //if the stepper should be running
{
myMotor->step(1, FORWARD, SINGLE); //advance it one step.
}
}
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
thank you very much
so, to run 2 motors at once, what should be added in the program
sorry before, I inquired continue
regards
BANNED.S
so, to run 2 motors at once, what should be added in the program
sorry before, I inquired continue
regards
BANNED.S
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Assuming that you want them both to do the same thing. Simply define another motor:so, to run 2 motors at once, what should be added in the program
Code: Select all
Adafruit_StepperMotor *myOtherMotor = AFMS.getStepper(200, 1);
Code: Select all
myMotor->step(1, FORWARD, SINGLE); //advance it one step.
myOtherMotor->step(1, FORWARD, SINGLE); //advance it one step.
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
thank you very much :-)
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Hallo,
I want to ask how to set the speed of the motor using a potentiometer
Thanks
I want to ask how to set the speed of the motor using a potentiometer
Thanks
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
Assuming that you have a potentiometer connected to analog 0, this code should do it:
Code: Select all
int speed = map(analogRead(0), 0, 1024, 0, 255); // Map the potentiometer input intoa motor speed
motor.setSpeed(speed);
- Inra_Juntak
- Posts: 68
- Joined: Thu Sep 04, 2014 3:26 am
Re: How To Make A Program Adafruit Motor Shield V2 With Butt
I've tried the code themselves but it does not work
My plan to drive the motor using the button. Where speed is set by potentiometer
Where the code i will type in the sketch
Error "motor" not declared
My plan to drive the motor using the button. Where speed is set by potentiometer
Where the code i will type in the sketch
Error "motor" not declared
Please be positive and constructive with your questions and comments.