Accelstepper without motor or driver.

266 views
Skip to first unread message

ss_a...@yahoo.co.uk

unread,
Apr 24, 2013, 6:27:29 PM4/24/13
to accels...@googlegroups.com
I'm trying to debug my arduino sketch with just the arduino since I can't move my steppermotor and driver to my computer easily. Is it possible to do so?
What does "stepper.currentPosition()" if no motor or motor driver is connected?

Sandy Noble

unread,
Apr 24, 2013, 6:29:49 PM4/24/13
to accels...@googlegroups.com
Yep you don't need anything connected to run the software - accelstepper does not get any feedback from the driver circuit or the motor.  CurrentPosition() will just be 0.0 (at startup), or whatever you last moved it to otherwise.

sn


On 24 April 2013 23:27, <ss_a...@yahoo.co.uk> wrote:
I'm trying to debug my arduino sketch with just the arduino since I can't move my steppermotor and driver to my computer easily. Is it possible to do so?
What does "stepper.currentPosition()" if no motor or motor driver is connected?

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Sandy Noble

ss_a...@yahoo.co.uk

unread,
Apr 25, 2013, 5:18:25 AM4/25/13
to accels...@googlegroups.com
Thanks, that's good to know. This leads me to another question, the code below has some unexpected behaviour. The code prints the current position when "CPos" is received over serial and sets a position to move to with "CPos x" where x is a number. The unexpected behaviour is that currentPosition() does not match the requested position, but only on odd tries. i.e sending "CPos 1", will not work ("CPos" will still report 0), then sending "CPos 2" will work, then sending "CPos 3" will not work, then sending "CPos 1" will work (it has nothing to do with the actual number requested). Asking for a negative number (CPos -1) will result in currentPosition() reporting an ever increasing number. Any ideas why this is happening?

#include <AccelStepper.h> //library for stepper motor
#include <SerialCommand.h> //library for serial commands

#define EDDIR 19      // PIN Easydriver Direction
#define EDSTEP 18     // PIN Easydriver Step

int SMode =8;
int SPosition=0;
int SPitch=5000;
int SDistance=5000;
int SPercent=0;

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, EDSTEP, EDDIR);  //pin 2=step, pin 3=dir
SerialCommand SerialStepper;     // SerialCommand object

void setup() {  
  //Set Pins and baud rate
  Serial.begin(9600);     // open the serial connection usually at 19200bps
  pinMode(EDDIR, OUTPUT); // set pin 12 to output
  pinMode(EDSTEP, OUTPUT); // set pin 12 to output
  
   //Set Serial callback functions
  SerialStepper.addCommand("CPos", StepperPosition);    // Reports or moves motor to position
 }

 
//Stepper Position Callback function used over serial communication, moves to position
void StepperPosition() {
  char *arg;
  arg = SerialStepper.next();     // Get the next argument from the SerialCommand object buffer
  String Cmd=arg;
  if (Cmd != NULL) {               // if a command option was given move to position
     SPercent=Cmd.toInt();
     SPosition= SPercent;//map(SPercent,0,100.0,0,SPitch);
     Serial.print("req:");
     Serial.println(SPosition);
     stepper.moveTo(SPosition);}
   else {
         Serial.print("got:");
         Serial.println(stepper.currentPosition());
   }
}

void loop()
  SerialStepper.readSerial();
  stepper.run();

 

Sandy Noble

unread,
Apr 27, 2013, 6:58:32 AM4/27/13
to accels...@googlegroups.com
Good example - not sure why it's behaving quite that way (perhaps that is a sign of a genuine bug), but I can make it work properly (I think) by explicitly setting a speed in the setup()

  stepper.setMaxSpeed(500);
  stepper.setAcceleration(500);


Maybe that does the trick?  I guess it is stuck on speed 0 otherwise.  But that doesn't explain to me why it does the backwards thing, or the alternate working thing.

sn





 

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Sandy Noble
Reply all
Reply to author
Forward
0 new messages