Current section
Files
Jump to
Current section
Files
README.md
# PCA9685
[](https://hex.pm/packages/pca9685)
[](https://www.apache.org/licenses/LICENSE-2.0)
Driver for PCA9685 based 16 channel, 12 bit PWM driver connected over I2C.
## Usage
Add your device to your config like so:
```elixir
config :pca9685,
devices: [%{bus: "i2c-1", address: 0x40}]
```
The properties `bus` and `address` are mandatory. You can optionally provide
`pwm_freq` which is the output frequency you'd like to set (in Hz) and
`oe_pin` which is the GPIO pin that you want to use for the output-enable
function. Remember that the OE pin is expecting to be driven high to +5V, so
won't work on a Raspberry Pi without a level shifter of some kind.
Your devices will be reset and you will be able to drive the outputs with your
specified output frequency and duty cycle.
### Turning outputs off
Opening a device turns every channel fully off, and each channel stays off
until you set it. To turn outputs off again, use `PCA9685.Device.channel_off/2`
for one channel or `PCA9685.Device.all_off/1` for all of them. These set the
chip's full-OFF bit, which is how the datasheet says to hold an output off.
The datasheet also says a channel's ON and OFF counts should never be equal, so
setting equal counts with `PCA9685.Device.channel/4` or `PCA9685.Device.all/3`
turns the channel fully off instead.
Writes return `:ok` once the chip has acknowledged them, or `{:error, reason}`
if the I2C write fails.
### Opening with the outputs disabled
With an `oe_pin`, the device enables its outputs (drives OE low) when it opens.
Pass `output_enabled: false` to open it with OE high instead, and call
`PCA9685.Device.output_enable/1` when you're ready. The pin is opened high, so
it is never driven low in between. Stopping the device drives OE high again
whether or not the outputs were ever enabled.
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `pca9685` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:pca9685, "~> 1.2.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/pca9685](https://hexdocs.pm/pca9685).
## Github Mirror
This repository is mirrored [on Github](https://github.com/jimsynz/pca9685)
from it's primary location [on my Forgejo instance](https://harton.dev/james/pca9685).
Feel free to raise issues and open PRs on Github.
## License
This software is licensed under the terms of the
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0), see the `LICENSE.md`
file included with this package for the terms.