ESP_IOT v2.5
IOT ESP Coding
ULN2003_StepperClass.cpp
Go to the documentation of this file.
1//
2// ULN2003_StepperClass.cpp
3// ESP_IOT
4//
5// Created by Scott Moody on 8/13/25.
6//
7
9
10
11// from Dispense it calls getFeederType_mainModule()
12//#include "StepperModule.h"
13//! 8.14.25 grabbed our own copy..
14#include "../AtomStepMotor/Stepper.h"
15///#include <Stepper.h>
16
17// Steps per revolution for 28BYJ-48 in half-step mode
18//int _STEPS_PER_REV = 2048;
19
20// M5Atom GPIO pins connected to ULN2003 IN1–IN4
21#define IN1 22
22#define IN2 19
23#define IN3 23
24#define IN4 33
25
26// Create Stepper object
27Stepper *_stepperMotor;//(STEPS_PER_REV, IN1, IN3, IN2, IN4);
28
29
30#ifdef NOT_USED
31//#include "TimerDelayClass.h"
32//! create instance of the timer class
33TimerDelayClass *_timerDelayClass_ULN2003_StepperClass;
34#endif
35
36#ifdef NOT_USED
37//! default .. this could be set via Preferences (TODO)
38float _motorSpeedRPM_ULN2003_Stepper_setting = 0.5;
39#endif
40
41/******************stepper declarations******************************/
42
44{
45 SerialDebug.printf("ULN2003_StepperClass init %s\n", config);
46#ifdef NOT_USED
47 _timerDelayClass_ULN2003_StepperClass = new TimerDelayClass(_motorSpeedRPM_ULN2003_Stepper_setting);
48#endif
49}
50
51
52/************* Set all motor pins off which turns off the motor ************************************************/
53
54//! stop the motor
56{
57 SerialDebug.println("ULN2003_StepperClass::stop_MotorStepper");
58 //! 7.9.25 if the pin was set use it otherwise use the hard coded values
59 //! LOW is off
60// digitalWrite(_pin1, LOW);
61// digitalWrite(_pin2, LOW);
62
63#ifdef NOT_USED
64 //!user timer class instance
65 _timerDelayClass_ULN2003_StepperClass->stopDelay();
66#endif
67}
68
69//! NOTE: this is not right as only 1 instance is around .. so this class cannot be instantiated more than 1 time..
71
72//! These are called from StepperModule
73//!Prepare motor controller
75{
77 return;
78
79 SerialDebug.println("ULN2003_StepperClass::setup_MotorStepper");
80 SerialDebug.printf("PINS = %d, %d, %d, %d\n", IN1, IN3, IN2, IN4);
81
82 //! FIRST: normalize in case use goofed up, especially 0
83 //! grab this value.
85 if (motorSpeedRPM == 0 || motorSpeedRPM > 30)
86 motorSpeedRPM = 15;
87
88 //! grab this value.
90 if (stepsPerRevolution == 0 || stepsPerRevolution > 4000)
91 stepsPerRevolution = 2048;
92
93 SerialDebug.printf("Motor RPM = %d, stepsPerRev = %d\n", motorSpeedRPM, stepsPerRevolution);
94
95 //! create stepper motor
96 _stepperMotor = new Stepper(stepsPerRevolution, IN1, IN3, IN2, IN4);
97
98 //! Set motor speed (RPM)
99 //! 15 is default...
100 _stepperMotor->setSpeed(motorSpeedRPM);
101
102 //! 5.3.25 trying to figure out the PIN use
103 registerPinUse_mainModule(IN1, "IN1", "ULN2003_StepperClass", false);
104 registerPinUse_mainModule(IN2, "IN2", "ULN2003_StepperClass", false);
105 registerPinUse_mainModule(IN3, "IN3", "ULN2003_StepperClass", false);
106 registerPinUse_mainModule(IN4, "IN4", "ULN2003_StepperClass", false);
107
108
110}
111
112//!This will advance the stepper clockwise once by the angle specified in SetupStepper. Example 16 pockets in UNO is 22.5 degrees
113//!This is the FEED message .. the comments mention the Stepper Motor .. which this isn't
115{
116 SerialDebug.println("ULN2003_StepperClass::start_MotorStepper");
118
119 SerialDebug.println("***** ULN2003_StepperClass::Starting ULN2003_Stepper *********");
120
121 //! 5.15.25 try the async CLICK
122 //! click call 5.26.25 SYNC version
124
125#pragma mark NEW_CODE_HERE
126 //Set the four pins to their proper state for the current step in the sequence,
127 //and for the current direction
128
129 int startTime = getTimeStamp_mainModule();
130
131 //! FIRST: normalize in case use goofed up, especially 0
132 //! grab this value.
134 if (motorSpeedRPM == 0 || motorSpeedRPM > 30)
135 motorSpeedRPM = 15;
136
137 //! grab this value.
139 if (stepsPerRevolution == 0 || stepsPerRevolution > 4000)
140 stepsPerRevolution = 2048;
141 SerialDebug.printf("Motor RPM = %d, stepsPerRev = %d\n", motorSpeedRPM, stepsPerRevolution);
142
143 //! create stepper motor
144 //! 8.14.25 Setting the Speed and Steps each time..
145 //! Set motor speed (RPM)
146 //! 15 is default...
147 _stepperMotor->setSpeedSteps(motorSpeedRPM, stepsPerRevolution);
148
149 if (this->isClockwiseDirection())
150 {
151 SerialDebug.println("Rotating one revolution clockwise...");
152 _stepperMotor->step(stepsPerRevolution);
153 }
154 else
155 {
156 SerialDebug.println("Rotating one revolution counterclockwise...");
157 _stepperMotor->step(-stepsPerRevolution);
158 }
159
160 SerialDebug.println("**************** ULN2003_StepperClass::Ending ULN2003_Stepper *************");
161 int endTime = getTimeStamp_mainModule();
162
163 SerialMin.printf("Turn Length: %d seconds \n",endTime - startTime);
164
165}
166
167
168//!loop the PTStepper (so timer can run)
170{
171#ifdef NOT_USED
172
173 //!user timer class instance
174 if (_timerDelayClass_ULN2003_StepperClass->delayFinished())
175 {
176 SerialDebug.println("ULN2003_StepperClass::delayFinished");
177
178 this->stop_MotorStepper();
179 }
180#endif
181}
182
void main_dispatchSyncCommand(int syncCallCommand)
the main sync command (no parameters yet)
void registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
int getTimeStamp_mainModule()
#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_RPM_SETTING
#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING
#define IN4
boolean _isSetup_ULN2003_Stepper
NOTE: this is not right as only 1 instance is around .. so this class cannot be instantiated more tha...
#define IN1
8.14.25 grabbed our own copy..
Stepper * _stepperMotor
#define IN2
#define IN3
An mostly virtual class.
boolean isClockwiseDirection()
returns if clockwise
void setSpeedSteps(long whatSpeed, int number_of_steps)
8.14.25 set speed and number_of_steps
Definition: Stepper.cpp:187
void step(int number_of_steps)
Definition: Stepper.cpp:198
void setSpeed(long whatSpeed)
Definition: Stepper.cpp:175
An concrete class.
boolean delayFinished()
whether the currently delay is finished, false if not running at all
void stopDelay()
stops delay
void stop_MotorStepper()
stops motor
void setup_MotorStepper()
setup the PTStepper
void start_MotorStepper()
starts the PTStepper
ULN2003_StepperClass(char *config)
constructor
void loop_MotorStepper()
loop the PTStepper (so timer can run)