Thanks! I have managed to control the servo with precision I was aiming for.
Few notes for people that will be in the same trouble as me:
Step 1:
Enable dtoverlay (no idea what is it, but we need it, trust me - I'm engineer)
Note: "pwm-2chan" worked for me the best.Remember to reboot:Step 2:
Create somewhere a script to run your servo (actually to have it as a reference for future) let's call it "ServoExample.sh"Step 3:
Run the script:Step 4:
Debug, it never works straight away...
Check if the pin you are using is actually pwm, and if the channel you have specified is actually correct.For the example script you should get this output
P.S.
This is to control the single servo, the problem is - for my project I'll have to control more than 20 servos simultaneously, this is the reason i have got few PCA9685 boards. Is there a way to get same precision as I have now using the solution above? or maybe I have to get some other board(s)?
Few notes for people that will be in the same trouble as me:
Step 1:
Enable dtoverlay (no idea what is it, but we need it, trust me - I'm engineer)
Note: "pwm-2chan" worked for me the best.
Code:
sudo nano /boot/firmware/config.txtdtoverlay=pwm-2chanCode:
sudo reboot -fCreate somewhere a script to run your servo (actually to have it as a reference for future) let's call it "ServoExample.sh"
Code:
#!/bin/bashCHANNEL=2# The channel your servo is onCHIP=pwmchip0# I had only this one, most examples mention pwmchip2 - i have no idea where to get one :)PWM=pwm$CHANNEL# Do not touch!# Disable and unexport if already existsif [ -d "/sys/class/pwm/$CHIP/$PWM" ]; then echo 0 > /sys/class/pwm/$CHIP/$PWM/enable 2>/dev/null || true echo $CHANNEL > /sys/class/pwm/$CHIP/unexport 2>/dev/null || truefiecho $CHANNEL > /sys/class/pwm/$CHIP/exportsleep 1echo 16666667 > /sys/class/pwm/$CHIP/$PWM/period # 16.67ms period (60Hz), should be ok for hobby servosecho 1500000 > /sys/class/pwm/$CHIP/$PWM/duty_cycle # 1.5ms pulse (midpoint), my servo has 500-2500ms rangeecho 1 > /sys/class/pwm/$CHIP/$PWM/enableRun the script:
Code:
bash ServoExample.shDebug, it never works straight away...
Check if the pin you are using is actually pwm, and if the channel you have specified is actually correct.
Code:
pinctrl 18Code:
18: a3 pd | lo // GPIO18 = PWM0_CHAN2P.S.
This is to control the single servo, the problem is - for my project I'll have to control more than 20 servos simultaneously, this is the reason i have got few PCA9685 boards. Is there a way to get same precision as I have now using the solution above? or maybe I have to get some other board(s)?
Statistics: Posted by Naivrat — Sat Oct 11, 2025 11:04 pm