Bonjour, qui peut m'aider a controler un moteur nema 17 avec un lolin wemos d1 mini v4 en wifi
Alimentation 12v
Mp2315
Driver A4988
Bonsoir lolomini1
Que veux tu faire de ton moteur NEMA17, depuis l'interface Web?
Pour le câblage, une petite recherche ![]()
Cordialement
jpbbricole
Je veux controler sa vitesse de rotation
Donc il sera en rotation continue ?
Tu veux que ton Lolin soit un serveur Web autonome ou que ton Lolin se connecte à ton réseau et que tu y accède via ton réseau ?
Le moteur en rotation continue
Le wemos d1 mini a sa propre connexion wifi
Votre autre post identique dans la section en anglais a été déplacé par un modérateur puis clos car doublon de celui ci.
Merci de bien lire et appliquer les recommandations listées dans « Les bonnes pratiques du Forum Francophone”
Bonjour lolomini1
Serais tu intéressé par une interface de ce type?
Programme réalisé avec ChatGPT.
Pour le brochage:
// ------------------- Config A4988 -------------------
#define ENA_PIN D2
#define STEP_PIN D5
#define DIR_PIN D4
Pour connecter le Wifi c'est:
// ------------------- Config WiFi -------------------
const char *ssid = "lolomini1_AP";
const char *password = "12345678";
Une fois connecté au Wifi la page est:
http://192.168.4.1
Adresse par défaut, éventiuellement, regarder dans la console à 115200, l'adresse attribuée:
IP du module : 192.168.4.1
Le programme:
/*
Name: AF_lolomini1_LolinWemosA4988Wifi.ino
Created: 25.08.2025
Author: ChatGPT/jpbbricole
Remarque: Commande d'un moteur pas à pas via une page Web et un A4988
http://192.168.4.1
https://chatgpt.com/share/68ac5fc5-ad08-8013-a34a-a585b7d44a2f
*/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <AccelStepper.h>
// ------------------- Config WiFi -------------------
const char *ssid = "lolomini1_AP";
const char *password = "12345678";
// ------------------- Config A4988 -------------------
#define ENA_PIN D2
#define STEP_PIN D5
#define DIR_PIN D4
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
ESP8266WebServer server(80);
// ------------------- Variables -------------------
int rpm = 100; // valeur initiale (RPM)
int rpmMin = 50; // vitesse min (RPM)
int rpmMax = 200; // vitesse max (RPM)
bool running = false;
int direction = 1; // 1 = CW, -1 = CCW
// ------------------- HTML PAGE -------------------
String getPage()
{
String page = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<title>lolomini1's Nema17 regulator</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Arial; text-align:center; margin:20px; }
h1 { color: #333; }
.slider-container { margin: 20px; }
input[type=range] { width: 60%; }
.btn {
padding: 12px 20px;
margin: 10px;
font-size: 16px;
border: none;
border-radius: 8px;
cursor: pointer;
}
.btn-cw { background-color: #4CAF50; color: white; }
.btn-ccw { background-color: #2196F3; color: white; }
.btn-stop { background-color: #f44336; color: white; }
</style>
</head>
<body>
<h1>lolomini1's Nema17 regulator</h1>
<div class="slider-container">
<label for="speed">Vitesse (RPM): </label>
<input type="range" min=")rawliteral" + String(rpmMin) + R"rawliteral("
max=")rawliteral" + String(rpmMax) + R"rawliteral("
value=")rawliteral" + String(rpm) + R"rawliteral("
id="speed"
oninput="document.getElementById('val').innerHTML=this.value"
onchange="sendSpeed(this.value)">
<span id="val">)rawliteral" + String(rpm) + R"rawliteral(</span>
</div>
<div>
<button class="btn btn-ccw" onclick="sendCmd('CCW')">Marche CCW</button>
<button class="btn btn-stop" onclick="sendCmd('STOP')">STOP</button>
<button class="btn btn-cw" onclick="sendCmd('CW')">Marche CW</button>
</div>
<script>
function sendSpeed(val) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/setSpeed?val=" + val, true);
xhr.send();
}
function sendCmd(cmd) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/cmd?val=" + cmd, true);
xhr.send();
}
</script>
</body>
</html>
)rawliteral";
return page;
}
// ------------------- Routes -------------------
void handleRoot()
{
server.send(200, "text/html", getPage());
}
void handleSetSpeed()
{
if (server.hasArg("val"))
{
rpm = server.arg("val").toInt();
long stepsPerRev = 200; // Nema17 classique
float stepsPerSec = (rpm * stepsPerRev) / 60.0;
stepper.setMaxSpeed(stepsPerSec);
stepper.setSpeed(direction * stepsPerSec);
Serial.printf("Web : setSpeed %d RPM (%f steps/s)\n", rpm, stepsPerSec);
}
server.send(200, "text/plain", "OK");
}
void handleCmd()
{
if (server.hasArg("val"))
{
String cmd = server.arg("val");
if (cmd == "CW")
{
direction = 1;
running = true;
}
else if (cmd == "CCW")
{
direction = -1;
running = true;
}
else if (cmd == "STOP")
{
running = false;
}
Serial.printf("Web : %s\n", cmd.c_str());
}
server.send(200, "text/plain", "OK");
}
// ------------------- Setup -------------------
void setup()
{
Serial.begin(115200);
pinMode(ENA_PIN, OUTPUT);
digitalWrite(ENA_PIN, LOW); // Active le driver (LOW = enabled)
// WiFi AP
WiFi.softAP(ssid, password);
Serial.println("AP Démarré");
Serial.print("IP du module : ");
Serial.println(WiFi.softAPIP());
// Stepper config
stepper.setAcceleration(500);
// vitesse initiale au démarrage
long stepsPerRev = 200;
float stepsPerSec = (rpm * stepsPerRev) / 60.0;
stepper.setMaxSpeed(stepsPerSec);
stepper.setSpeed(direction * stepsPerSec);
Serial.printf("Init : rpm=%d (%f steps/s)\n", rpm, stepsPerSec);
// Routes
server.on("/", handleRoot);
server.on("/setSpeed", handleSetSpeed);
server.on("/cmd", handleCmd);
server.begin();
}
// ------------------- Loop -------------------
void loop()
{
server.handleClient();
if (running)
{
long stepsPerRev = 200;
float stepsPerSec = (rpm * stepsPerRev) / 60.0;
stepper.setSpeed(direction * stepsPerSec);
stepper.runSpeed();
}
}
A ta disposition pour toutes questions ![]()
Dans le moniteur, à 115200, il y a des informations quand au fonctionnement du programme:
Web : CW
Web : CCW
Web : STOP
Web : setSpeed 150 RPM (500.000000 steps/s)
Web : CW
Web : STOP
Web : CCW
C'est testé "en vrai"
A+
jpbbricole
Bonjour jpbbricole ,
Puis je avoir le schéma de raccordement en image svp.
Bonjour lolomini1
Voila le schéma:
J'ai fait l'essai avec un ESP8266 LoLin NodeMcu V3, alimenté en 5V par l'USB
A+
jpbbricole
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.




