Servo motor control on the Jetson Xavier NX GPIO Header Pins

Hello, has anyone successfully controlled a servo motor directly connected on the jetson xavier nx gpio header pins? With no external hardware! If so how did you achieve it? Any help and suggestions would be appreciated. Python (preferably python 2) and C++ code are most preferrable.

I already did pinmux changes on the pinmux excel spreadsheet and flashed the Jetson (JetPack : 4.6) - just incase.

I have tried Jetson-GPIO. The motor turns roughly but not as expected. Below is some sample code. Using an SG-5010 for testing in case there’s something I maybe missing:

import Jetson.GPIO as GPIO
import time

control = [5,5.5,6,6.5,7,7.5,8,8.5, 9, 9.5, 10]

# control =  [6.25, 7, 7.5, 8, 8.5]

servo = 33 # connect to pwm pin


GPIO.setup(servo, GPIO.OUT)
# in servo motor,
# 1ms pulse for 0 degree (LEFT)
# 1.5ms pulse for 90 degree (MIDDLE)
# 2ms pulse for 180 degree (RIGHT)

# so for 50hz, one frequency is 20ms
# duty cycle for 0 degree = (1/20)*100 = 5%
# duty cycle for 90 degree = (1.5/20)*100 = 7.5% 
# duty cycle for 180 degree = (2/20)*100 = 10%    

p=GPIO.PWM(servo,50) # 50hz frequency

p.start(2.5) # starting duty cycle ( it set the servo to 0 degree )

       while True:
           for x in range(len(control)):
             print control[x]

           for x in range(len(control)-1,0,-1):
             print control[x]

except KeyboardInterrupt:


this should be issue follow-up of Topic 198975.

Yes @JerryChang, in fact I checked the signal before and after connecting the motor. It seems the generated signal is fine before connecting the motor. But after connecting the motor to the Jetson, It becomes entirely something different. What could the cause of this? For example, an LED works fine with PWM but ta motor does not. Also how can I solve this? Is there a way?

Another issue, even after stopping the script and performing a GPIO.cleanup, the Pin keeps generating a signal with the most previous value. Is it supposed to work that way, or is it supposed to stop generating the signal on the pin?

hello user105768,

may I confirm which pin you’re used, is it pin-32 of the 40-pin expansion header?
if yes, this pin is… GPIO07 / SOC_GPIO44 / GP_PWM8

you’ll need to did pinmux changes on the pinmux excel spreadsheet and flashed the Jetson, note, the -r options should be exclude to apply the configurations correctly.
after that, could you please configure the PWM via sysfs and share the results.
for example,
$ cd /sys/devices/32f0000.pwm/pwm/pwmchip3/
$ echo 0 > export
$ cd pwm0
$ echo xxx > period && echo xxx > duty_cycle
$ echo 1 > enable

PWM8’s clock parent is pllp_out0, which is 102Mhz; the possible rate of a PWM controller is… 48.63Hz to 398.4Mhz;
in pwm driver, period is in terms of nanoseconds, you’ll also need do the Hz to ns conversion then apply the settings.
taking an example,
if you’re going to configure 50Hz, 10%, you should set the values as following,
i.e. $ echo 20000000 > period && echo 2000000 > duty_cycle

Hello, I did pinmux changes on the pinmux excel spreadsheet and flashed the jetson using the tool provided after installing the sdkmanager.
note, the -r options should be exclude to apply the configurations correctly. I do not understand this part. But i configured both pin 32 and 33 as PWM.
I am using pin 33 at the moment. but running the script shows that both pin 32 and 33 are pwm.
There is no
$ cd /sys/devices/32f0000.pwm/pwm/pwmchip3/

But I can:
$ cd /sys/devices/32f0000.pwm/pwm/pwmchip4/
Should i continue? Only pwmchip4 is the available option.

hello user105768,

Jetson Xavier NX has four PWM outputs,
for example,

and… you should also refer to Xavier Series SoC Technical Reference Manual,
you might check session-3.1.2 for the system address map, there’s shows the start address of those PWMs.
for example,
GPIO07 / GP_PWM8 / 0x32f0000
GPIO12 / GP_PWM4 / 0xc340000
GPIO13 / GP_PWM1 / 0x3280000
GPIO14 / GP_PWM6 / 0x32d0000

so, the software node under /sys/devices/32f0000.pwm/ is actually using GP_PWM8
please test your use-case accordingly, thanks

I performed those operations for pin 33: /sys/devices/3280000.pwm/pwm/pwmchip0
The motor rotates a bit. then begins to shake and rotate a rather slowly. The same happens when I change duty cycle to 5% and 7.5%. It never stays calmly in one place or significantly switch position.