找到arduino 資料夾 libraries 貼上 ServoESP32-master 資料夾 便可
解壓檔案
開啟監控視窗
輸入 1 或 2 ,步進馬達就會轉180度
注意!

影片
伺服馬達接線圖


黃線 接 GPIO27 、 紅線 接 5V 、 黑線 接 GND
ESP32 電力只能推動一個馬達,若是要鞭策兩個馬達就要外接電源了
程式碼
- #include <Servo.h>
- Servo myservo; // 建立伺服馬達節制
-
- // 伺服馬達的連接 GPIO
- static const int servoPin = 27;
- int pos = 0;
- void setup() {
- // put your setup code here, to run once:
- myservo.attach(servoPin); // 將伺服馬達毗連的GPIO pin連接伺服物件
- Serial.begin(115200);//序列阜連線速率
- }
-
- void loop() {
- // put your main code here, to run repeatedly:
- if(Serial.available()){ //
- int num = Serial.parseInt(); // case 前置 num(數字鍵)
-
- switch(num) { //
-
- case 1 : //1~9
- for(pos = 0; pos < 180; pos += 1) // 一度一度由 0 度扭轉到 180 度
- myservo.write(pos);
- delay(200);
- break;
-
- case 2 : // 1~9
- for(pos = 180; pos>=1; pos-=1) // 一度一度由 180 度扭轉到 0 度
- myservo.write(pos);
- delay(200);
- break;
- }
- }
- }
複製代碼 

解決方式
寫入時若是出現了下方狀態
先到打開伺服esp32網址(上方網址)

以下內文出自: