All Projects → Reinbert → pca9685

Reinbert / pca9685

Licence: other
This software is a devLib extension to wiringPi http://wiringpi.com/ and enables it to control the Adafruit PCA9685 16-Channel 12-bit PWM/Servo Driver http://www.adafruit.com/products/815 via I2C interface.

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to pca9685

pigpio-client
A nodejs client for pigpio socket interface.
Stars: ✭ 24 (-50%)
Mutual labels:  servo, raspberrypi, pwm
blinkt go
A Golang library for the Pimoroni Blinkt!
Stars: ✭ 24 (-50%)
Mutual labels:  raspberrypi, wiringpi
DC-Servo
Analog speed control of Brushed DC Motor
Stars: ✭ 16 (-66.67%)
Mutual labels:  servo, pwm
Raspberry-ili9325
Parallel TFT Shield Library for wiringPi
Stars: ✭ 40 (-16.67%)
Mutual labels:  raspberrypi, wiringpi
pwm-pca9685-rs
Platform-agnostic Rust driver for the PCA9685 I2C 16-channel, 12-bit PWM/Servo/LED controller
Stars: ✭ 19 (-60.42%)
Mutual labels:  servo, pwm
pumpkin-pi
Raspberry pi project that controls jack-o-lantern via servo motor and PIR motion sensors
Stars: ✭ 15 (-68.75%)
Mutual labels:  servo, raspberrypi
gladys-gateway
An End-to-End Encrypted Gateway to access Gladys from the internet
Stars: ✭ 17 (-64.58%)
Mutual labels:  raspberrypi
vigilantpi
VigilantPI is a lightweight NVR which targets mainly Raspberry Pi
Stars: ✭ 14 (-70.83%)
Mutual labels:  raspberrypi
rust-crosscompiler-arm
Docker images for Rust dedicated to cross compilation for ARM v6 and more
Stars: ✭ 48 (+0%)
Mutual labels:  raspberrypi
PowerBlock
Driver for petrockblock.com PowerBlock
Stars: ✭ 37 (-22.92%)
Mutual labels:  raspberrypi
servonk
Servo on Gonk
Stars: ✭ 84 (+75%)
Mutual labels:  servo
NR1-UI
Userinterface for Volumio (RaspberryPi) with ssd1322 and ssd1306 oled display, spectrum bargraph, progress bar, LED functions, Standby-functions, 4 Buttons and Rotary Encoder.
Stars: ✭ 29 (-39.58%)
Mutual labels:  raspberrypi
CyberSecurity-Box
Firewall-System based on OpenWRT or Pi-Hole with UnBound, TOR, optional Privoxy, opt. ntopng and opt. Configuration of the AVM FRITZ!Box with Presets for Security and Port-List. Please visit:
Stars: ✭ 20 (-58.33%)
Mutual labels:  raspberrypi
hexy
Code for a hexapod robot
Stars: ✭ 69 (+43.75%)
Mutual labels:  servo-controller
os
OS for Pi-KVM based on Arch Linux ARM
Stars: ✭ 42 (-12.5%)
Mutual labels:  raspberrypi
pinetime-updater
Flash firmware to PineTime the friendly wired way with OpenOCD
Stars: ✭ 53 (+10.42%)
Mutual labels:  raspberrypi
subwayclock
Display clock for NYC subways
Stars: ✭ 29 (-39.58%)
Mutual labels:  raspberrypi
blinkt
A Rust library for the Pimoroni Blinkt!, and any similar APA102 or SK9822 LED strips or boards, on a Raspberry Pi.
Stars: ✭ 18 (-62.5%)
Mutual labels:  raspberrypi
gpio
A RaspberryPi GPIO library written in PHP.
Stars: ✭ 16 (-66.67%)
Mutual labels:  raspberrypi
Rc Engine Sound ESP32
Allows to play vehicle engine sounds on an ESP32. Additional sounds can play in parallel with the engine sound! Controls your lights as well. compatible with SBUS, IBUS, PWM, PPM and SUMD signals.
Stars: ✭ 139 (+189.58%)
Mutual labels:  pwm

