AccelStepper.currentPosition question

3,387 views
Skip to first unread message

FredB

unread,
Aug 3, 2017, 5:44:24 AM8/3/17
to accelstepper
Hi All,

I'm fairly new to the arduino platform and the accelStepper library.

My question is, (for debug reasons and to see if it can be done :-)) can accelStepper.currentPosition be used to output where the stepper thinks it is?

A section of code that has not yet been tested;

#include <Wire.h>
#include <AccelStepper.h>
#define HALFSTEP 8
#define D6T_addr 0x0A
#define D6T_cmd 0x4C

// Motor pin definitions
#define motorPin1  1     // IN1 on the ULN2003 driver 1
#define motorPin2  2     // IN2 on the ULN2003 driver 1
#define motorPin3  3     // IN3 on the ULN2003 driver 1
#define motorPin4  4     // IN4 on the ULN2003 driver 1

byte rbuf[19];
float temp[9]; // amb + 8 temp_readings
float temp2[9]; // amb + 8 temp_readings to compare with the values in temp
boolean bodyPresent = 0;// boolean to indicate if body is sensed by the DT6 sensor. 1 = body present
const int SWITCH = 22; // input pin for home position indicator
int homeFlag = 0;
int ledPins [] = {5,6,7,8,9,10,11,12}; //array of output pins for leds
long Position = 0;
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);


void setup()
{
  stepper1.setMaxSpeed(2000.0);
  stepper1.setAcceleration(800.0);
  stepper1.setSpeed(500);
  stepper1.moveTo(5000);// need to adjust this empirically
  Wire.begin();
  Serial.begin(9600); //
  pinMode (homeFlag, INPUT);
  for(int index = 0; index < 8; index ++)
  {
  pinMode(ledPins[index], OUTPUT); //declare LED as output
  }
 
// Initialise flag position
  //if the flag is not up, drive it until the homeFlag = HIGH
  homeFlag = digitalRead (SWITCH);
  if (homeFlag == LOW)
  {
    while (homeFlag == LOW){
      stepper1.run();
    }
    stepper1.stop();
    Position = stepper1.currentPosition; // debug this line to print the motor position.
                                                         // this line generates the following  compiler error " error: cannot convert 'AccelStepper::currentPosition' from type 'long int (AccelStepper::)()' to type 'long int'


    Serial.print (Position);
    Serial.println ();
    stepper1.setSpeed (500);
}

Any help and comments greatly received :-)

gregor christandl

unread,
Aug 3, 2017, 5:52:33 AM8/3/17
to accelstepper
Hi,
currentPosition is a function, not a variable. The correct call is:

Position = stepper1.currentPosition();


--
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/d/optout.

FredB

unread,
Aug 15, 2017, 4:22:54 AM8/15/17
to accelstepper
Many thanks for your help Gregor

Paulo Silva

unread,
Aug 25, 2017, 12:50:27 PM8/25/17
to accelstepper
i also use currentPosition but it runs slower, very slow in did, why? 1/10 of the speed
Reply all
Reply to author
Forward
0 new messages