commit d9b7eebc130c200bb9b650ab0b5177afe45b767b Author: 威勝 張 Date: Fri Apr 19 11:11:09 2024 +0800 up diff --git a/CODE/Arduino_MOTOR_0417/Arduino_MOTOR_0417.ino b/CODE/Arduino_MOTOR_0417/Arduino_MOTOR_0417.ino new file mode 100644 index 0000000..77d7a63 --- /dev/null +++ b/CODE/Arduino_MOTOR_0417/Arduino_MOTOR_0417.ino @@ -0,0 +1,50 @@ + + +bool LEDState = HIGH; +void setup() { + // initialize digital pin LED_BUILTIN as an output. + Serial.begin(115200); + pinMode(13, OUTPUT); + pinMode(12, OUTPUT); + digitalWrite(12, HIGH); +} + + +void motor_run(){ + digitalWrite(12, LOW); // 方向 + for (int i = 0; i < 200; i++) { + digitalWrite(13, HIGH); // 将引脚设置为高电平 + delay(10); // 等待10毫秒 + digitalWrite(13, LOW); // 将引脚设置为低电平 + delay(10); // 等待10毫秒 + } + } +void motor_36_run(){ + digitalWrite(12, LOW); // 方向 + for (int i = 0; i < 20; i++) { + digitalWrite(13, HIGH); // 将引脚设置为高电平 + delay(10); // 等待10毫秒 + digitalWrite(13, LOW); // 将引脚设置为低电平 + delay(10); // 等待10毫秒 + } + + } +// the loop function runs over and over again forever +void loop() { + if (Serial.available() > 0) { // 检查是否有可用的串行数据 + char receivedData[64]; // 用于存储接收到的数据 + int dataSize = Serial.readBytesUntil('\n', receivedData, sizeof(receivedData)); // 读取串行数据直到遇到换行符为止 + receivedData[dataSize] = '\0'; // 添加字符串结束符 + Serial.print("Received: "); // 打印接收到的消息 + Serial.println(receivedData); // 打印接收到的数据 + if(strcmp(receivedData, "move_all") == 0) { + motor_run(); + Serial.println("run_all"); // 打印接收到的数据 + } + if(strcmp(receivedData, "move_36") == 0) { + motor_36_run(); + Serial.println("run_36"); // 打印接收到的数据 + } + } + delay(10); +} diff --git a/CODE/ESP32_MOTOR_com_0417/ESP32_MOTOR_com_0417.ino b/CODE/ESP32_MOTOR_com_0417/ESP32_MOTOR_com_0417.ino new file mode 100644 index 0000000..b70533f --- /dev/null +++ b/CODE/ESP32_MOTOR_com_0417/ESP32_MOTOR_com_0417.ino @@ -0,0 +1,51 @@ +int out_1_pin = 26; +int out_2_pin = 27; + +bool LEDState = HIGH; +void setup() { + // initialize digital pin LED_BUILTIN as an output. + Serial.begin(115200); + pinMode(out_1_pin, OUTPUT); + pinMode(out_2_pin, OUTPUT); + +} + + +void motor_run(){ + digitalWrite(out_1_pin, LOW); // 方向 + for (int i = 0; i < 200; i++) { + digitalWrite(out_2_pin, HIGH); // 将引脚设置为高电平 + delay(10); // 等待10毫秒 + digitalWrite(out_2_pin, LOW); // 将引脚设置为低电平 + delay(10); // 等待10毫秒 + } + } +void motor_36_run(){ + digitalWrite(out_1_pin, LOW); // 方向 + for (int i = 0; i < 20; i++) { + digitalWrite(out_2_pin, HIGH); // 将引脚设置为高电平 + delay(10); // 等待10毫秒 + digitalWrite(out_2_pin, LOW); // 将引脚设置为低电平 + delay(10); // 等待10毫秒 + } + + } +// the loop function runs over and over again forever +void loop() { + if (Serial.available() > 0) { // 检查是否有可用的串行数据 + char receivedData[64]; // 用于存储接收到的数据 + int dataSize = Serial.readBytesUntil('\n', receivedData, sizeof(receivedData)); // 读取串行数据直到遇到换行符为止 + receivedData[dataSize] = '\0'; // 添加字符串结束符 + Serial.print("Received: "); // 打印接收到的消息 + Serial.println(receivedData); // 打印接收到的数据 + if(strcmp(receivedData, "move_all") == 0) { + motor_run(); + Serial.println("run_all"); // 打印接收到的数据 + } + if(strcmp(receivedData, "move_36") == 0) { + motor_36_run(); + Serial.println("run_36"); // 打印接收到的数据 + } + } + delay(10); +} diff --git a/CODE/ESP32_Motor_web_0417/ESP32_Motor_web_0417.ino b/CODE/ESP32_Motor_web_0417/ESP32_Motor_web_0417.ino new file mode 100644 index 0000000..ac98070 --- /dev/null +++ b/CODE/ESP32_Motor_web_0417/ESP32_Motor_web_0417.ino @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include + +int out_1_pin = 26; +int out_2_pin = 27; + +const char *ssid = "leo"; // Put your SSID here +const char *password = "00000000"; +unsigned long previousMillis =0; +unsigned long interval = 30000; + +WebServer server(80); + +//WiFi連線 +void WifiConnecte() { + //Set your Static IP address + IPAddress local_IP(192, 168,1 , 185); + // Set your Gateway IP address + IPAddress gateway(192, 168, 1, 1); + IPAddress subnet(255, 255, 255, 0); + + if (!WiFi.config(local_IP, gateway, subnet)) { + Serial.println("STA Failed to configure"); + } + //開始WiFi連線 + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println("WiFi連線成功"); + Serial.print("IP Address:"); + Serial.println(WiFi.localIP()); + +} +void handleNotFound() { + //digitalWrite(LED,LOW);//LED + String message = "Server is running!\n\n"; + //server.send(200, "text/plain", message); +} + +//Web_chaek +void web_check(void){ + WiFiClient client = server.client(); + String response = "HTTP/1.1 200 OK\r\n"; + response += "Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n"; + server.sendContent(response); +} + +void motor_run(){ + digitalWrite(out_1_pin, LOW); // 方向 + for (int i = 0; i < 200; i++) { + digitalWrite(out_2_pin, HIGH); // 将引脚设置为高电平 + delay(10); // 等待10毫秒 + digitalWrite(out_2_pin, LOW); // 将引脚设置为低电平 + delay(10); // 等待10毫秒 + } + WiFiClient client = server.client(); + server.send(200, "text/plain","run end"); + } + +void motor_36_run(){ + digitalWrite(out_1_pin, LOW); // 方向 + for (int i = 0; i < 20; i++) { + digitalWrite(out_2_pin, HIGH); // 将引脚设置为高电平 + delay(10); // 等待10毫秒 + digitalWrite(out_2_pin, LOW); // 将引脚设置为低电平 + delay(10); // 等待10毫秒 + } + WiFiClient client = server.client(); + server.send(200, "text/plain","run end"); + } +void setup() { + // put your setup code here, to run once: + pinMode(out_1_pin, OUTPUT); + pinMode(out_2_pin, OUTPUT); + Serial.begin(115200); + Serial.println("Hello!"); + WifiConnecte(); + server.on("/motor_run",HTTP_GET,motor_run); + server.on("/motor_36_run",HTTP_GET,motor_36_run); + server.on("/web_check",HTTP_GET,web_check); + server.onNotFound(handleNotFound); + server.begin(); + +} + +void loop() { + // put your main code here, to run repeatedly: + unsigned long currentMills = millis(); + if ((WiFi.status() != WL_CONNECTED)&& (currentMills - previousMillis >= interval)) { + Serial.print(millis()); + Serial.print("wifi正在連線中... "); + WiFi.disconnect();//断开连接 + WiFi.reconnect(); + WifiConnecte(); + } + server.handleClient(); + +} diff --git a/CODE/Python/Motor/Motor_0417.py b/CODE/Python/Motor/Motor_0417.py new file mode 100644 index 0000000..99a9a89 --- /dev/null +++ b/CODE/Python/Motor/Motor_0417.py @@ -0,0 +1,17 @@ +# -*- coding: UTF-8 -*- +import serial, time +import sys +print(sys.getfilesystemencoding()) +#port = '/dev/ttyTHS0' +port = 'COM4' +#ser = serial.Serial(port, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1) +ser = serial.Serial("COM4",115200,bytesize=8, parity='N', stopbits=1, timeout=1) +time.sleep(2) +while True: + + # 向串口发送数据 + command = "move_36" # 发送给Arduino的命令 + ser.write(command.encode()) # 将命令转换为字节并发送到串口 + print(ser.readline()) + time.sleep(2) + diff --git a/PPT/MCU_1.pptx b/PPT/MCU_1.pptx new file mode 100644 index 0000000..157910e Binary files /dev/null and b/PPT/MCU_1.pptx differ