HowTo: ESPEasy – Use a PCA9685 and ESPEasy to control servos

The PCA9685 is a PWM port expander. This makes it possible to connect up to 16 LEDs, servos or other components to your ESP8266 and supply them with a PWM signal.

Thanks to ESPEasy (and the matching plug-in), controlling the PCA9685 is particularly easy. With the PCA9685, you can ultimately control up to 16 servos using ESPEasy.

In order for this to work, however, you have to pay attention to a few settings. Everything you need to know is described in the following article.


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/

Affiliate links / advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
You can find additional tips on ESPEasy in the following articles.

Required tools:

Required material:


How it works

The signal for controlling a servo basically consists of a pulse of 0.5 to 2.5 ms in length. This pulse should be repeated every 20 ms.

This signal can be simulated using the PCA9685. To do this, the PWM frequency only needs to be adjusted so that it corresponds to the period duration of the servo signal.

In this picture you can see the relationship between servo signal (left) and servo position (right).

Source: https://de.wikipedia.org/wiki/Servo


Configuration in ESPEasy

This section only deals with the configuration of the ESPEasy plug-in. That means you should already have connected the PCA9685 or the breakout board on which it is installed to the ESP8266. For this you should have connected the two according to the following scheme.

PCA9685ESP8266
GNDGND
VCC5V or 3V3
SDAGPIO 0
SCLGPIO 2
V+5V

The ESPEasy firmware should already be installed on your ESP8266. How you can proceed is described in the article ESPEasy – Compile firmware, flash it and configure WiFi access data.

Then you can switch to the “Devices” section and create the “Extra IO – PCA9685” device.

You should then configure the created plugin as shown.

It is important that you set the PWM frequency (“Frequency”) to 50Hz. This corresponds to the period duration of 20 ms (required for the servo).

Once you have made all the configurations, you can control the connected servos with the correct command.

An example:

The command

PCAPWM,0,300,

sets the PWM signal of the first (=0) connection of the PCA9685(which is called PCAPWM) to the value 300.

For the servo that I use on connection 0 of my PCA9685, I was able to use the following commands, for example.

  • Smallest angle: PCAPWM,0,50,
  • Largest angle: PCAPWM,0,300,

How you can send commands to your ESPEasy device is described in the article ESPEasy – Execute commands and actions via HTTP, MQTT, UDP and directly.

Additional general information about this ESPEasy plugin can also be found under the following link:
https://www.letscontrolit.com/wiki/index.php?title=PCA9685


I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *