Go Down

Topic: Arduino Due Stepper Libraries (Read 1 time) previous topic - next topic

EM501

Jul 11, 2017, 04:48 pm Last Edit: Jul 11, 2017, 05:39 pm by EM501
Hi guys.  I am trying to use my arduino due with stepper motor libraries but it appears that the libraries do not support the Due.  Do you guys have any suggestions or libraries that I could try?

Code:

Code: [Select]

#include <StepperDriver.h>
#include <AFMotor.h>
#include <AccelStepper.h>

const int maxrpm = 1000;
const int accdec_steps = 650;
const int motor_steps = 400;
const int step_division = 1;
const int en_pin = 3;
const int cw_pin = 5;      //direction pin
const int clk_pin = 3;     //step pin
int stepnumber = 0;
int rpm = 0;
int totalsteps = 6278;
int stepinterval = 1;
int stallcount = 0;
int passcount = 0;
long pos_deg;
long dircount;
int resetcount=0;

StepperDriver ss(motor_steps, step_division, en_pin, cw_pin, clk_pin);

void setup(){
  Serial.begin(9600);
  ss.powerEnable(true);
  delay(1600);
}

void loop(){
  float sensorValue=analogRead(A1);
  float voltage=sensorValue*(10.0/1023.0);
 
  if(dircount%2==0){
    pos_deg=0.032*stepnumber;
  }

  if(dircount%2==1){
    pos_deg=200-(0.032*stepnumber);
  }
   
  if(stepnumber<accdec_steps){
    rpm=rpm+(maxrpm/accdec_steps);
    ss.setSpeed(rpm);
    ss.step(stepinterval);
    if(voltage<=2){
      passcount++;
    }
    stepnumber++;
  }
 
  if(stepnumber>=accdec_steps && stepnumber<=totalsteps-accdec_steps){
    ss.setSpeed(rpm);
    ss.step(stepinterval);
    if(voltage<=2){
      passcount++;
    }
    stepnumber++;
  }
 
  if(stepnumber>totalsteps-accdec_steps){
    rpm=rpm-(maxrpm/accdec_steps);
    ss.setSpeed(rpm);
    ss.step(stepinterval);
    if(voltage<=2){
      passcount++;
    }
    stepnumber++;
  }

  if(stepnumber==totalsteps && passcount>=1){
    rpm=0;
    pos_deg=0;
    stepnumber=0;
    stepinterval=stepinterval*-1;
    dircount++;
    passcount=0;

    Serial.println("stallcount");
    Serial.println(stallcount);
    Serial.println("resetcount");
    Serial.println(resetcount);
  }

  if(stepnumber==totalsteps && passcount==0){
    if(dircount%2==0){
      ss.setSpeed(800);
      ss.step(totalsteps,accdec_steps,accdec_steps);
      resetcount++;
    }
    if(dircount%2==1){
      ss.setSpeed(800);
      ss.step(-totalsteps,accdec_steps,accdec_steps);
      resetcount++;
    }
    stallcount++;
    rpm=0;
    pos_deg=0;
    stepnumber=0;
    stepinterval=stepinterval*-1;
    dircount++;
    passcount=0;

    Serial.println("stallcount");
    Serial.println(stallcount);
    Serial.println("resetcount");
    Serial.println(resetcount);
  }
}



Also, I keep getting this error:

In file included from E:\Summer Internship 2017\ArduinoLibraryTwoDirV3\ArduinoLibraryTwoDirV3.ino:3:0:

C:\Users\etmossel\Desktop\Arduino\libraries\adafruit-Adafruit-Motor-Shield-library-99381df/AFMotor.h:156:47: error: 'DC_MOTOR_PWM_RATE' was not declared in this scope

   AF_DCMotor(uint8_t motornum, uint8_t freq = DC_MOTOR_PWM_RATE);

                                               ^

exit status 1
Error compiling for board Arduino Due (Programming Port).

ard_newbie


I think there several ways to drive a stepper motor. Two of them are registers TC_SMMR and PWM_SMMR.

E.g. datasheet page 981 for PWM_SMMR:

It is possible to configure a couple of channels to provide a 2-bit gray count waveform on 2 outputs. Dead-Time Generator and other downstream logic can be configured on these channels.

and you can change PWM frequency on the fly with PWM_CPRDUPD and duty cycle with PWM_DTYUPD.

EM501

Im not sure I understand your answer.  That may be more complicated than I am looking for.  I am just asking what the error means and if there are any libraries that work with the Arduino Due.

pert

#3
Jul 11, 2017, 11:27 pm Last Edit: Jul 11, 2017, 11:28 pm by pert
From https://github.com/adafruit/Adafruit-Motor-Shield-library:
Quote
This library is old and deprecated - and the hardware disconinued years ago. V2 of the shield uses i2c only and works with anything that has I2C support (e.g. all arduinos) without endless incompatibilities and porting requirements!
Are you sure that you need to use that library (AFmotor.h)?

EM501

I looked and that library is not needed.  Apparently that library is not supported by the DUE.  Thank you for your help the program works great.


Go Up