ESP32s2 servo SG90

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
bo2be
Normal user
Posts: 26
Joined: 18 Sep 2023, 14:52
Location: France
Contact:

ESP32s2 servo SG90

#1 Post by bo2be » 18 Sep 2023, 15:36

Has anybody succeeded to drive a servo SG90 with an ESP32S2 mini?
For the test, I compared with an ESP8266 D1 Mini clone and it works pretty well.
I tested with an ESP32s2 mini and obtained only a random short vibration.

Both test assemblies were commanded with http

Code: Select all

http://192.168.1.XXX/control?cmd=Servo,1,15,YY
XXX is my local ip adress for the ESP and YY is an angle between 0 and 90.
SG90 orange wire is on pin 15.

I tested several SG90, several ESPS2 mini boards, several pins, several EspEasy releases with no different behaviour.
I also tested with rules commands without more success.

Current configuration:
ESPs2 mini
ESP Board Name: Espressif Generic ESP32-S2 USB CDC 4M Flash ESPEasy 1810k Code/OTA 316k FS
Binary Filename: ESP_Easy_mega_20230822_normal_ESP32s2_4M316k_CDC

ESP8266 D1 mini
ESP Board Name: Espressif Generic ESP8266 ESPEasy 4M Flash 1M FS
Binary Filename:⋄ ESP_Easy_mega_20230822_normal_ESP8266_4M1M

Thanks in advance for comments.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#2 Post by TD-er » 18 Sep 2023, 18:56

I never tested it on an S2.
I will hook up one later this evening to see what the logic analyzer will report.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#3 Post by TD-er » 18 Sep 2023, 23:49

Yep, confirmed.
The servo command does not work well on an ESP32-S2.
When you set it to any positive angle, only a single pulse is given. No idea if it is of correct length.
Angle set to 0 or negative will give a constant pulse @ 1 kHz with 74.02% duty cycle.

Edit:
Will probably be fixed when I apply this fix: https://github.com/RoboticsBrno/ServoESP32/pull/25

Working on it... :)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#4 Post by TD-er » 19 Sep 2023, 00:17

Here is the fix: https://github.com/letscontrolit/ESPEasy/pull/4807

Here will be the GitHub Actions build: https://github.com/letscontrolit/ESPEas ... 6228585983

And here a zip with the ESP32-S2 normal build: https://www.dropbox.com/scl/fi/nwl55eq8 ... e432n&dl=0
Both the OTA update file and the 'factory' bin file included for flashing via serial.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#5 Post by TD-er » 19 Sep 2023, 00:28

Not sure though if the ESP32-S2 is the best choice for a servo.
ESP32 (classic) has 20 bit resolution, where the S2 only has 14 bit.

You only have a fraction of the full pulse width available, so I guess it will be roughly 9 - 10 bits left for the full range of the servo.

bo2be
Normal user
Posts: 26
Joined: 18 Sep 2023, 14:52
Location: France
Contact:

Re: ESP32s2 servo SG90

#6 Post by bo2be » 19 Sep 2023, 10:46

Super! it works!
Thanks a lot TD-er for your tremendous job.
You are wright for the less precise driving of the S2 ESP32 vs ES32 classic but it suits me for my purpose.
I run around twenty ESP's mainly for temperature monitoring with Domoticz. I gradually swap from ESP8266 to ESP32 and mainly for S2 type with a better wifi sensibility. Last year, I started 2 beehives weight recording with EspEasy with very good results. Now, as we live in a chalet in the Alps mountain, we are visited, to our great regret, by mischievous mice. So I am manufacturing several mouse traps with a photocell which drives a door and send us a SMS and mail alert through EaspEasy. Then we can release them, with no kill, far from our house (but not so far from our neighbor's :D ). So I don't need a huge precision with the servo which has just to draw the small cable which unlock the mouse trap door closing.
Thanks again for your fast answer.
Image
Image
Attachments
Mouse trap1.jpg
Mouse trap1.jpg (398.36 KiB) Viewed 3097 times

bidrohini
Normal user
Posts: 105
Joined: 03 Nov 2022, 16:24

Re: ESP32s2 servo SG90

#7 Post by bidrohini » 19 Sep 2023, 10:59

Thanks for the whole thread. I was planning to use the same servo with ESP.

bidrohini
Normal user
Posts: 105
Joined: 03 Nov 2022, 16:24

Re: ESP32s2 servo SG90

