Wow! That is amazing! Thank you so much!Well you could use the sysfs for the PCA9685
First Enable the I2c, reboot, connect your PCA9685 on I2C-1 (gpio2 & 3).
To check if you see the PCA9685 do a i2cdetect -y 1it should display at 0x40 or 0x41Code:
daniel@Pi5:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- daniel@Pi5:~ $
Then enable the overlayadd this line after [all]Code:
sudo nano /boot/firmware/config.txt
Save and reboot!Code:
dtoverlay=i2c-pwm-pca9685a,addr=0x40
Now the i2c detect should display something like thisOk we could try manually to see if it works.Code:
daniel@Pi5:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- daniel@Pi5:~ $
I found a c++ class to access all PWM butut has some compile error that I fixed in udev.Code:
cd /sys/class/pwm/pwmchip6echo 0 > exportecho 20000000 > pwm0/periodecho 1500000 > pwm0/duty_cycleecho 1000000 > pwm0/duty_cycle
So I forked it!Compile it (check the README).Code:
git clone https://github.com/danjperron/sysfspwm.git
Once it is compiled you could check if it works
N.B. small bug that I will fix later! you need to export the pin manually
echo 0 >/sys/class/pwm/pwmchip6/export
You will need to do it for every servos.For a servo the period is 20ms (50Hz) and the duty cycle is 1.5ms = 7.5% (0.075)Code:
:~/sysfspwm/build/example $ ./pwm_control /sys/class/pwm/pwmchip6 0 50 0.05sysfspwm Exampleconfiguring pwm at /sys/devices/platform/axi/1000120000.pcie/1f00074000.i2c/i2c-1/1-0040/pwm/pwmchip6/pwm0frequency is 50 and duty cycle is 5%:~/sysfspwm/build/example $ ./pwm_control /sys/class/pwm/pwmchip6 0 50 0.07sysfspwm Exampleconfiguring pwm at /sys/devices/platform/axi/1000120000.pcie/1f00074000.i2c/i2c-1/1-0040/pwm/pwmchip6/pwm0frequency is 50 and duty cycle is 7%:~/sysfspwm/build/example $
I was able to move servo from terminal with commands you assigned.
Will write some C++ tomorrow, will report all the results here, probably somebody will find it useful.
My i2cdetect -y 1 command gives me this result:
Code:
jryba@raspberrypi:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Am i right that i have to modify my config file to
dtoverlay=i2c-pwm-pca9685a,addr=0x40,addr=0x29
and it will give me control over second servo? Should i use same comands to control second servo?
Statistics: Posted by jryba — Sat Mar 16, 2024 10:43 pm