1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我正在尝试使用 NodeMCU 和 NEMA17 电机构建自动电动百叶窗,但是,由于到目前为止我已经烧毁了两个 NodeMCU 板,所以肯定是不对的。该电路会工作一段时间(经常失去 wifi 连接),然后在运行几个小时后它会变热,我无法再使用我的电脑连接到它。
下图显示了我的设置和我用来控制它的代码。有人可以帮助我,如果他们发现我的设置有任何错误,请告诉我吗? 代码:全选/***************************************************** * Date: 9 july 2018 * Written by: Usman Ali Butt * Property off: microcontroller-project.com * ***************************************************/ #include const char* ssid = "MissionControl"; const char* password = "Apollo11"; int Step = 5; //D1 of Nodemcu--Step of stepper motor driver int Dir = 4; //D2---D4 of Nodemcu--Direction of stepper motor driver #define sleepPin 14 //D5 #define M2 12 //D6 #define M1 13 //D7 WiFiServer server(80); void setup() { Serial.begin(115200); delay(10); pinMode(Step, OUTPUT); //Step pin as output pinMode(Dir, OUTPUT); //Direcction pin as output pinMode(sleepPin, OUTPUT); pinMode(M2, OUTPUT); pinMode(M1, OUTPUT); digitalWrite(Step, LOW); // Currently no stepper motor movement digitalWrite(Dir, LOW); digitalWrite(sleepPin, LOW); digitalWrite(M2, HIGH); digitalWrite(M1, HIGH); //digitalWrite(enablePin, LOW); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); // Start the server server.begin(); Serial.println("Server started"); // Print the IP address on serial monitor Serial.print("Use this URL to connect: "); Serial.print("http://"); //URL IP to be typed in mobile/desktop browser Serial.print(WiFi.localIP()); Serial.println("/"); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); while(!client.available()){ delay(1); } // Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); // Match the request int i=0; int value = LOW; if (request.indexOf("/Command=forward") != -1) { //Move 50 steps forward digitalWrite(sleepPin, HIGH); digitalWrite(Dir, HIGH); //Rotate stepper motor in clock wise direction for( i=1;i<=89600;i++){ digitalWrite(Step, HIGH); delay(1); digitalWrite(Step, LOW); delay(1);} value = HIGH; digitalWrite(sleepPin, LOW); } if (request.indexOf("/Command=backward") != -1) { //Move 50 steps backwards digitalWrite(sleepPin, HIGH); digitalWrite(Dir, LOW); //Rotate stepper motor in anti clock wise direction for( i=1;i<=96000;i++){ digitalWrite(Step, HIGH); delay(1); digitalWrite(Step, LOW); delay(1);} value = LOW; digitalWrite(sleepPin, LOW); } // Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println(""); client.println(""); client.println(" Stepper motor controlled over WiFi"); client.print("Stepper motor moving= "); if(value == HIGH) { client.print("Forward"); } else { client.print("Backward"); } client.println(" "); client.println("Forward "); client.println("Backward "); client.println(""); delay(1); Serial.println("Client disonnected"); Serial.println(""); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
358 浏览 0 评论
1202 浏览 1 评论
591浏览 6评论
485浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
468浏览 5评论
467浏览 4评论
445浏览 4评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-31 02:17 , Processed in 0.791110 second(s), Total 76, Slave 60 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号