diff --git a/lib/lib_div/arduino-vid6608/doc/StepperMotor-X27-168v1.fzpz b/lib/lib_div/arduino-vid6608/doc/StepperMotor-X27-168v1.fzpz new file mode 100644 index 000000000..59ce90c2a Binary files /dev/null and b/lib/lib_div/arduino-vid6608/doc/StepperMotor-X27-168v1.fzpz differ diff --git a/lib/lib_div/arduino-vid6608/doc/vid6608-example-sketch.fzz b/lib/lib_div/arduino-vid6608/doc/vid6608-example-sketch.fzz new file mode 100644 index 000000000..bee012275 Binary files /dev/null and b/lib/lib_div/arduino-vid6608/doc/vid6608-example-sketch.fzz differ diff --git a/lib/lib_div/arduino-vid6608/doc/vid6608-example-sketch_bb.png b/lib/lib_div/arduino-vid6608/doc/vid6608-example-sketch_bb.png new file mode 100644 index 000000000..508d7c8d6 Binary files /dev/null and b/lib/lib_div/arduino-vid6608/doc/vid6608-example-sketch_bb.png differ diff --git a/lib/lib_div/arduino-vid6608/library.json b/lib/lib_div/arduino-vid6608/library.json index e2f609302..7df9fa303 100644 --- a/lib/lib_div/arduino-vid6608/library.json +++ b/lib/lib_div/arduino-vid6608/library.json @@ -13,7 +13,7 @@ "email": "petro@petro.ws", "url": "https://petro.ws/" }, - "version": "1.0.2", + "version": "1.0.3", "frameworks": "arduino", "platforms": "*" } diff --git a/lib/lib_div/arduino-vid6608/library.properties b/lib/lib_div/arduino-vid6608/library.properties index 43dcfdb69..4e4952f1c 100644 --- a/lib/lib_div/arduino-vid6608/library.properties +++ b/lib/lib_div/arduino-vid6608/library.properties @@ -1,5 +1,5 @@ name=vid6608 -version=1.0.2 +version=1.0.3 author=Petr Golovachev maintainer=Petr Golovachev sentence=Arduino library for driving IC VID6608 and clones for Switec X25.168 / X27.168 miniature stepper motors diff --git a/lib/lib_div/arduino-vid6608/src/vid6608.cpp b/lib/lib_div/arduino-vid6608/src/vid6608.cpp index 5531d180e..042cdf69b 100644 --- a/lib/lib_div/arduino-vid6608/src/vid6608.cpp +++ b/lib/lib_div/arduino-vid6608/src/vid6608.cpp @@ -48,6 +48,7 @@ vid6608::vid6608(int stepPin, int dirPin, uint16_t maxSteps /*= VID6608_MAX_STEP this->dirPinState = MOVE_NONE; // invalid state to force update on first step this->currentPosition = 0; this->targetPosition = 0; + this->targetPositionNext = 0; this->setAccelTable(defaultAccelTable); // Setup pins pinMode(this->stepPin, OUTPUT); @@ -56,16 +57,19 @@ vid6608::vid6608(int stepPin, int dirPin, uint16_t maxSteps /*= VID6608_MAX_STEP digitalWrite(this->dirPin, LOW); } -void vid6608::zero(uint16_t delay /*= VID6608_DEFAULT_ZERO_SPEED*/) { +void vid6608::zero(uint16_t initialPos /*= VID6608_DEFAULT_MAX_STEPS/2*/, uint16_t delay /*= VID6608_DEFAULT_ZERO_SPEED*/) { // We have to optimize the zeroing process to avoid bouncing on end-stops // Drive makes 1/2 move forward and 1/2 backward to reduce bouncing // This will reduce bouncing, if the last position was not a zero position - uint16_t halfSteps = this->maxSteps / 2; - // Move to halfSteps forward - for (uint16_t x = 0; x < halfSteps; x++) { + if (initialPos >= this->maxSteps) { + initialPos = this->maxSteps - 1; + } + uint16_t stepsForward = this->maxSteps - initialPos; + // Move forward to defined steps count + for (uint16_t x = 0; x < stepsForward; x++) { step(MOVE_FORWARD, delay); } - // Move to halfSteps back + // Move full round back to 0 for (uint16_t x = 0; x < this->maxSteps; x++) { step(MOVE_BACKWARD, delay); } diff --git a/lib/lib_div/arduino-vid6608/src/vid6608.h b/lib/lib_div/arduino-vid6608/src/vid6608.h index a42819366..8f465a540 100644 --- a/lib/lib_div/arduino-vid6608/src/vid6608.h +++ b/lib/lib_div/arduino-vid6608/src/vid6608.h @@ -47,9 +47,10 @@ class vid6608 { * Uses optimized method to reduce bouncing end-stops * @warning this function is blocking, execution is delayed upon done * + * @param initialPos initial position to assume zeroing, default is half of maxSteps. If you know the "old" gauge potision, you can provide it here to avoid end-stop bounce * @param delay single step delay, controls sthe speed of motor, default is deined in VID6608_DEFAULT_ZERO_SPEED */ - void zero(uint16_t delay = VID6608_DEFAULT_ZERO_SPEED); + void zero(uint16_t initialPos = VID6608_DEFAULT_MAX_STEPS/2, uint16_t delay = VID6608_DEFAULT_ZERO_SPEED); /** * @brief Shedules movement to defined absolute position diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 16f5f7b26..c352fdb16 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -1132,6 +1132,7 @@ //#define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code) //#define USE_A4988_STEPPER // Add support for A4988/DRV8825 stepper-motor-driver-circuit (+10k5 code) //#define USE_VID6608 // Add support for VID6608 Automotive analog gauge driver (+0k7 code) +// #define VID6608_RESET_ON_INIT true // Reset VID6608 on init (default: true), change if you control this manually //#define USE_PROMETHEUS // Add support for https://prometheus.io/ metrics exporting over HTTP /metrics endpoint diff --git a/tasmota/tasmota_xdrv_driver/xdrv_92_vid6608.ino b/tasmota/tasmota_xdrv_driver/xdrv_92_vid6608.ino index da4bea59c..71b8fba13 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_92_vid6608.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_92_vid6608.ino @@ -76,6 +76,16 @@ #define VID6608_RTOS #endif +/** + * @brief Reset all drives on init? + * + * Disable if you dont want to perform reset/homing operation on driver init, + * usefull for cases, where you have advanced mode (i.e. use saved values from NVRAM to restore and manual reset). + */ +#ifndef VID6608_RESET_ON_INIT + #define VID6608_RESET_ON_INIT true +#endif + #include "vid6608.h" /** @@ -178,7 +188,7 @@ void CmndGaugeCommand(int32_t command, uint32_t index, int32_t payload) { ResponseAppend_P(PSTR("\"%d\":{"), (int32_t)(x+1)); switch (command) { case GAUGE_ZERO: - driver->zero(); + driver->zero(payload); ResponseAppend_P(PSTR("\"cmd\":\"zero\",\"pos\":0")); break; case GAUGE_SET: @@ -287,8 +297,12 @@ void VID6608Init() { vid6608Drives[x] = new vid6608(pinStep, pinDir); // Perform homing operation - vid6608Drives[x]->zero(); - AddLog(LOG_LEVEL_DEBUG, PSTR("VID: zero %d done"), x); + if (VID6608_RESET_ON_INIT) { + vid6608Drives[x]->zero(); + AddLog(LOG_LEVEL_DEBUG, PSTR("VID: zero %d done"), x); + } else { + AddLog(LOG_LEVEL_DEBUG, PSTR("VID: zero %d skipped"), x); + } vid6608Present = true; } else { vid6608Drives[x] = nullptr;