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
89 //! 6.5.26
90 //! @see https://docs.espressif.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html#ledc
91 //! ledcSetup and ledcAttachPin removed ..
92#ifdef M5UNIFIED
95#else
100#endif
101 pinMode(VIN_PIN, INPUT);
102 pinMode(FAULT_PIN, INPUT);
104 //clearPins_HDriverStepper(); // Go turn all motor pins off
105}
106
107
108//!This will advance the stepper clockwise once by the angle specified in SetupStepper. Example 16 pockets in UNO is 22.5 degrees
109//!This is the FEED message .. the comments mention the Stepper Motor .. which this isn't
111{
112 SerialDebug.println("**************** HDriverStepperStepper::Starting HDriverStepper *******************");
113 //! 5.15.25 try the async CLICK
114 //! click call 5.26.25 SYNC version
116
117#define NEW_CODE_HERE
118 //Set the four pins to their proper state for the current step in the sequence,
119 //and for the current direction
120
121 if (this->isClockwiseDirection()) {
122 //M5.dis.drawpix(0, 0x0000f0);
123 ledcWrite(_ledChannel1_HDriverStepper, 1000);
124 ledcWrite(_ledChannel2_HDriverStepper, 0);
125 } else {
126 //M5.dis.drawpix(0, 0xff00f0);
127 ledcWrite(_ledChannel1_HDriverStepper, 0);
128 ledcWrite(_ledChannel2_HDriverStepper, 1000);
129 }
130
131 //! grab this value.
133
134 //! start the delay.. (which at .5 might not be needed...)
136
137 SerialDebug.println("**************** HDriverStepperStepper::Ending HDriverStepper *************");
138
139}
140
141
142//!loop the PTStepper (so timer can run)
144{
145 //!user timer class instance
147 {
148 SerialDebug.println("HDriverStepperClass::delayFinished");
149
150 this->stop_MotorStepper();
151 }
152
153}
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]
boolean registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
void main_dispatchSyncCommand(int syncCallCommand)
the main sync command (no parameters yet)
#define SYNC_CLICK_SOUND
Definition: MainModule.h:268
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