Skip to content

"Centering" the stepper motor #16

@drp0

Description

@drp0

I wanted to set the start position of the stepper and attached an opto sensor to allow the stepper motor to be moved until a hole in a rotated cardboard disc, caused the opto to read Low.
This all went to plan until I realised that the library initialised its position from the first call to CheapStepper stepper (8,9,10,11) .
I realised I needed a new library call (stepReset) to set stepN = 0 and hence establish a new base position.

void CheapStepper::stepReset(){

      stepN = 0; 
}

This works well.

My centering code;


byte a =  digitalRead(12);  // opto sensor on pin 12
  if(a==1){
  Serial.println("Centering..");
    while(a == 1){
    stepper.move (moveClockwise, 1);
    a = digitalRead(12);
    }
  stepper.stepReset(); // reset position count
  Serial.println("Centred"); Serial.flush();
  stepper.newMove(moveClockwise, 0); // fixes a restart issue
  }

Others may find this useful,

David

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions