Replies: 4 comments 4 replies
-
Hi @anjanbabu - I didn't get notified about your topic (d'oh!).
Ok, but you successfully got the code to compile without any changes? If so, then we can sort this out. In the root level of the project (not buried in any sub-folder) you'll find a file called That file looks like this: ; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
description = IoT controlled smart watch winder
[env:esp32doit-devkit-v1]
platform = espressif32@^5.2.0
board = esp32doit-devkit-v1
framework = arduino
upload_speed = 115200
monitor_speed = 115200
build_src_filter = +<*> -<./angular/>
board_build.filesystem = littlefs
check_tool = cppcheck, clangtidy
build_flags =
-D OLED_ENABLED=false
-D PWM_MOTOR_CONTROL=false
check_flags =
clangtidy: -fix-errors,--format-style=google
lib_deps =
esphome/AsyncTCP-esphome@^1.2.2
esphome/ESPAsyncWebServer-esphome@^2.1.0
Wire
https://github.com/tzapu/WiFiManager.git
https://github.com/bblanchon/ArduinoJson.git
fbiego/ESP32Time@^2.0.0
adafruit/Adafruit SSD1306@^2.5.9
electromagus/ESPMX1508@^1.0.5 There's a line in this file: -D PWM_MOTOR_CONTROL=false Change the value |
Beta Was this translation helpful? Give feedback.
-
As for converting the You'd need to modify this line to reference your 4 pins for the stepper motor controller board: The result would be something like: # main.cpp
int pinA = 25;
int pinB = 26;
int pinC = 27;
int pinD = 28;
...
...
...
#if PWM_MOTOR_CONTROL # < -- we're relying on you setting the build flag I talked about in the first reply, above!
MotorControl motor(pinA, pinB, pinC, pinD);
#else
MotorControl motor(directionalPinA, directionalPinB);
#endif
...
... And in the # src/platformio/osww-server/src/utils/MotorControl.cpp
#include "MotorControl.h"
#include <Arduino.h>
#include <Stepper.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#define STEPS_PER_REVOLUTION 2048 // Number of steps per revolution for 28BYJ-48
// Global variables for task control
int8_t _motorDirection = 2; // 0 for counterclockwise, 1 for clockwise, 2 to stop
int numSteps = 100; // Number of steps to move (can be adjusted)
int stepSpeed = 10; // Motor speed in RPM
MotorControl::MotorControl(int pinA, int pinB, int pinC, int pinD)
: _stepper(STEPS_PER_REVOLUTION, pinA, pinB, pinC, pinD) // Initialize Stepper object
{
// Set default motor speed
_stepper.setSpeed(stepSpeed);
}
void MotorControl::clockwise()
{
_motorDirection = 0; // Set global direction to clockwise
Serial.println("[STATUS] - Motor turning clockwise");
}
void MotorControl::countClockwise()
{
_motorDirection = -1; // Set global direction to counterclockwise
Serial.println("[STATUS] - Motor turning counterclockwise");
}
void MotorControl::stop()
{
_motorDirection = 2; // Set global direction to stop
Serial.println("[STATUS] - Motor stopped");
}
// FreeRTOS task to handle motor movement
void motorTask(void *parameter)
{
MotorControl *motor = (MotorControl *)parameter;
while (true)
{
if (_motorDirection != 2)
{
// Move motor in the specified direction
motor->moveSteps(_motorDirection * numSteps);
}
else
{
// If _motorDirection is 0, stop the motor
motor->stop();
vTaskDelay(100 / portTICK_PERIOD_MS); // Check again after 100ms
}
}
}
void MotorControl::determineMotorDirectionAndBegin()
{
// Create the FreeRTOS task for motor control
xTaskCreate(motorTask, "Motor Task", 2048, this, 1, NULL);
}
void MotorControl::moveSteps(int steps)
{
_stepper.step(steps); // Move the motor by the specified number of steps
}
int MotorControl::getMotorDirection()
{
return _motorDirection;
}
void MotorControl::setMotorDirection(int direction)
{
_motorDirection = direction;
}
void MotorControl::setSpeed(int speed)
{
stepSpeed = speed;
_stepper.setSpeed(speed);
} I don't have any of the equipment on hand to test, but I think that's pretty much it. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the guidance via the Reddit post, but I’m having issues with getting this to work. I also tried the ChatGPT request to create the header file, but still getting errors. I do appreciate all of your help thus far. |
Beta Was this translation helpful? Give feedback.
-
Chat GPT gives this: #ifndef MOTORCONTROL_H #define MOTORCONTROL_H #include <Arduino.h> // Define the number of steps per revolution for 28BYJ-48 class MotorControl {
private:
}; #endif // MOTORCONTROL_H |
Beta Was this translation helpful? Give feedback.
-
This is an amazing project! love that it has a phone UI and OLED support!
I see a lot of DIY watch winders use small stepper motors like the 28BYJ-48 unipolar stepper motor with the ULN2003 motor driver, it would be nice if you could enable the Winderoo code to work with these motors as well since they're so cheap and accessible. These fancy 3D printable gyro winders also use the same motors.
I did attempt to modify the code as suggested by an ESP32 forum user, but I'm an ultra noob and I could not wrap my head around switching the PWM motor control code to a stepper motor one.
Beta Was this translation helpful? Give feedback.
All reactions