Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.
/ pca9685.ex Public archive

Elixir library for the PCA9685 12-channel PWM driver.

Notifications You must be signed in to change notification settings

jimsynz/pca9685.ex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PCA9685

This is a simple elixir library for controlling servos or LEDs with the NXP PCA9685 16 channel i2c PWM controller.

Installation

If available in Hex, the package can be installed as:

  1. Add pca9685 to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:pca9685, "~> 0.1.0"}]
end
```
  1. Ensure pca9685 is started before your application:
```elixir
def application do
  [applications: [:pca9685]]
end
```

Usage

Add your device(s) to your project's config:

config :pca9685,
        devices: [%{bus: "i2c-1", address: 0x40}]

You can optionally specify a PWM frequency to configure at startup, useful if you're driving servos:

config :pca9685,
        devices: [%{bus: "i2c-1", address: 0x40, pwm_freq: 60}]

You can use the PCA9685.Device API to manipuate the device's outputs, for example:

# Set the duty cycle for all channels on device "i2c-1:0x40" to 0:150:
PCA9685.Device.all("i2c-1", 0x40, 0, 150)
# Set the duty cycle for an individual channel:
PCA9685.Device.all("i2c-1", 0x40, 0, 0, 150)

Additionally, if you have servos connected and want to control then individually you can add servos to your configuration as below;

config :pca9685,
        servos: [%{bus: "i2c-1", address: 0x42, channel: 0, position: 90, min: 150, max: 600}]

And then manipulate them with the PCA9685.Servo API.

The position key is optional, and sets the initial starting position of the servo (in degrees between 0 and 180). The min and max keys are also optional, and will default to a duty cycle of 0:150 and 0:600 respectively, you will most likely need to tune these values for each type of servo you have connected. Sorry about that.

Thanks

Thanks to Adafruit for their Python and Arduino libraries, from which this code is heavily influenced.

About

Elixir library for the PCA9685 12-channel PWM driver.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages