ESP_IOT v2.5
IOT ESP Coding
HDriverStepperClass.cpp
Go to the documentation of this file.
1//! \link HDriverStepperStepperClass
2// HDriverStepperStepperClass.cpp
3//
4//
5// Created by Scott Moody on 3/24/25.
6//
7
9
10// from Dispense it calls getFeederType_mainModule()
11#include "StepperModule.h"
12
13//#include "TimerDelayClass.h"
14//! create instance of the timer class
16
17//! default .. this could be set via Preferences (TODO)
19
20/******************stepper declarations******************************/
21
23{
24 SerialDebug.printf("HDriverStepperClass init %s\n", config);
26
27}
28
29//! This works with the ESP_M5
30
31const int IN1_PIN = 19;
32const int IN2_PIN = 23;
37int VIN_PIN = 33;
38int FAULT_PIN = 22;
39
40//https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
41
42#define NUM_PINS 2
43////Put all the pins in an array to make them easy to work with
45 IN1_PIN, //IN1 on the ULN2003 Board, BLUE end of the Blue/Yellow motor coil
46 IN2_PIN //IN2 on the ULN2003 Board, PINK end of the Pink/Orange motor coil
47};
48
49/************* Set all motor pins off which turns off the motor ************************************************/
51{
52#ifdef NOT_USED_FOR_H_DRIVER
53 for (int pin = 0; pin < NUM_PINS; pin++)
54 {
55 pinMode(_pins_HDriverStepperClass[pin], OUTPUT);
56 digitalWrite(_pins_HDriverStepperClass[pin], LOW);
57 }
58#endif
59}
60
61
62//! stop the motor
64{
65 SerialDebug.println("HDriverStepperClass::stop_MotorStepper");
66
67 //M5.dis.drawpix(0, 0x000000);
68 ledcWrite(_ledChannel1_HDriverStepper, 0);
69 ledcWrite(_ledChannel2_HDriverStepper, 0);
70
71 //!user timer class instance
73}
74
76//! These are called from StepperModule
77//!Prepare motor controller
79{
80 SerialDebug.println("HDriverStepperClass::setup_MotorStepper");
81
82 //! 5.3.25 trying to figure out the PIN use
83 registerPinUse_mainModule(IN1_PIN, "IN1_PIN", "HDriverStepperClass", false);
84 registerPinUse_mainModule(IN2_PIN, "IN2_PIN", "HDriverStepperClass", false);
85 registerPinUse_mainModule(VIN_PIN, "VIN_PIN", "HDriverStepperClass", false);
86 registerPinUse_mainModule(FAULT_PIN, "FAULT_PIN", "HDriverStepperClass", false);
87
88#define NOT_TRY_ON_FIRST_FEED
89#ifdef NOT_TRY_ON_FIRST_FEED
94 pinMode(VIN_PIN, INPUT);
95 pinMode(FAULT_PIN, INPUT);
97#endif
98 //clearPins_HDriverStepper(); // Go turn all motor pins off
99}
100
101#ifdef NOT_TRY_ON_FIRST_FEED
102#else
103//! 3.26.25 try to only setup on the first feed
104void setup_again()
105{
107 {
111 ledcAttachPin(IN1_PIN, _ledChannel1_HDriverStepper);
112 ledcAttachPin(IN2_PIN, _ledChannel2_HDriverStepper);
113 pinMode(VIN_PIN, INPUT);
114 pinMode(FAULT_PIN, INPUT);
115 }
116}
117#endif
118//!This will advance the stepper clockwise once by the angle specified in SetupStepper. Example 16 pockets in UNO is 22.5 degrees
119//!This is the FEED message .. the comments mention the Stepper Motor .. which this isn't
121{
122 SerialDebug.println("HDriverStepperClass::start_MotorStepper");
123
124#ifdef NOT_TRY_ON_FIRST_FEED
125#else
126 //! 3.26.25 try to only setup on the first feed
127 setup_again();
128#endif
129
130
131 SerialDebug.println("**************** HDriverStepperStepper::Starting HDriverStepper *******************");
132 //! 5.15.25 try the async CLICK
133 //! click call 5.26.25 SYNC version
135
136#define NEW_CODE_HERE
137 //Set the four pins to their proper state for the current step in the sequence,
138 //and for the current direction
139
140 if (this->isClockwiseDirection()) {
141 //M5.dis.drawpix(0, 0x0000f0);
142 ledcWrite(_ledChannel1_HDriverStepper, 1000);
143 ledcWrite(_ledChannel2_HDriverStepper, 0);
144 } else {
145 //M5.dis.drawpix(0, 0xff00f0);
146 ledcWrite(_ledChannel1_HDriverStepper, 0);
147 ledcWrite(_ledChannel2_HDriverStepper, 1000);
148 }
149
150 //! grab this value.
152
153 //! start the delay.. (which at .5 might not be needed...)
155
156 SerialDebug.println("**************** HDriverStepperStepper::Ending HDriverStepper *************");
157
158}
159
160
161//!loop the PTStepper (so timer can run)
163{
164 //!user timer class instance
166 {
167 SerialDebug.println("HDriverStepperClass::delayFinished");
168
169 this->stop_MotorStepper();
170 }
171
172}
const int IN1_PIN
This works with the ESP_M5.
float _delaySeconds_HDriverStepper_setting
default .. this could be set via Preferences (TODO)
int FAULT_PIN
void clearPins_HDriverStepper()
int _resolution_HDriverStepper
#define NUM_PINS
int VIN_PIN
int _freq_HDriverStepper
int _ledChannel1_HDriverStepper
boolean _isSetup_HDriverStepper
int _ledChannel2_HDriverStepper
TimerDelayClass * _timerDelayClass_HDriverStepperClass
HDriverStepperStepperClass
const int IN2_PIN
int _pins_HDriverStepperClass[NUM_PINS]
void main_dispatchSyncCommand(int syncCallCommand)
the main sync command (no parameters yet)
void registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
#define SYNC_CLICK_SOUND
Definition: MainModule.h:258
float getPreferenceFloat_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING
void setup_MotorStepper()
setup the PTStepper
HDriverStepperClass(char *config)
constructor
void start_MotorStepper()
starts the PTStepper
void stop_MotorStepper()
stops motor
void loop_MotorStepper()
loop the PTStepper (so timer can run)
An mostly virtual class.
boolean isClockwiseDirection()
returns if clockwise
An concrete class.
void startDelay(float delayAmountSeconds)
starts delay calculation
boolean delayFinished()
whether the currently delay is finished, false if not running at all
void stopDelay()
stops delay