Hi Everyone, Like a lot of us here im new at this programming but im keen. :)
Im working on a project with an UNO and a motor shield v2 with a stepper the typical 18 deg / 200 step. 4 wire.
I can make it work with the basics but I have a purpose for this and I need it to
be able to be controlled with a Pot only with speed.
The other problem is im trying to get it to go to a home position with a reed switch and then move till it hits
another reed switch and then reverse , so it goes back and forth..?
Can anyone point me in the right direction with this or help on the code, I would be much appreciated !! I feel after hours im not
moving forward.. Thanks
Motor Shield V2
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: Motor Shield V2
Post the code you are currently using and explain what parts work and what does not.
-
- Posts: 8
- Joined: Mon Jun 09, 2014 1:33 pm
Re: Motor Shield V2
Ok so ive been trying the button part first to see if I can get it to just turn the motor off and on then I was going to try and see if I could adjust it to change direction then I would add another reed switch. Im guessing a reed switch would act like a push button.
Code: Select all
#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();
// 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);
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 0; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(100); // OR with a different frequency, say 1KHz
myMotor->setSpeed(100); // 50 rpm
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is Low:
if (buttonState == Low)
// turn off:
myMotor->step(FORWARD, SINGLE); }
}
Last edited by adafruit_support_bill on Tue Jun 10, 2014 7:54 am, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2
That code looks pretty straightforward. How do you have your pushbutton wired? If you don't have an external pullup resistor, you can enable the internal one in your pinMode statement:
That should run the motor for as long as you have the button pressed.
You may also need a delay in your loop so that the motor doesn't try to step too fast:
Code: Select all
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
You may also need a delay in your loop so that the motor doesn't try to step too fast:
Code: Select all
if (buttonState == Low)
{
// turn off:
myMotor->step(FORWARD, SINGLE);
delay(10)
}
-
- Posts: 8
- Joined: Mon Jun 09, 2014 1:33 pm
Re: Motor Shield V2
Thanks so much !! .. ill work on it some more ~ as they say one step at a time :)
Please be positive and constructive with your questions and comments.