From dd4b9cac43a0c0dbc0c531dc89529f3527f213e2 Mon Sep 17 00:00:00 2001 From: JeremyLaurenson Date: Sun, 2 Jun 2024 16:51:18 -0400 Subject: [PATCH] Added Stepper 6600 This adds support for the 6600 stepper controller for example here: https://www.dfrobot.com/product-1547.html --- src/extras/Stepper_TB6600.h | 97 +++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/extras/Stepper_TB6600.h diff --git a/src/extras/Stepper_TB6600.h b/src/extras/Stepper_TB6600.h new file mode 100644 index 0000000..c27463a --- /dev/null +++ b/src/extras/Stepper_TB6600.h @@ -0,0 +1,97 @@ +/********************************************************************************* + * MIT License + * + * Copyright (c) 2023-2024 Jeremy laurenson + * + * https://github.com/HomeSpan/HomeSpan + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ********************************************************************************/ + +#pragma once + +// Implementation of StepperControl for a TB6600 stepper driver +// https://www.dfrobot.com/product-1547.html + +// This implementation uses direction and pulse pins and optinally enable pins only to save pinouts + +////////////////////////// + +struct Stepper_TB6600 : StepperControl { + + int stepPin; + int dirPin; + int enablePin; + +////////////////////////// + + Stepper_TB6600(int stepPin, int dirPin, int enablePin, std::pair taskParams = {1,0}) : StepperControl(taskParams.first,taskParams.second){ + this->stepPin=stepPin; + this->dirPin=dirPin; + this->enablePin=enablePin; + + pinMode(stepPin,OUTPUT); + pinMode(dirPin,OUTPUT); + if(enablePin>0)pinMode(enablePin,OUTPUT); + + setStepType(EIGHTH_STEP); + // FULL_STEP_ONE_PHASE=0, + //FULL_STEP_TWO_PHASE=1, + //HALF_STEP=2, + //QUARTER_STEP=4, + //EIGHTH_STEP=8 + } + +////////////////////////// + + void onStep(boolean direction) override { + digitalWrite(dirPin,direction); + digitalWrite(stepPin,HIGH); + delayMicroseconds(10); // Wait for controller to see this. Min is 2.2uS + digitalWrite(stepPin,LOW); + } + +////////////////////////// + + void onEnable() override { + if(enablePin>0)digitalWrite(enablePin,0); + } + +////////////////////////// + + void onDisable() override { + if(enablePin>0)digitalWrite(enablePin,1); + } + +////////////////////////// + + StepperControl *setStepType(int mode) override { + switch(mode){ + case FULL_STEP_TWO_PHASE: + break; + default: + ESP_LOGE(STEPPER_TAG,"Unknown StepType=%d",mode); + } + return(this); + } + +}; + +//////////////////////////