Radxa rock-4c+ running python with PCA9685

Running servoTest.py in Thonny I get the following result, does any one have an idea of the problem
I am trying to run a pan and tilt camera setup using i2c7 output.

“Terminal output for i2c test”

ali@rock-4c-plus:~$ sudo i2cdetect -y -r 7
[sudo] password for ali:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – --
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: 40 – -- – -- – -- – -- – -- – -- – -- –
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: 70 – -- – -- – -- –

“servoTest.py in Thonny”

from adafruit_servokit import ServoKit
sKit=ServoKit(channels=16)
sKit.servo[0].angle=45

“Error in Thonny”

Python 3.9.2 (/usr/bin/python3)

%Run servoTest.py
ImportError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/ali/servoTest.py”, line 1, in
from adafruit_servokit import ServoKit
File “/usr/local/lib/python3.9/dist-packages/adafruit_servokit.py”, line 35, in
import board
File “/usr/local/lib/python3.9/dist-packages/board.py”, line 251, in
from adafruit_blinka.board.radxa.rockpi4 import *
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/board/radxa/rockpi4.py”, line 7, in
from adafruit_blinka.microcontroller.rockchip.rk3399 import pin
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/rockchip/rk3399/pin.py”, line 7, in
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py”, line 8, in
raise ImportError(
ImportError: libgpiod Python bindings not found, please install and try again! See https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh

it seems that libgpiod is not installed.
try opening python3 and importing it manually:

python3
import libgpiod

if this failes then it needs to be installed
if this succeeds then you it is installed, probably in your users sub directory and when you use sudo, PYTHON_PATH environment variable is not including libs installed under your user.

Thank you for your quick response, I am new to linux, I checked and I could import libgpiod.
I find libgpiod.py and libgpiod.sh is in my /home/ali directory, but not sure what to do now, i;ve never set up paths before.

the easiest way would be with exporting with new value:

export PYTHONPATH=$PYTHONPATH:$HOME

the issue is that it is not consistent and every time you exit your dev environment, you’ll have to run the command every time.
You can make it permanent by saving the code below at the end of /etc/bash.bashrc file

echo PYTHONPATH=$PYTHONPATH:/home/yourusername >> /etc/bash.bashrc

reboot after the command and it should work

read this for additional info

Tried what you asked, still not working, line at bottom add to /etc/bash.bashrc file.
this is the latest error I get below.
Website https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh does not work correctly :- 404 - page not found

Thonny code

from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)
kit.servo[0].angle = 90

Python 3.9.2 (/usr/bin/python3)

