tyhenry / CheapStepper

Arduino library for the cheap but decent 28BYJ-48 5v stepper motor with ULN2003 board
GNU General Public License v3.0
122 stars 46 forks source link

Reset position to 0 #7

Closed ChazSingh closed 6 years ago

ChazSingh commented 6 years ago

Hi Great work on CheapStepper. I am using it in a project and it is working well I would be grateful if you could help with the following please; When I power up the project I have the stepper set a dial to to the zero position using a sensor. Before I power on the dial could be in any position. Unfortunately for other reasons cannot set this position to zero at power down. What I would like to do is once I have reached this zero position is to set the position in CheapStepper as zero so if I say move to position 2048 it rotates the dial halfway (180 degrees) My problem is that CheapStepper effectively sets position zero at power on and I would like to set this at any point in my sketch. What would be great is a command like stepper.(resetposition(0)) Which would set it to zero or any other value entered without moving the stepper. If I then used the command Serial.print(stepper1.getStep()) it would tell me the position is to the value I'd set. They may already be a way to do this but I am struggling to find it. Any help would be most appreciated. Thank you Charin

tyhenry commented 6 years ago

Hi - good idea, but unfortunately the limitation here is the hardware, since you can't read position from a stepper motor, only move it and record the relative change over time.

You would need to add an extra sensor and use a sensor library to gauge the absolute position.

You could potentially use a rotary encoder, a la this tutorial.

Alternatively you may be able to store the last stepper position into EEPROM storage which is saved after the power is cut.