PHPackages                             phpdreams/pca9685 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpdreams/pca9685

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpdreams/pca9685
=================

PHP Class to enable control of the Adafruit PCA9685 16-channel PWM/Servo I2C Interface

764PHP

Since Feb 27Pushed 9y ago3 watchersCompare

[ Source](https://github.com/phpdreams/pca9685)[ Packagist](https://packagist.org/packages/phpdreams/pca9685)[ RSS](/packages/phpdreams-pca9685/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PCA9685 PWM Controller
======================

[](#pca9685-pwm-controller)

**PHP Class to enable control of the Adafruit PCA9685 16-channel PWM/Servo I2C Interface**

I wrote this to allow me to control the Adafruit PCA9685 PWM board to do some custom LED lighting in my living room. The only code I could find for this was in Python. I've been a PHP developer for nearly 20 years, so I naturally wanted to code in something I was more comfortable with.

It took a lot of reading and piecing together a way to get this working including reviewing quite a bit of the 52-page datasheet for the PCA9685 chip (linked below). In the end, it was worth it as I can now control all the channels of this great little board from a web page on any device in the house.

As much trouble as I had, I figured others might have the same issues. I decided I'd put the code together as a **Composer** package and make it available on **Packagist**. I hope it helps somebody else.

### Requirements

[](#requirements)

*I'm not going to show how you can get PHP7 &amp; Nginx running on your Raspberry Pi, there are lots of other resources for that kind of thing.*

This code does require that you have already enabled **I2C** support and installed the `i2c-tools`.

For my new (purchased Jan 2017) Raspberry Pi 3, this was easy as I only had to edit the `/boot/config.txt` file and uncomment the `dtparam=i2c_arm=on` line and reboot.

Then I installed the I2C tools:

```
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools

```

You can read up a bit more here:

### Resources

[](#resources)

Interface board can be purchased directly from Adafruit here:

Datasheet for the PCA9685:

Installation
------------

[](#installation)

Installation is best accomplished with Composer ()

```
composer require "phpdreams/pca9685":"dev-master"

```

Usage
-----

[](#usage)

```
require_once(__DIR__ . '/vendor/autoload.php');

use PHPDreams\PCA9685\PCA9685;

$pwm = new PCA9685();
```

I've setup two ways to set the PWM level of any given channel. You can do it by percent or by setting the on and off points.

#### Set Channel Output by Percent:

[](#set-channel-output-by-percent)

```
$pwm->setPWMpercent($channel, $percent);
```

Channel is a number from 0 to 15.

#### Manually setting the on and off points:

[](#manually-setting-the-on-and-off-points)

```
$pwm->setPWM($channel, $countOff, $countOn = 0);
```

You can set the on and off points in the 4096-count cycle. So setting a channel to turn off at at 2048 would be a 50% duty cycle.

*If you don't set an 'On' point, it will default to 0.*

#### Set ALL channels to a value:

[](#set-all-channels-to-a-value)

```
$pwm->setAll($channel, $countOff, $countOn = 0);
```

#### Set refresh frequency in Hz:

[](#set-refresh-frequency-in-hz)

```
$pwm->setFrequency($frequency);
```

*Defaults to 200Hz refresh.*

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/808685?v=4)[Bill Wheeler](/maintainers/phpdreams)[@phpdreams](https://github.com/phpdreams)

---

Top Contributors

[![phpdreams](https://avatars.githubusercontent.com/u/808685?v=4)](https://github.com/phpdreams "phpdreams (2 commits)")

### Embed Badge

![Health badge](/badges/phpdreams-pca9685/health.svg)

```
[![Health](https://phpackages.com/badges/phpdreams-pca9685/health.svg)](https://phpackages.com/packages/phpdreams-pca9685)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
