PiPCA9685 provides an interface for controlling a PCA9685 chip from a Raspberry Pi in C++ and Python.
This library was originally designed to control servos with Adafruit's PWM Hat. It was born out of a desire for C++ bindings, which Adafruit did not provide.
-
Before you begin, make sure your Pi has I2C enabled.
This step is not needed when using Ubuntu.
- Run
sudo raspi-config - Select "Interfacing Options"
- Enable I2C automatic loading
- Run
-
Clone repo
git clone https://github.com/barulicm/PiPCA9685.git
-
Install dependencies from apt
cd PiPCA9685 xargs -a apt_dependencies.txt sudo apt-get install -yNote: On Ubuntu, you may need to enable the universe repostiory with the command below to find some of the needed packages. This is NOT needed on Raspberry Pi OS.
sudo add-apt-repository universe
-
Build and install library
sudo cmake --workflow --preset install
Alternatively, you can install the library without root permissions, only for your user, with the following command:
cmake --workflow --preset install-nonroot
You can uninstall the library with this CMake command:
sudo cmake --workflow --preset uninstallOr, if you installed without root permissions, use this command:
sudo cmake --workflow --preset uninstall-nonrootYou can find simple examples of how to use this library in C++ and Python in the examples directory.
To build and run the C++ example, run the following commands in the examples/cpp/ directory.
cmake --workflow --preset build
./build/example-cppIf you installed without root permissions, you may need to tell cmake where to find the library:
PiPCA9685_DIR=~/.local/lib/cmake/PiPCA9685/ cmake --workflow --preset build
./build/example-cppTo run the Python example, run the following command in the examples/python/ directory.
python3 example.py