Run servo with Python on ESP32 (Windows)

MicroPython is installed in ESP32 in advance in the above.

Connect the servo and ESP32

This time I decided to connect it to the G2 pin. See Pins and GPIOs (https://micropython-docs-ja.readthedocs.io/ja/latest/esp32/quickref.html#pins-and-gpio) for available pins. Since the required voltage of the servo I bought was 4.8V ~ 6V, it is connected to 5V. image.png

Check the servo with PuTTY

How to use PuTTY is described in the postscript of the above.

Enter the command line by line in PuTTY and press Enter to check the range of motion of the servo.

Declaration to use PWM pulse and GPIO pin from machine import PWM, Pin

I named it servo1 with the frequency of pin 2 set to 50. It seems that the rotation speed is determined by the strength of the frequency. servo1 = PWM(Pin(2), freq = 50)

Changed the duty ratio of the servo. With this, adjust the angle many times and check the range of motion. Fine-tune in the range of 30 to 120. When the frequency is set to 100, it seems to be 60 to 240.

servo1.duty(30)

When I checked it while turning it, the minimum and maximum limits of my servo were 25 to 130.

Write code

I named it main.py and wrote the following simple code and saved it on my desktop. sleep is important. Without it, an infinite loop would occur and the ESP32 could not be overwritten with new code. If you can't overwrite it, you need to erase the flash and re-insert MicroPython.

main.py


# -*- coding: utf-8 -*-

from machine import PWM, Pin
import time

servo1 = PWM(Pin(2), freq = 50)

#Repeat angle 30 (minimum) and angle 120 (maximum) every 2 seconds
while True:
    servo1.duty(30)
    time.sleep_ms(2000)
    servo1.duty(120)
    time.sleep_ms(2000)

Send code to ESP32

Install the tool to send the code from the command prompt pip install adafruit-ampy

Ampy command confirmation ampy You can confirm by hitting.

I saved main.py to my desktop so I moved it to the bottom of my desktop cd Desktop

Send the main.py file to the ESP32. Change the COM3 part to the port you are connected to.

It worked safely.

reference

▼ ESP32 parts for Fritzing https://qiita.com/XZ_Manj/items/8bbdef59eeac4286e4f8

▼ Pin and GPIO https://micropython-docs-ja.readthedocs.io/ja/latest/esp32/quickref.html#pins-and-gpio

▼ Hada memo Move the servo by adjusting the pulse width https://scrapbox.io/hada/ESP32でサーボモータ[2018/10/29]_22:09:36

Recommended Posts

Run servo with Python on ESP32 (Windows)
Run python with PyCharm (Windows)
Put MicroPython on Windows to run ESP32 on Python
Run SwitchBot on Windows 10 with Bleak
Getting started with Python 3.8 on Windows
Python on Windows
Run Python with VBA
Run prepDE.py with python3
Run Blender with python
Python starting with Windows 7
python basic on windows ②
Install python on windows
Run iperf with python
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Rock-paper-scissors with Python Let's run on a Windows local server for beginners
Set-enable Python virtualenv on Windows
Python with VS Code (Windows 10)
Run Kali Linux on Windows with GUI (without VirtualBox)
Install watchdog on Windows + Python 3.3
Problems with windows python being called on pipenv on WSL
Run Python with CloudFlash (arm926ej-s)
Let's run Excel with Python
Python + Kivy development on Windows
Run Paints Chainer on CPU with official python on win10
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
Fastest Python installation on Windows
Build Python environment on Windows
Run Tensorflow 2.x on Python 3.7
PIL with Python on Windows 8 (for Google App Engine)
Run Python CGI on CORESERVER
Run unix command on python
Build python environment on windows
Run Label with tkinter [Python]
I ran python on windows
[Python] [Chainer] [Windows] Install Chainer on Windows
Use Python on Windows (PyCharm)
Time synchronization (Windows) with Python
Run Jupyter Notebook on windows
Run DHT22 with RasPi + Python
Blogging with Pelican on Windows
Until you create a machine learning environment with Python on Windows 7 and run it
OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
Let's get started with Python ~ Building an environment on Windows 10 ~
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
Python environment construction memo on Windows 10
Face detection with YOLO Face (Windows10, Python3.6)
Python 3.6 on Windows ... and to Xamarin.
Installing Kivy on Windows10 64bit Python3.5
Anaconda python environment construction on Windows 10
Install python2.7 on windows 32bit environment
Run Rotrics DexArm with python API
Install xgboost (python version) on Windows
Install Python on Windows + pip + virtualenv
Run mruby with Python or Blender
Run Tensorflow natively supported on windows
Install Pytorch on Blender 2.90 python on Windows
Integrate Modelica and Python on Windows
Run Python on Schedule on AWS Lambda
Run TensorFlow Docker Image on Python3
Run XGBoost with Cloud Dataflow (Python)