seanfhear / IoTea

IoT system for growing a tea plant.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stepper Motor

mmcatcd opened this issue · comments

Background

Mongoose OS has no library for controlling stepper motors so I'll have to write my own.

Stepper motors typically have a number of stators that when activated in a particular order, turn the motor a step.

The stepper motor we have has a control board with an IC that allows for a 5V line to be given and a control pin for each stator that can be connected to input pins on the ESP32 to control it.

Tasks

  • Write a library that controls the stepper motor.

Task Watchdog Timer (TWDT) Problem

One thing I stumbled on when writing the library was the ESP32 Task watchdog timer. It detects tasks that run for a prolonged period with yielding.

Initially I copied the implementation of the stepper motor library as used in the Arduino IDE. However, it loops and delays for a long time, blocking other threads from executing. The TWDT was resetting the ESP32 after 30 seconds.

To solve the problem I used Timers that yield between steps but you can also disable the TWDT in the configuration if needed.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/wdts.html#task-watchdog-timer