Newby Onestep function for a4988 question

Is there a way of using a one step function with the A4988? Id like the motor to move 1 step every 36 seconds. Are there libraries I should be utilizing for this function? I am new to the Pololu world so any help would be greatly appreciated.

Hello.

When using the A4988, each low to high transistion of the step pin advances the motor by one step. Therefore, you should send one square wave pulse each time you want the motor to make a step.

-Claire

So I understand that I should send one square wave. Tomorrow I will post a pic of my set up. When I say Newbie i mean totally new at the Pololu product. I had a bad experience with the Baby Orangutan and got scared off of your product but the A4988 seems promising if I can get it to work. I have my program working using Adafruits motor shield but would prefer to use the A4988. Here is the code I have started with. I figure this should be easy to control but my motor either makes a high pitched sound when not stepping OR makes a high pitched sound while turning slowly. I think its just the 36 second pauses I am having a problem with.

}

}

#define stepPin 2
#define dirPin 3
#define enablePin 4

void setup()
{
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, HIGH); 
  
  Serial.begin(9600);
  Serial.println("Starting stepper exerciser.");
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
}
void loop()
{
  int j;
  digitalWrite(enablePin, LOW); 
  delayMicroseconds(36000);
  digitalWrite(dirPin, HIGH);
  
  for(j=0; j<=200; j++) 
  {
    digitalWrite(stepPin, LOW);
    delayMicroseconds(20000);
    delay(20000);
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(10000);

Hello.

First, let me point out that you are using two different delay functions in your code: delay and delayMicroseconds. Delay accepts a millisecond value while delayMicroseconds accepts a microsecond value. Also, the enable pin on the A4988 is internally pulled low so you do not need to do anything with it in your code.

Here is an example of a simple program that steps the motor every 36 seconds to get
you started.

#define stepPin 2
#define dirPin 3

void setup()
{  
  Serial.begin(9600);
  Serial.println("Starting stepper exerciser.");
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  digitalWrite(dirPin, HIGH);
}
void loop()
{
  digitalWrite(stepPin, HIGH);
  delay(1000);
  digitalWrite(stepPin, LOW);
  delay(35000);
}

In addition, could you post a picture of your setup with all the connections?

I am sorry to hear you had a bad experience with the Baby Orangutan; if you would like, we could also try to help you with that.

-Claire

Thank you so much for your help. That worked well. I now have the motor moving in one direction or the other. My only issue now is that I am having a problem controlling direction and speed. The program I am trying to mimic is the following which worked with my Adafruit Motor Shield

#include <AccelStepper.h>

#include <AFMotor.h>


AF_Stepper stepper(50, 2);
const int steps = 50;

 
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Clock intial start!");

}

void loop () {
   for (int i = 0; i < 100; i++) { 
   stepper.onestep (FORWARD, DOUBLE);
delay(3000);

Why can i not just upload this program to the a4988?

The libraries used in this code were designed specifically for the Adafruit motor shield and are not directly compatible with the A4988. There is no reason to expect code based on those libraries to work with anything other than the specific device and connections it was written for.

However, you can easily control the speed and direction of your motor by simply adjusting the amount of delay between steps and toggling the direction pin.

-Claire

Thanks for helping me understand the difference between the 2 items. With so many items out there its been hard to figure out what works with what. I think I am close to understanding this pulse width issue. I’ll probably have a million more questions but for now i think I can keep plugging away until i get stuck again.
Thanks again