Pages: [1]   Go Down
Author Topic: Help with AccelStepper  (Read 1392 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've written a sketch using the Adafruit motor shield to take a picture, move a mirror at constant stepper speed 296 steps, take a 2nd picture, and return. I'd like to have the mirror accelerate and deaccelerate instead of running at constant speed so I can get it in position more quickly.  I've read and tried all of the AccelStepper examples but I can't figure out how to just do a single accel/deaccel movement followed by other code followed by another movement.

Also I have a bipolar motor and I think the AccelStepper code defaults to unipolar and I can't figure out I tell it my motor is bipolar??
Here is my code and I would like to just replace the current motor movement with  AccelStepper code.  Are there examples I can copy?  Where would I find them?

#include <AFMotor.h>

AF_Stepper motor(400, 2);//400 steps per rev, port 2 M3-M4
byte camtrig=13;//set output 13 to trigger camera
int prepulse=125;
int campulse=55;
int picdelay=215;
int flipdelay=50;//delay pic1 to start flip
float rate=1;//multiplier for speed of machine
byte mirrorPos=0;//flag for mirror position
byte button=2;//button to trigger cycle
int sensor=1;// flip mirror sensor
int delta=14;// mirror adj to home position

void setup() {
  Serial.begin(9600);// set up Serial library at 9600 bps
  Serial.flush();//clear serial line
  motor.release();//motor off
  pinMode(camtrig,OUTPUT); //set pin 13 as output
  motor.setSpeed(20);//motor speed at initialize
void loop(){
// check if button is pressed 
  byte state2 = digitalRead(button);
  if (state2 == HIGH ) {
// Call the function pic flip and pic

void PicFlipPic(){
//Take pic1
  digitalWrite(camtrig,HIGH);//pretrigger 1
  digitalWrite(camtrig,HIGH);//picture 1
//End pic1

  motor.setSpeed(80); //80 rpm
  motor.step(296, BACKWARD, DOUBLE);//#steps, direction, steptype

//Take pic2
  digitalWrite(camtrig,HIGH);//pretrigger 2
  digitalWrite(camtrig,HIGH);//picture 2
//End pic2

  motor.setSpeed(40);  //40 rpm   
  motor.step(296, FORWARD, SINGLE);
  delay (1000);


Offline Offline
Jr. Member
Karma: 0
Posts: 70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi ThomasT,
Im studying this library too. I found your issue on this line:
motor.step(296, FORWARD, SINGLE);
If you want to change the stepper for Bipolar, you must change every  SINGLE to DOUBLE.
Actually AFMotor.h has these settings ( i dont know how to name it , I'm not a coder).

Make a test and see what happens.

« Last Edit: September 19, 2011, 03:29:06 pm by tomasi » Logged

Offline Offline
Shannon Member
Karma: 216
Posts: 12556
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please use the code button ('#') to include code in the postings, its much more readable that way...

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: