How To Make A Program Adafruit Motor Shield V2 With Button S

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

i have inserted the code but not working,Please check my code if there is one wrong
I directly type the code in void loop,

Thanks, i'm sorry before

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

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by adafruit_support_bill »

i have inserted the code but not working
Please tell us exactly what is not working. Is it not compiling? Is it not running? Does the motor do anything at all?

If you don't give us any information about the problem we don't know what to look for.

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

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.
  
  }
}

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

This results in the serial monitor when i turn the potentiometer from the largest value to the smallest value
Attachments
1.png
1.png (122.4 KiB) Viewed 406 times

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

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by adafruit_support_bill »

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?

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

wait a minute
Attachments
2.png
2.png (120.3 KiB) Viewed 405 times

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

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

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

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by adafruit_support_bill »

When the value goes to zero, the step interval becomes infinite.

Try changing the map statement so that it doesn't go all the way to zero:

Code: Select all

 speed = map (speed, 0, 1023, 1, 255);

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

Thank You Very Much

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

whether the value of the serial monitor of 1-255 declared rotation speed of the motor in units of RPM

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

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by adafruit_support_bill »

Yes. It is in RPM.

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

If I want to use that type of motor below, how do I know the maximum speed and minimum speed ideally
Attachments
DSC_0003.jpg
DSC_0003.jpg (774.48 KiB) Viewed 347 times
Last edited by Inra_Juntak on Wed Sep 24, 2014 2:19 pm, edited 1 time in total.

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

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by adafruit_support_bill »

Please post a link to the data sheet for that motor.

User avatar
Inra_Juntak
 
Posts: 68
Joined: Thu Sep 04, 2014 3:26 am

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by Inra_Juntak »

I've been finding but can not find the datasheet
but if i use this motor (http://www.dfrobot.com/index.php?route= ... uct_id=785) What is the maximum speed and minimum ideally
Thank You

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

Re: How To Make A Program Adafruit Motor Shield V2 With Butt

Post by adafruit_support_bill »

Rated Voltage : 3.4V
Current : 1.7A/PHASE
This motor is not compatible with the V2 motor shield. The current per phase is too high.
https://learn.adafruit.com/all-about-st ... he-stepper

These motors are a good match: https://www.adafruit.com/product/324
With the #324 motor you can get about 80 RPM with the standard library. With a modified library you can get over 200 RPM.
The minimum speed for any motor is always 0 RPM.

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

Return to “Arduino Shields from Adafruit”