Using SpeedyStepper position and set home

Hello - I am building a HVAC vent controller and I am using SpeedyStepper to control the stepper motors. I am reasonably new to coding. I have pulled out a small piece of code to limit the code amount to try and resolve why I am unable to set the current position, move the motor and then get the new motor position. Code shown just prints value of position. I plan to use move to commands once I can reliably know the current position of the stepper after moves.

I'd like to use set current position and get current position functions that as far as I see exist in SpeedyStepper. Any help will be appreciated. I've try many combinations and placement for the code without any success.

The code complies and uploads fine, it's the output that doesn't provide a new location for the stepper.

I read thru the rules and methods to ask a question. Hopefully, I have adhered to the rules of the forum and provided what is needed for some help. If i haven't then the feedback that i haven't is welcome to so I can improve that too.

Thanks

// **************************************************

#include <SpeedyStepper.h>

const int LED_PIN = 13;
const int MOTOR_STEP_PIN = 11;
const int MOTOR_DIRECTION_PIN = 10;
long currentPosition_InSteps;

SpeedyStepper stepper;

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);

  setCurrentPositionInSteps(8);

  stepper.connectToPins(MOTOR_STEP_PIN, MOTOR_DIRECTION_PIN);
}

// ================----------------------===================

void loop()
{
  stepper.setSpeedInStepsPerSecond(100);
  stepper.setAccelerationInStepsPerSecondPerSecond(100);

  Serial.print("Current Steps   ");
  Serial.println(currentPosition_InSteps);

  getCurrentPositionInSteps();

  stepper.moveRelativeInSteps(200);

  delay(1000);

  stepper.moveRelativeInSteps(-125);
  delay(1000);

  stepper.setSpeedInStepsPerSecond(500);
  stepper.setAccelerationInStepsPerSecondPerSecond(500);
  stepper.moveRelativeInSteps(200 * 5);
  delay(2000);
}

//==============================================

void setCurrentPositionInSteps(long currentPositionInSteps)
{
  currentPosition_InSteps = currentPositionInSteps;
}

// ==============================================

void getCurrentPositionInSteps()
{
  return (currentPosition_InSteps);
}

What do the serial prints show?

Current Steps 8
Current Steps 8
Current Steps 8
...

Repeating each time program executes the loop

why I'm unable to set the home-position.
Do you have a home-position-sensor?

I'd like to use these functions that as far as I see exist in SpeedyStepper

all functions that "exist in" speedystepper would be called by the dot-notation

example

stepper.moveRelativeInSteps(-125);

uses the function with name "moveRelativeInSteps" inside the stepper-object.

If you define some functions like

void setCurrentPositionInSteps(long currentPositionInSteps)
{
  currentPosition_InSteps = currentPositionInSteps;
}

// ==============================================

void getCurrentPositionInSteps()
{
  return (currentPosition_InSteps);
}

They have absolutely nothing to do with the stepper-internal functions.

You have to lookup what functions the SpeedyStepper-library offers.
and then use them it the dot-notation
stepper-dot-functionname
examples

stepper.connectToPins()
stepper.setSpeedInStepsPerSecond()
stepper.setAccelerationInStepsPerSecondPerSecond()
stepper.moveRelativeInSteps()

best regards Stefan

Thanks, I think I understand what you are saying. I have used the

stepper.connectToPins()
stepper.setSpeedInStepsPerSecond()
stepper.setAccelerationInStepsPerSecondPerSecond()
stepper.moveRelativeInSteps()

commands successfully. I just can't get the getCurrentPositionInSteps nor the setCurrentPositionInSteps to work.

I am thinking I can set a location then move using the any of the step move commands that exist in SpeedyStepper and be able to then ask for current position. I know it's not current position from the motors viewpoint rather it is the current position based on whatever commands were sent to driver using the commands within SpeedyStepper. I think it should be keeping track of the math basically from what I see.

After every move:

Serial.println(stepper.getCurrentPositionInSteps());

Like:

stepper.moveRelativeInSteps(200);
Serial.println(stepper.getCurrentPositionInSteps());

Thanks all -

I took both of your advices and was able to get some numbers back.

Super cool.

Not sure, well actually I am very sure I don't thoroughly understand it yet, but I'm gaining on it.

Thanks for helping move forward.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.