stepper motor instead - GO TO, not speed
This commit is contained in:
parent
57d0aaa6f4
commit
fb216b16fb
@ -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);
|
||||
|
@ -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
|
||||
@ -15,12 +9,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 <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Servo.h>
|
||||
#include <AccelStepper.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user