#8 Post by bidrohini » 19 Sep 2023, 11:00

bo2be wrote: 19 Sep 2023, 10:46 Super! it works!
Thanks a lot TD-er for your tremendous job.
You are wright for the less precise driving of the S2 ESP32 vs ES32 classic but it suits me for my purpose.
I run around twenty ESP's mainly for temperature monitoring with Domoticz. I gradually swap from ESP8266 to ESP32 and mainly for S2 type with a better wifi sensibility. Last year, I started 2 beehives weight recording with EspEasy with very good results. Now, as we live in a chalet in the Alps mountain, we are visited, to our great regret, by mischievous mice. So I am manufacturing several mouse traps with a photocell which drives a door and send us a SMS and mail alert through EaspEasy. Then we can release them, with no kill, far from our house (but not so far from our neighbor's :D ). So I don't need a huge precision with the servo which has just to draw the small cable which unlock the mouse trap door closing.
Thanks again for your fast answer.
Image
Image
By the way, is the woodwork also done by yourself?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#9 Post by TD-er » 19 Sep 2023, 11:09

Hmm if you are switching to ESP32-S2 for better WiFi stability, then you may have to be very lucky in buying boards.
Especially the "Wemos D1 mini" like form factor with ESP32-S2 are truly bad at WiFi. (those purple ones with PCB copper trace antenna)

My personal favorite right now whenever I need a small unit with good WiFi is the XIAO ESP32-C3 board.
https://www.tinytronics.nl/shop/en/deve ... o-esp32-c3
It has a 'sticker antenna', which you can mount in just the orientation you need.

bo2be
Normal user
Posts: 26
Joined: 18 Sep 2023, 14:52
Location: France
Contact:

Re: ESP32s2 servo SG90

#10 Post by bo2be » 19 Sep 2023, 15:03

Thanks for the advice and I will test one at least within some weeks.
You were wright, I am using purple board devices.
Image

Sometimes, I even weld 3 m of RG316, to cross some huge walls
Image

I didn't notice stability problem at my level of use which is not a reference.
If I notice something I will let you know.

For bidrohini , yes,it is home woodwork with old deck boards, not precisely cut, but it does the job!
Attachments
ESP32-S2.jpg
ESP32-S2.jpg (95.8 KiB) Viewed 3085 times
Welded ant cable.jpg
Welded ant cable.jpg (253.18 KiB) Viewed 3085 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#11 Post by TD-er » 19 Sep 2023, 15:27

Problem with those purple ESP32-S2 boards is that the WiFi stability can suddenly change.
One time it is working perfectly well and the next moment it may suddenly loose several packets (e.g. when sending a continuous ping to the unit).
I have no idea what may be causing such behavior.
I also have some really old ESP32-S2 boards which are encapsulated in a separate shield on a PCB like those old ESP12-F modules on the early NodeMCU and Wemos D1 mini boards and those work very well.
So I guess it may have something to do with either proper impedance matching of the antenna, or maybe the shielding actually does help improving stability.

bo2be
Normal user
Posts: 26
Joined: 18 Sep 2023, 14:52
Location: France
Contact:

Re: ESP32s2 servo SG90

#12 Post by bo2be » 19 Sep 2023, 18:21

For that purpose I will purchase an encapsulated ESP32-C3 board and a bare one. Just to see if I notice a difference.
Attachments
ESP32-C3.jpg
ESP32-C3.jpg (46.29 KiB) Viewed 3066 times
ESP32-C3-with_Ant.jpg
ESP32-C3-with_Ant.jpg (116.91 KiB) Viewed 3066 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#13 Post by TD-er » 19 Sep 2023, 18:54

That "open" board in the first picture does have a ceramic antenna.
Those are often significantly better than PCB trace antennas.

bo2be
Normal user
Posts: 26
Joined: 18 Sep 2023, 14:52
Location: France
Contact:

Re: ESP32s2 servo SG90

#14 Post by bo2be » 22 Sep 2023, 16:05

Mouse trap mass production is done with Esp32S2 driving the SG90 servo.
My cat can retired!
Attachments
IMG_20230922_155526.jpg
IMG_20230922_155526.jpg (127.69 KiB) Viewed 2988 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32s2 servo SG90

#15 Post by TD-er » 22 Sep 2023, 16:45

Maybe you can send your cat to follow a course to become the mouse trap supervisor.
Perhaps at some point he/she can coordinate an entire crew of mouse-relocators to empty those traps.

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests