How do I use PWM on Jetson Nano?

Now I’m trying to control a motor by using PWM.
I searched for the information, and I found that 4 pins in J15 can be used as PWM outputs.
However, I don’t know how to control these pins.
Can I control them by using Jetson.GPIO library?

Thanks in advance for the help

Check out the article below. They uses RPi.GPIO for PWM on Raspberry Pi. The Jetson.GPIO library is supposed to be code compatible with RPi.GPIO and also Raspberry Pi pin compatible. Haven’t yet tried it, but plan to in the near furture.

Thank you for your information, but when I tried the code in the website, I got the error that module ‘Jetson.GPIO’ has no attribute ‘PWM’.

And, in /opt/nvidia/jetson-gpio/doc/README.txt,
“The Jetson GPIO library provides all public APIs provided by the RPi.GPIO library with the exception of the Software PWM APIs”.
Does this mean that it is impossible to control PWM by using Jetson.GPIO?

In this case, how can I control PWM output pins.

That is a major bummer. Thanks for trying it out. Hopefully nvidia may have some updates to include PWM in the Jetson.gpio library or they may have another way to handle it. I need PWM capability for my project too.

Raspbery pi have the following PWM support:

Pin 12 – PWM-0,channel-0
Pin 32 – PWM-0,channel-1

Pin 33 – PWM-1,channel-0
Pin 35 – PWM-1,channel-1

if Jetson Nano indeed is using the same layout, you should able to enable those as well. so, two PWM pin with two channel each.

but, I did further research by checking the actually device by ls /sys/class/pwm
I got pwmchip0 pwmchip4

if you cd to pwmchip0 and cat npwm you will get 4, which means pwmchip0 have 4 channel, and then if you do the same for pwmchip4 you will get 1, which means pwmchip4 only have 1 channel. So, that is different than Raspberry Pi layout. So, there are total 5 channels (vs. 4 channel from Pi)

Theoretically, if you know which pin is each channel is corresponding to, you can use it without problem. Hope there are some official answer here.

Jetson Nano Pin layout

Pi Pin layout

hi all,

FYI,
you might also check the Jetson Nano Pinmux Table for the pinmux configuration and also for new system customize design.
thanks

I am able to use the pin 33 as pwm but cant do same for pin 32,getting the following error:

Traceback (most recent call last):
File “ras.py”, line 44, in
main()
File “ras.py”, line 20, in main
p = GPIO.PWM(output_pin, 100)
File “/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py”, line 595, in init
_export_pwm(self._ch_info)
File “/usr/local/lib/python3.6/dist-packages/Jetson/GPIO/gpio.py”, line 231, in _export_pwm
f.write(str(ch_info.pwm_id))
OSError: [Errno 16] Device or resource busy

I am using two dc motors to control a robot.

1 Like

hello sagar16eligar,

let’s tracking at the discussion thread you had just initialize, Topic 1066485.
thanks

How do I solve the above issue?

Hey Sagar,
I hope you are well. Can you share with how you control your dc motor speed?
Thank you!

Regards
Aans

1 Like

in file “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio_pin_data.py”:
it says:

# Older versions of L4T have a DT bug which instantiates a bogus device
# which prevents this library from using this PWM channel.
(168, {}, "6000d000.gpio", 32, 12, 'GPIO07', 'LCD_BL_PW', '7000a000.pwm', 0),
(38, {}, "6000d000.gpio", 33, 13, 'GPIO13', 'GPIO_PE6', '7000a000.pwm', 2),
1 Like

AFAICS only pins 32 and 33 are PWM capable on the Jetson Nano. And you need to run /opt/nvidia/jetson-io/jetson-io.py to enable PWM on those pins.

3 Likes