I directly type the code in void loop,i have inserted the code but not working,Please check my code if there is one wrong
Thanks, i'm sorry before
Moderators: adafruit_support_bill, adafruit
I directly type the code in void loop,i have inserted the code but not working,Please check my code if there is one wrong
Please tell us exactly what is not working. Is it not compiling? Is it not running? Does the motor do anything at all?i have inserted the code but not working
Hello
I've tried the code many times and finally succeeded, but I have a new problem when I turn the potentiometer to the smallest value ("0") and then rotate back to the highest value ("255") the motor does not move at all, if you want I have to move the motor back to reset the motor drivers
I am using the code below
Code: Select all
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
int buttonPin1 = 2 ;
int buttonPin2 = 3 ;
int potPin = A0;
int speed ;
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(400, 2);
Adafruit_StepperMotor *myOtherMotor = AFMS.getStepper(400, 1);
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(400, 2);
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
}
void loop() {
speed = analogRead (potPin);
speed = map (speed, 0, 1023, 0, 255);
myMotor->setSpeed(speed);
Serial.println (speed);
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, DOUBLE); //advance it one step.
myOtherMotor->step(1, BACKWARD, DOUBLE); //advance it one step.
}
}
This results in the serial monitor when i turn the potentiometer from the largest value to the smallest value
Your screen shot only shows 255 which is the maximum value. Does the value go all the way to zero when you turn the pot to the other end?This results in the serial monitor when i turn the potentiometer from the largest value to the smallest value
wait a minute
the position of the smallest value ("0") the motor does not move immediately despite the start button is pressed, and when the back is turned to the highest value of the motor is not moving
Code: Select all
speed = map (speed, 0, 1023, 1, 255);
Thank You Very Much
whether the value of the serial monitor of 1-255 declared rotation speed of the motor in units of RPM
If I want to use that type of motor below, how do I know the maximum speed and minimum speed ideally
I've been finding but can not find the datasheet
Thank Youbut if i use this motor (http://www.dfrobot.com/index.php?route= ... uct_id=785) What is the maximum speed and minimum ideally
This motor is not compatible with the V2 motor shield. The current per phase is too high.Rated Voltage : 3.4V
Current : 1.7A/PHASE