Jetson Nano 2GB PWM problem

Hey,

I have a Jetson nano 2GB, I’m trying to control two servo motors using the 32 & 33 PWM pinouts.
When running a simple test python code:
import Jetson.GPIO as GPIO
import time

output_pin = 33 # Servo2, Servo1 is at 32
if output_pin is None:
raise Exception(‘PWM not supported on this board’)

def main():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(output_pin, GPIO.OUT, initial=GPIO.HIGH)
p = GPIO.PWM(output_pin, 50)
val = 0
incr = 5
p.start(val)
p.stop()
GPIO.cleanup()


print(“PWM running. Press CTRL+C to exit.”)
try:
while True:
time.sleep(2)
if val >= 100:
incr = -incr
if val <= 0:
incr = -incr
val += incr
p.ChangeDutyCycle(0)
finally:
p.stop()
GPIO.cleanup()


if name == ‘main’:
main()

I get the following error:

PWM running. Press CTRL+C to exit.
Traceback (most recent call last):
File “/home/nk47/SeeShoot/tests/Servo_test.py”, line 39, in main
p.ChangeDutyCycle(0)
File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 655, in ChangeDutyCycle
self._reconfigure(self._frequency_hz, duty_cycle_percent)
File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 680, in _reconfigure
_set_pwm_duty_cycle(self._ch_info, self._duty_cycle_ns)
File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 262, in _set_pwm_duty_cycle
ch_info.f_duty_cycle.seek(0)
ValueError: I/O operation on closed file.


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
File “/home/nk47/SeeShoot/tests/Servo_test.py”, line 45, in
main()
File “/home/nk47/SeeShoot/tests/Servo_test.py”, line 41, in main
p.stop()
File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 660, in stop
_disable_pwm(self._ch_info)
File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 278, in _disable_pwm
with open(_pwm_enable_path(ch_info), ‘w’) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/sys/devices/7000a000.pwm/pwm/pwmchip0/pwm2/enable’

I have checked my L4T version using the command “sudo apt-cache show nvidia-jetpack”, and got the following output:

Package: nvidia-jetpack
Version: 4.6.1-b110
Architecture: arm64
Maintainer: NVIDIA Corporation
Installed-Size: 194
Depends: nvidia-cuda (= 4.6.1-b110), nvidia-opencv (= 4.6.1-b110), nvidia-cudnn8 (= 4.6.1-b110), nvidia-tensorrt (= 4.6.1-b110), nvidia-visionworks (= 4.6.1-b110), nvidia-container (= 4.6.1-b110), nvidia-vpi (= 4.6.1-b110), nvidia-l4t-jetson-multimedia-api (>> 32.7-0), nvidia-l4t-jetson-multimedia-api (<< 32.8-0)
Homepage: Autonomous Machines | NVIDIA Developer
Priority: standard
Section: metapackages
Filename: pool/main/n/nvidia-jetpack/nvidia-jetpack_4.6.1-b110_arm64.deb
Size: 29366

Would love to get assistance… totally stuck.

Please help :O

Pleasec check below threads to see if can help:
How to use servo and pwm motor libraries - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums
Cannot control servos through Nano - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums
Jetson Nano wiring to PWM driver for servo control. - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums

Hello and thank you for your response.
I have been to this threads before…
Unfortunately, they do not have a solution to my problem.

I would love to get assistance.

Is it okay for you to learn other kind of interface to control PWM? We are not familiar wtih the PWM code you are running now.

Also, have you changed the pinmux?

It is from that git:

“Also, have you changed the pinmux?” - I am not sure what that means :0