PCA9685 README

This software is a devLib extension to wiringPi and enables it to control the Adafruit PCA9685 16-Channel 12-bit PWM/Servo Driver via I2C interface.

Copyright (c) 2019 Reinhard Sprung

If you have questions or improvements email me at reinhard.sprung[at]gmail.com

NOTE: The software could run faster because some write function read the current register value before they write to it, but it shouldn't matter in usual setups. If you need it super fast, you probably need to program your own write functions.

REQUIREMENTS

Enable I2C on your Raspberry Pi and make sure your PCA9685 controller board can be found. A tutorial on how to do this can be found here.

INSTALL

This pca9685 library requires an installed version of wiringPi. WiringPi comes preinstalled on standard raspbian systems so check first if it is there already. To do so, open a terminal and execute gpio -v.

If it's not installed, the easiest way is by calling sudo apt install wiringpi. If you need addidtional information or want to install from sources, check out http://wiringpi.com/download-and-install/.

NOTE: WiringPi is now deprecated and will not work out of the box on newer (≥Rpi4) boards, check out http://wiringpi.com/wiringpi-deprecated/

USAGE

You can include pca9685.h and pca9685.c directly in your project or compile it and include the lib file instead.

To compile, navigate into the src folder an run

sudo make install

This will install pca9685 in your /usr/lib, /usr/local/lib and /usr/local/include directories. To include the files add the line

#include <pca9685.h>

into your source code and include "wiringPiPca9685" in your linked files during compilation

EXAMPLES

There are some example files included in this repository. To compile them, cd into examples directory and make them. To run, add a "./" before each example and execute them, e.g. ./servo.

FUNCTIONS

Use

int pca9685Setup(const int pinBase, const int i2cAddress/* = 0x40*/, float freq/* = 50*/);

to setup a single pca9685 device at the specified i2c address and PWM frequency.

Parameters are:

- pinBase: 		Use a pinBase > 64, eg. 300
- i2cAddress:	The default address is 0x40
- freq:			Frequency will be capped to range [40..1000] Hertz. Try 50 for servos

When successful, this will reserve 17 pins in wiringPi and return a file descriptor with which you can access advanced functions (view below).

The pca9685 pins are as follows:

[0...15]: The 16 individual output pins as numbered on the driver
[16]: All pins (Note that reading from this pin returns always 0)

Use the following wiringPi functions to read and write PWM. NOTE: Don't forget to add the pin base!

Set PWM

void pwmWrite (int pin, int value)

if value <= 0, set full-off else if value >= 4096, set full-on else set PWM

Set full-on or full-off

void digitalWrite (int pin, int value)

if value != 0, set full-on else set full-off

Read off-register

int digitalRead (int pin)

To get PWM: mask with 0xFFF To get full-off bit: mask with 0x1000 Note: ALL_LED pin will always return 0

Read on-register

int analogRead (int pin)

To get PWM: mask with 0xFFF To get full-on bit: mask with 0x1000 Note: ALL_LED pin will always return 0

NOTE: Unfortunately wiringPi doesn't offer suitable names for pca9685's functions, so we have to work with the provided ones. Masking means to bitwise-AND (operator &) the return value with the mask. E.g. & 0xFFF

int offValue = digitalRead(pinBase + 0) & 0xFFF;

ADVANCED

If you don't want to use the wiringPi functions or want to access the pca9685 directly, you can use the file descriptor returned from the setup function to access the following functions for each connected pca9685 individually. (View source code for more details)

Set output frequency in a range between 40 and 1000 Hertz

void pca9685PWMFreq(int fd, float freq);

Reset all PWM output of this device to default state which is full-off

void pca9685PWMReset(int fd);

Write PWM on and off values to a specific pin. (View source code)

void pca9685PWMWrite(int fd, int pin, int on, int off);
void pca9685PWMRead(int fd, int pin, int *on, int *off);

Write enable or disable full-on and full-off of a specific pin. (View source code)

void pca9685FullOn(int fd, int pin, int tf);
void pca9685FullOff(int fd, int pin, int tf);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].