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 -y
Note: 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
You can uninstall the library with this CMake command:
sudo cmake --workflow --preset uninstall
You 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-cpp
To run the Python example, run the following command in the examples/python/
directory.
python3 example.py