diff --git a/data/index.html b/data/index.html index 5d9d711..44a9756 100644 --- a/data/index.html +++ b/data/index.html @@ -60,7 +60,7 @@ function action(angle, direction) { clearTimeout(currentTimeout); } - $.post("192.168.1.232/angle", { + $.post("/angle", { angle: angle, }); $("#currentAngle").text("Current Action: " + direction); diff --git a/frank_tank.ino b/frank_tank.ino index 7883cf2..a1ca69c 100644 --- a/frank_tank.ino +++ b/frank_tank.ino @@ -1,10 +1,4 @@ /* - Project made and maintained by Kumar Aditya - - ESP8266 Servo Controller - - Create a ESP8266 Webserver for controlling the real-time position of the servo motor attached to ESP8266. - Change these lines as per yours: const char *ssid = "REPLACE_WITH_YOUR_SSID"; // replace with your SSID const char *password = "REPLACE_WITH_YOUR_PASSWORD"; // replace with your Password @@ -14,12 +8,6 @@ NodeMCU : https://amzn.to/397GzNe - - Servo Motor : - https://amzn.to/2SmyFtJ - - The source code can be found at: - https://git.io/JfOQv Download ESPAsyncWebServer library : https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip @@ -36,22 +24,34 @@ #include #include #include -#include +#include +const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution + +// ULN2003 Motor Driver Pins +#define IN1 5 +#define IN2 4 +#define IN3 14 +#define IN4 12 + +// initialize the stepper library +AccelStepper stepper(AccelStepper::HALF4WIRE, IN1, IN3, IN2, IN4); const char *ssid = "TARDIS"; // replace with your SSID const char *password = "EvangelionUnit-01"; // replace with your Password const uint8_t servoPin = D1; // replace with servo pin -/* Create Servo Object */ -Servo servo; // Create Server instance AsyncWebServer server(80); void setup() { // Attach Servo, start SPIFFS and Connect to WiFi Serial.begin(115200); - servo.attach(servoPin); - servo.write(160); + stepper.setMaxSpeed(2000); + stepper.setAcceleration(500); + // set target position + stepper.moveTo(0); + + if (!SPIFFS.begin()) { Serial.println("An Error has occurred while mounting SPIFFS"); @@ -73,13 +73,31 @@ void setup() Serial.println("Send index.html."); request->send(SPIFFS, "/index.html", "text/html"); }); - // Receive Angle from client and process it - server.on("/angle", HTTP_POST, [](AsyncWebServerRequest *request) { + + /*server.on("/angle", HTTP_POST, [](AsyncWebServerRequest *request) { String angle = request->arg("angle"); Serial.println("Current Position: " + angle + "°"); servo.write(angle.toInt()); request->send(200); + });*/ + server.on("/stop", HTTP_POST, [](AsyncWebServerRequest *request) { + Serial.println("stopping"); + stepper.stop(); + request->send(200); }); + server.on("/cw", HTTP_POST, [](AsyncWebServerRequest *request) { + Serial.println("cw"); + stepper.moveTo(2 * stepsPerRevolution); + request->send(200); + }); + + server.on("/ccw", HTTP_POST, [](AsyncWebServerRequest *request) { + Serial.println("cw"); + stepper.moveTo(- 2 * stepsPerRevolution); + request->send(200); + }); + + // Send Favicon server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico"); // Begin Server @@ -87,4 +105,11 @@ void setup() } void loop() { + stepper.run(); } + + + + + +