2022-10-28 05:48:02 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
const uint8_t servoPin = D4; // replace with servo pin
|
|
|
|
|
|
|
|
Parts list:
|
|
|
|
|
|
|
|
NodeMCU :
|
|
|
|
https://amzn.to/397GzNe
|
|
|
|
|
|
|
|
Download ESPAsyncWebServer library :
|
|
|
|
https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
|
|
|
|
|
|
|
|
Download ESPAsyncTCP library :
|
|
|
|
https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip
|
|
|
|
|
|
|
|
Download ESP8266 Filesystem Uploader :
|
|
|
|
https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.5.0/ESP8266FS-0.5.0.zip
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Import libraries
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESPAsyncTCP.h>
|
|
|
|
#include <ESPAsyncWebServer.h>
|
2022-10-28 14:39:18 +00:00
|
|
|
#include <AccelStepper.h>
|
2022-11-01 05:08:29 +00:00
|
|
|
#include <string>
|
2022-10-28 14:39:18 +00:00
|
|
|
|
|
|
|
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
|
2022-11-01 05:08:29 +00:00
|
|
|
bool initializing = false;
|
2022-10-28 05:48:02 +00:00
|
|
|
|
2022-10-28 14:39:18 +00:00
|
|
|
// 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);
|
2022-10-28 05:48:02 +00:00
|
|
|
|
|
|
|
const char *ssid = "TARDIS"; // replace with your SSID
|
|
|
|
const char *password = "EvangelionUnit-01"; // replace with your Password
|
2022-11-01 05:08:29 +00:00
|
|
|
|
2022-10-28 05:48:02 +00:00
|
|
|
// Create Server instance
|
|
|
|
AsyncWebServer server(80);
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
// Attach Servo, start SPIFFS and Connect to WiFi
|
|
|
|
Serial.begin(115200);
|
2022-11-01 05:08:29 +00:00
|
|
|
stepper.setMaxSpeed(3000);
|
|
|
|
stepper.setAcceleration(2500);
|
2022-10-28 14:39:18 +00:00
|
|
|
// set target position
|
|
|
|
stepper.moveTo(0);
|
|
|
|
|
|
|
|
|
2022-10-28 05:48:02 +00:00
|
|
|
if (!SPIFFS.begin())
|
|
|
|
{
|
|
|
|
Serial.println("An Error has occurred while mounting SPIFFS");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
Serial.print("Connecting to WiFi..");
|
|
|
|
while (WiFi.status() != WL_CONNECTED)
|
|
|
|
{
|
|
|
|
delay(1000);
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
|
|
|
Serial.print("\nConnected to the WiFi network: ");
|
|
|
|
Serial.print(WiFi.SSID());
|
|
|
|
Serial.print("IP address:");
|
|
|
|
Serial.print(WiFi.localIP());
|
|
|
|
// Send home page from SPIFFS
|
|
|
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
|
|
|
Serial.println("Send index.html.");
|
|
|
|
request->send(SPIFFS, "/index.html", "text/html");
|
|
|
|
});
|
2022-10-28 14:39:18 +00:00
|
|
|
|
2022-11-01 05:08:29 +00:00
|
|
|
|
|
|
|
server.on("/setTemperature", HTTP_POST, [](AsyncWebServerRequest *request) {
|
|
|
|
int rotations = request->arg("rotations").toInt();
|
|
|
|
double multiplier = 0.2; // TODO: find me out
|
|
|
|
stepper.moveTo((multiplier * rotations) * stepsPerRevolution);
|
2022-10-28 14:39:18 +00:00
|
|
|
request->send(200);
|
|
|
|
});
|
|
|
|
|
2022-11-01 05:08:29 +00:00
|
|
|
|
|
|
|
//rotate a looot back to 90 F, as we cant go lower, so we over rotate then mark that as 0 POSITION
|
|
|
|
server.on("/initialize", HTTP_POST, [](AsyncWebServerRequest *request) {
|
|
|
|
initializing = true;
|
|
|
|
stepper.moveTo(-10 * stepsPerRevolution);
|
2022-10-28 14:39:18 +00:00
|
|
|
request->send(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-10-28 05:48:02 +00:00
|
|
|
// Send Favicon
|
|
|
|
server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico");
|
|
|
|
// Begin Server
|
|
|
|
server.begin();
|
|
|
|
}
|
2022-11-01 05:08:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-28 05:48:02 +00:00
|
|
|
void loop()
|
|
|
|
{
|
2022-11-01 05:08:29 +00:00
|
|
|
if (stepper.distanceToGo() == 0 && initializing){
|
|
|
|
initializing = false;
|
|
|
|
stepper.stop();
|
|
|
|
stepper.setCurrentPosition(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.print("Current Position: ");
|
|
|
|
Serial.println(stepper.currentPosition());
|
2022-10-28 14:39:18 +00:00
|
|
|
stepper.run();
|
2022-10-28 05:48:02 +00:00
|
|
|
}
|