Quantcast
Viewing all articles
Browse latest Browse all 4921

Beginners • Re: Rpi 5 and Pan Tilt hat

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 1

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: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --                         daniel@Pi5:~ $ 
it should display at 0x40 or 0x41

Then enable the overlay

Code:

sudo nano /boot/firmware/config.txt
add this line after [all]

Code:

dtoverlay=i2c-pwm-pca9685a,addr=0x40
Save and reboot!
Now the i2c detect should display something like this

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:~ $
Ok we could try manually to see if it works.

Code:

cd /sys/class/pwm/pwmchip6echo 0 > exportecho 20000000 > pwm0/periodecho  1500000 > pwm0/duty_cycleecho  1000000 > pwm0/duty_cycle
I found a c++ class to access all PWM butut has some compile error that I fixed in udev.
So I forked it!

Code:

git clone https://github.com/danjperron/sysfspwm.git
Compile it (check the README).

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.

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 $ 
For a servo the period is 20ms (50Hz) and the duty cycle is 1.5ms = 7.5% (0.075)
Wow! That is amazing! Thank you so much!
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: -- -- -- -- -- -- -- --   
There are two servos connected to pca9685.
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



Viewing all articles
Browse latest Browse all 4921

Trending Articles