%Run servoTest.py
ImportError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/ali/servoTest.py”, line 1, in
from adafruit_servokit import ServoKit
File “/usr/local/lib/python3.9/dist-packages/adafruit_servokit.py”, line 35, in
import board
File “/usr/local/lib/python3.9/dist-packages/board.py”, line 251, in
from adafruit_blinka.board.radxa.rockpi4 import *
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/board/radxa/rockpi4.py”, line 7, in
from adafruit_blinka.microcontroller.rockchip.rk3399 import pin
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/rockchip/rk3399/pin.py”, line 7, in
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py”, line 8, in
raise ImportError(
ImportError: libgpiod Python bindings not found, please install and try again! See https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh

Line I have added as you have shown to /etc/bash.bashrc file

echo PYTHONPATH=$PYTHONPATH:/home/ali >> /etc/bash.bashrc
thank you again for helping
Alistair

I have just noticed at the top of the terminal ** bash: /etc/bash.bashrc: Permison denied **
This may be my problem, have I added the echo line wrongly ?
Alistair

use

sudo echo PYTHONPATH=$PYTHONPATH:/home/ali >> /etc/bash.bashrc

How did you install libgpiod?

Using sudo apt install libgpiod-dev I get the same error as you.

But following the install from https://learn.adafruit.com/circuitpython-on-orangepi-linux/orange-pi-r1#install-libgpiod-3029538-23

sudo apt-get install libgpiod2 python3-libgpiod
pip3 install gpiod

… no longer moans about bindings but instead errors about permission on /dev/gpiochip0 (which only has permissions for root so seems good).

Running thonny as sudo I get the code moaning that nothing’s attached (because it isn’t) so I assume it might work if hardware was attached.

(this is on a 4C+ on debian_bullseye_kde_b55 image).

Sorry still no good, still have permision problems, think a maybe software from scratch.

Still no joy, I am using “rock-4c-plus_debian_bullseye_xfce_b58.img.xz” image

I’ve tried the install I posted on a fresh xcfe_b58 and it doesn’t get the bindings error.

Wrote rock-4c-plus_debian_bullseye_xfce_b58.img.xz to SD card

Update

sudo apt update
sudo apt upgrade

Installed thonny

sudo apt install thonny

Ran code and get “no module names adafruit_servoKit” error.

Installed servokit

pip3 install adafruit-circuitpython-servokit

Ran code and get libgpiod python bindings not found error.

Installed libgpiod (libgpiod2 not required, says it’s latest version)

sudo apt-get install python3-libgpiod
pip3 install gpiod

Ran code and get a permission error on /dev/gpiochip0

Running thonny as sudo gets a “no module names adafruit_servoKit” when running the code which I didn’t get in KDE, but a quick dirty chmod for others on the /dev/gpiochip(s) and the code gets to “No Hardware on I2C” (which there isn’t).

Please note that chmodding for others on /dev/gpiochip# is definitely NOT the recommended method for giving access to them and shouldn’t really be done for anything other than testing. Make sure to undo rights changes for other if you do this and go the extra mile to grant access to non root.

getting same error as you plus
Traceback (most recent call last):
File “/home/ali/servoTest.py”, line 1, in
from adafruit_servokit import ServoKit
File “/usr/local/lib/python3.9/dist-packages/adafruit_servokit.py”, line 35, in
import board
File “/usr/local/lib/python3.9/dist-packages/board.py”, line 251, in
from adafruit_blinka.board.radxa.rockpi4 import *
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/board/radxa/rockpi4.py”, line 7, in
from adafruit_blinka.microcontroller.rockchip.rk3399 import pin
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/rockchip/rk3399/pin.py”, line 7, in
from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py”, line 8, in

Not too sure what you mean by same error.

I’m getting no hardware on I2C error because I don’t have any hardware on I2C. I’m assuming that if I did have hardware attached then it would be working.

If you have hardware attached and getting a no hardware on I2C error then I’m afraid I can’t really help any further.

Yes I have the hardware connected but still not working, given up now trying to get it to work, will maybe think of some other way using pwm pins.
Thank you for your help, much appreciated.

Had another try at this.

from adafruit_servokit import ServoKit
myKit=ServoKit(channels=16)
myKit.servo[0].angle=45

got a permission error on /dev/gpiochip0
To stop the error /dev/gpiochip0 I entered commands below

sudo chmod 777 /dev/gpiochip0
sudo chmod 777 /dev/gpiochip1
sudo chmod 777 /dev/gpiochip2
sudo chmod 777 /dev/gpiochip3
sudo chmod 777 /dev/gpiochip4

This got ride of that error, but now have this:-

%Run Servo_kit_test.py
Traceback (most recent call last):
File “/home/ali/Desktop/python/Servo_kit_test.py”, line 2, in
myKit=ServoKit(channels=16)
File “/home/ali/.local/lib/python3.9/site-packages/adafruit_servokit.py”, line 88, in init
i2c = board.I2C()
File “/home/ali/.local/lib/python3.9/site-packages/board.py”, line 369, in I2C
return busio.I2C(SCL, SDA)
File “/home/ali/.local/lib/python3.9/site-packages/busio.py”, line 35, in init
self.init(scl, sda, frequency)
File “/home/ali/.local/lib/python3.9/site-packages/busio.py”, line 150, in init
raise ValueError(
ValueError: No Hardware I2C on (scl,sda)=((2, 1), (2, 0))
Valid I2C ports: ((2, (2, 1), (2, 0)), (6, (2, 10), (2, 9)), (7, (2, 8), (2, 7)))

On rebooting the error /dev/gpioships0 is back, must be a way to make it permanent.