ArmbianPCA9685

Multiples servos with PCA9685 on I2C bus

Install

Packages

sudo armbian-config
sudo vim /boot/armbianEnv.txt
sudo apt-get install -y python3 git python3-pip python3-smbus python-dev-is-python3 i2c-tools
sudo apt --fix-broken install
sudo adduser jody i2c

/boot/armbianEnv.txt

verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun8i-h3
overlays=uart3 i2c0 spi-spidev
param_spidev_spi_bus=0
rootdev=UUID=2fe1cf2c-da2d-4a68-846a-f12a16f2883a
rootfstype=ext4
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
#!/bin/sh
# libgpiod.sh

# Instructions!
# cd ~
# wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/libgpiod.sh
# chmod +x libgpiod.sh
# ./libgpiod.sh

is_legacy=0

# Loop through arguments and process them
for arg in "$@"
do
    case $arg in
        -l|--legacy)
        is_legacy=1
        shift
        ;;
        *)
        shift
        ;;
    esac
done

echo "Installing build requirements - this may take a few minutes!"
echo

# install generic linux packages required
sudo apt-get update && sudo apt-get install -y \
   autoconf \
   autoconf-archive \
   automake \
   build-essential \
   git \
   libtool \
   pkg-config \
   python3 \
   python3-dev \
   python3-setuptools \
   swig3.0 \
   wget

# for raspberry pi we need...
sudo apt-get install -y raspberrypi-kernel-headers

build_dir=`mktemp -d /tmp/libgpiod.XXXX`
echo "Cloning libgpiod repository to $build_dir"
echo

cd "$build_dir"
git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git .

if test $is_legacy = 1; then
    git checkout v1.4.2 -b v1.4.2
fi


echo "Building libgpiod"
echo

include_path=`python3 -c "from sysconfig import get_paths; print(get_paths()['include'])"`

export PYTHON_VERSION=3
./autogen.sh --enable-tools=yes --prefix=/usr/local/ --enable-bindings-python CFLAGS="-I/$include_path" \
   && make -j 4 \
   && sudo make install \
   && sudo ldconfig

# This is not the right way to do this:
sudo cp bindings/python/.libs/gpiod.so /usr/local/lib/python3.?/dist-packages/
sudo cp bindings/python/.libs/gpiod.la /usr/local/lib/python3.?/dist-packages/
sudo cp bindings/python/.libs/gpiod.a /usr/local/lib/python3.?/dist-packages/

exit 0

Testing servos: servotest.py

#servotest.py
import time # system
from board import SCL, SDA # blinka
from busio import I2C


from adafruit_pca9685 import PCA9685 # PCA Module
from adafruit_motor import servo # servo library

i2c_bus = I2C(SCL, SDA)
pca = PCA9685(i2c_bus)
pca.frequency = 50

my_servo = servo.Servo(pca.channels[0])
pan = servo.Servo(pca.channels[1])

my_servo.angle = int(0)
pan.angle = int(0)
time.sleep(0.5)
my_servo.angle = int(90)
pan.angle = int(90)
time.sleep(0.5)
my_servo.angle = int(180)
time.sleep(0.5)
my_servo.angle = int(45)
pan.angle = int(0)

time.sleep(0.5)