pwm.pca9685#

Description#

This plugin interacts with an Adafruit PCA9685 circuit, a 16-channel PWM servo driver. You can leverage this plugin to control servos and motors through Platypush.

Note that the driver for PCA9685 has been written for CircuitPython, and in order to use it on a Raspberry Pi or similar devices you need to follow these steps:

# pip3 install --upgrade adafruit-python-shell
$ wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
# python3 raspi-blinka.py

Then reboot and check that the following virtual devices are available:

- /dev/i2c-1
- /dev/spidev0.0
- /dev/spidev0.1

Finally, install the PCA9685 drivers:

# pip3 install --upgrade adafruit-circuitpython-pca9685

This plugin works with a PCA9685 circuit connected to the Platypush host over I2C interface.

Configuration#

pwm.pca9685:
  # [Required]
  # Default PWM frequency to use for the driver, in Hz.
  frequency:   # type=float

  # [Optional]
  # Minimum PWM duty cycle (you can often find it in the documentation of your device).
  # Default: 0.
  # min_duty_cycle: 0  # type=int

  # [Optional]
  # Maximum PWM duty cycle (you can often find it in the documentation of your device).
  # Default: 0xffff.
  # max_duty_cycle: 65535  # type=int

  # [Optional]
  # Indices of the default channels to be controlled (default: all channels,
  # i.e. ``[0-15]``).
  # channels:   # type=Optional[Iterable[int]]

Dependencies#

pip

pip install adafruit-circuitpython-pca9685

Actions#

Module reference#

class platypush.plugins.pwm.pca9685.PwmPca9685Plugin(frequency: float, min_duty_cycle: int = 0, max_duty_cycle: int = 65535, channels: Iterable[int] | None = None, **kwargs)[source]#

Bases: Plugin

This plugin interacts with an Adafruit PCA9685 circuit, a 16-channel PWM servo driver. You can leverage this plugin to control servos and motors through Platypush.

Note that the driver for PCA9685 has been written for CircuitPython, and in order to use it on a Raspberry Pi or similar devices you need to follow these steps:

# pip3 install --upgrade adafruit-python-shell
$ wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
# python3 raspi-blinka.py

Then reboot and check that the following virtual devices are available:

- /dev/i2c-1
- /dev/spidev0.0
- /dev/spidev0.1

Finally, install the PCA9685 drivers:

# pip3 install --upgrade adafruit-circuitpython-pca9685

This plugin works with a PCA9685 circuit connected to the Platypush host over I2C interface.

__init__(frequency: float, min_duty_cycle: int = 0, max_duty_cycle: int = 65535, channels: Iterable[int] | None = None, **kwargs)[source]#
Parameters:
  • frequency – Default PWM frequency to use for the driver, in Hz.

  • min_duty_cycle – Minimum PWM duty cycle (you can often find it in the documentation of your device). Default: 0.

  • max_duty_cycle – Maximum PWM duty cycle (you can often find it in the documentation of your device). Default: 0xffff.

  • channels – Indices of the default channels to be controlled (default: all channels, i.e. [0-15]).

deinit()[source]#

De-initialize the PCA9685 if it was previously initialized.

get_channels() Dict[int, float][source]#

Get the current duty cycle value of the channels.

Returns:

A map in the format channel_index -> value, where value is the duty cycle of the associated channel, as a percentage value between 0 and 1.

reset()[source]#

Reset the PCA9685 (set all the channels to zero).

write(value: int | None = None, channels: Dict[int, float] | None = None, frequency: float | None = None, step: int | None = None, step_duration: float | None = None)[source]#

Send PWM values to the channels.

Parameters:
  • value – Send the value to all the channels (or to all the configured default channels). value and channels are mutually exclusive.

  • channels – Map of the values to be written, as a channel_index -> value, where value is a real number. value and channels are mutually exclusive.

  • frequency – Override default frequency.

  • step – If set, then the PWM duty cycle will be increased/decreased by this much per cycle (i.e. 1/frequency). This is useful when dealing with PWM devices that require smooth transitions, arming sequences or ramping signals. If None (default) then the new PWM values will be directly written with no ramping logic.

  • step_duration – If step is configured, this parameter identifies how long each step should last (default: 1/frequency).