the comment suggested to add the following lines to the /etc/udev/rules.d/99-com.rules file
SUBSYSTEM==“pwm*”, PROGRAM=“/bin/sh -c ’
chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;
chown -R root:gpio /sys/devices/platform/soc/.pwm/pwm/pwmchip && chmod -R 770 /sys/devices/platform/soc/.pwm/pwm/pwmchip
'”
,after i added them i got no errors and the script was working but the motor was not moving and when i connected it to pin 0 the motor is staying at a fixed angle and if i manually try to move i feel it trying to move back to the fixed angle so i changed this file /etc/udev/rules.d/99-com.rules back to this
SUBSYSTEM==“pwm*”, PROGRAM=“/bin/sh -c ’
chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;
chown -R root:gpio /sys/devices/platform/soc/.pwm/pwm/pwmchip && chmo$
'”
but still am facing the same problem and i realized the pwm0,pwm1… files are showing now and am able to modify their permissions
now even if i try sudo python servo.py the file executes but the motor dose not move
not: i tried connecting the motor to another input but it is still not working.
Navio2 kernel driver that generates PWM needs to be fed with data at least every 100 ms. To make PWM output work, you need to update the value set_duty_cycle every 100 ms or less.
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
pwm.set_period(50)
pwm.enable()
while (True):
pwm.set_duty_cycle(SERVO_MIN)
time.sleep(1)
pwm.set_duty_cycle(SERVO_MAX)
time.sleep(1)
when i run Python Servo.py am getting this error message:
Traceback (most recent call last):
File “Servo.py”, line 21, in
time.sleep(1)
File “/home/pi/Navio2/Python/navio/pwm.py”, line 19, in exit
self.deinitialize()
File “/home/pi/Navio2/Python/navio/pwm.py”, line 25, in deinitialize
with open(self.SYSFS_PWM_UNEXPORT_PATH, “a”) as pwm_unexport:
IOError: [Errno 13] Permission denied: ‘/sys/class/pwm/pwmchip0/unexport’
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
pwm.set_period(50)
pwm.enable()
while (True):
pwm.set_duty_cycle(SERVO_MIN)
time.sleep(1)
pwm.set_duty_cycle(SERVO_MAX)
time.sleep(1)
when i run Python Servo.py am getting this error message:
Traceback (most recent call last):
File “Servo.py”, line 21, in
time.sleep(1)
File “/home/pi/Navio2/Python/navio/pwm.py”, line 19, in exit
self.deinitialize()
File “/home/pi/Navio2/Python/navio/pwm.py”, line 25, in deinitialize
with open(self.SYSFS_PWM_UNEXPORT_PATH, “a”) as pwm_unexport:
IOError: [Errno 13] Permission denied: ‘/sys/class/pwm/pwmchip0/unexport’
Could you share what you are trying to achieve by configuring the Servo.py example to run without sudo? This might help me to find out a workaround for you.
l am trying to make an object tracking using a (pan tilt camera mount) and i want to move the servo motor when it is connected to the navio 2 pins ,the movement using this script is very smooth so this is why i want to use it in my project.
thank for replying ,but i have used this solution before and you are right the script will work but the servo motor will not move , and the navio2 pin 0 will have consistent output of almost 0.17 so basically it broke my pin 0 , and after i deleted the lines of code and rebooted my navio2 the problem did not go a way so l had to re-upload the os image to solve the problem ,if there any other solution i will gladly try it on.
I suggest using the original script for servo control with this pin. It’s highly possible that there’s a software-related issue with it.
I can hardly share any other solutions for the issue in such case. Servo.py script is mainly intended to work as an example showing how to control servos. It might be better to write your own script from scratch to bypass possible issues with PWM access.