Page 1 of 1

ESP32s2 servo SG90

Posted: 18 Sep 2023, 15:36
by bo2be
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.

Re: ESP32s2 servo SG90

Posted: 18 Sep 2023, 18:56
by TD-er
I never tested it on an S2.
I will hook up one later this evening to see what the logic analyzer will report.

Re: ESP32s2 servo SG90

Posted: 18 Sep 2023, 23:49
by TD-er
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... :)

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 00:17
by TD-er
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.

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 00:28
by TD-er
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.

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 10:46
by bo2be
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

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 10:59
by bidrohini
Thanks for the whole thread. I was planning to use the same servo with ESP.

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 11:00
by bidrohini
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?

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 11:09
by TD-er
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.

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 15:03
by bo2be
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!

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 15:27
by TD-er
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.

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 18:21
by bo2be
For that purpose I will purchase an encapsulated ESP32-C3 board and a bare one. Just to see if I notice a difference.

Re: ESP32s2 servo SG90

Posted: 19 Sep 2023, 18:54
by TD-er
That "open" board in the first picture does have a ceramic antenna.
Those are often significantly better than PCB trace antennas.

Re: ESP32s2 servo SG90

Posted: 22 Sep 2023, 16:05
by bo2be
Mouse trap mass production is done with Esp32S2 driving the SG90 servo.
My cat can retired!

Re: ESP32s2 servo SG90

Posted: 22 Sep 2023, 16:45
by TD-er
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.