Last week I bricked a4988, so ordered DRV8825 this time.
Goal: To spin the Nema 17 using Wifi
I used the article
http://electrica.uc3m.es/grobles/blog/?p=1384
The only changes - supplying 5v into Vin and usage of D3, D4 instead of D1 and D2 for step and direction.
12V with 2.5A is the power source for DRV8825. and using a buck boost converter to get 5V to supply for NodeMcu, reset, sleep.
Ground from mains is supplied to buck boost and ground pin of DRV is connected to NodeMcu too.
[ 100microF capacitor is used at VMOT]
using board - NodeMcu 1.0 [ESP 12E Module]
Problems: Motor not spinning, I occasionally herd small sound from Nema 17, and also the heat sik on DEV is damn hot.
Please can you tell me what could be the problem? and how to spin my Nema 17 stepper
Code:
#include <ESP8266WiFi.h> //I can connect to a Wifi
#include <ESP8266WebServer.h> //I can be a server 'cos I have the class ESP8266WebServer available
#include <WiFiClient.h>
const char* ssid =
const char* password =
ESP8266WebServer server(80); //Global object variable from the class ESP8266WebServer so we will be able to access it in our functions
//As argument for the constructor of this class, we will pass the port where the server will be listening to.
//Since 80 is the default port for HTTP, we will use this value, so we will not need to specify it in the URL
//when accessing to our ESP8266 server using a browser.
#define DIR_PIN D3
#define STEP_PIN D4
//const int dirPin = 5; //This pin corresponds to GPIO5 (D1) (Yellow wire) https://nodemcu.readthedocs.io/en/latest/en/modules/gpio/
//const int stepPin = 4; //This pin corresponds to GPIO4 (D2) (Orange wire)
int steps = 0; //This variable is related to the number of turns. If microstepping is disabled, 200 corresponds to a complete turn.
int stepDelay = 0; //This variable is the pulse duration in milliseconds and it is related to the rotation speed. Without microstepping, 1.8ยบ are stepDelay ms.
bool dir = HIGH; //Rotation direction. HIGH is clockwise.
void setup() {
pinMode(DIR_PIN, OUTPUT); // Pins are outputs
pinMode(STEP_PIN, OUTPUT);
delay(1000);
Serial.begin(115200); //I can debbug through the serial port
// Configure NODEMCU as Access Point
Serial.println("Configuring access point...");
WiFi.softAP(ssid); //Password is not necessary
IPAddress myIP = WiFi.softAPIP(); //Get the IP assigned to itself.
Serial.print("AP IP address: "); //This is written in the PC console.
Serial.println(myIP);
server.on("/", handleRootPath); //I specify which code to execute when an HTTP request is performed to each path.
//To do so, we call the on method on our previously declared server global object.
//The most elegant method consists on defining a handling function somewhere in our code and passing it to the
//on function alongside the URL that will trigger the execution of that function.
//This line indicates that when an HTTP request is received on the root ("/") path,
//it will trigger the execution of the handleRootPath function
server.on("/Init", handleInit); //Associate the handler function to the path "/Init".
server.begin(); //Let's call the begin method on the server object to start the server.
Serial.println("HTTP server started");
}
void loop() {
server.handleClient(); //To handle the actual incoming of HTTP requests, we need to call the handleClient method on the server object, on the main loop function.
}
void handleRootPath() {
server.send(200, "text/plain", "Ready, NodeMcu.");
//To define an answer to a request, I call the send method on the server object.
//Although the method can be called with a different set of arguments, its simplest form consists on receiving
//the HTTP response code (200 = OK), the content type and the content.
}
void handleInit() {// Handler. 192.168.XXX.XXX/c (One turn clockwise in one second)
//Check this https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp#L365
steps = 0; //Motor stopped if the arguments are wrong.
stepDelay = 0;
String message = "Initialization with: ";
if (server.hasArg("Dir")) {
digitalWrite(DIR_PIN, server.arg("Dir") == "HIGH"); //This is a cunning way of checking the value of the argument Dir.
message += "Direction: ";
message += server.arg("Dir");
}
if (server.hasArg("Delay")) {
stepDelay = (server.arg("Delay")).toInt(); //Converts the string to integer.
message += " Delay: ";
message += server.arg("Delay");
}
if (server.hasArg("Steps")) {
steps = (server.arg("Steps")).toInt();
message += " Steps: ";
message += server.arg("Steps");
}
server.send(200, "text/plain", message); //It's better to return something so the browser don't get frustrated+
for (int i = 0; i < steps; i++) { //Create a square wave signal with the incoming data.
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(stepDelay);
yield();
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(stepDelay);
server.send(200, "text/plain", "count: "+i);
}
}