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 45 forks source link

Fix restarts on ESP devices #22

Open maxim-kukushkin opened 4 years ago

maxim-kukushkin commented 4 years ago

Addressing #3

The restarts only happen on ESP devices and in case a long rotation is requested. The rotation is done by invocation of step() function in a loop, which ultimately does pin setup and delayMicroseconds. The latter one doesn't return the control back to the system (unlike delay()) sp the entire rotation happens in one solid execution. This is not a problem for an AVR, however on ESP (which has a network stack running in background) long runs without returning control back to the system cause watch dog to kick in and do a soft reset of the device.

In order to prevent such behavior, this PR adds invocation of yield() between performin the motor steps (gives a quick control back to the system).

The motor worked 360 degrees CW and CCW without restart with this change. The rotation speed visually wasn't affected. Returning control to the system is required for a reason, so perhaps there might be situations when the system actually starts doing some work and it will affect the motor performance, but it might be a matter for a bigger change. So far this PR should provide a reasonable relief, so that the library can be used on ESP devices

maxim-kukushkin commented 2 years ago

Any chance for this PR to get reviewed and merged?

maxim-kukushkin commented 2 years ago

@tyhenry, would you be able to have a look at this PR and indicate if it's something that can be merged eventually? If the repo is not maintained any longer, may be a respective note can be added to the Readme.md?