How to use servo and pwm motor libraries

I want to use servo motors and control the speed of DC motors on the Jetson Nano.

from adafruit_servokit import ServoKit # Servo library that works with Jetson
import Jetson.GPIO as GPIO			       # Part of PWM DC motor control 
GPIO.setmode(GPIO.BOARD)               # Error here

Error Description:

Traceback (most recent call last):
  File "", line 4, in <module>
  File "/usr/lib/python3/dist-packages/Jetson/GPIO/", line 317, in setmode
    raise ValueError("A different mode has already been set!")
ValueError: A different mode has already been set!

If there are any libraries that are simple to set up like ServoKit for the PCA9685 board, any easy fixes to have my current code run, or even a way to not use GPIO.setmode please let me know.

1 Like

hello carlos144,

could you please confirm the pin configuration, this error indicate that there’s different mode has been set.

I’m still learning all the lingo.
Is this what you are asking for?

I have my PWM output on pin33.

hello carlos144,

it’s GPIO13/GPIO3_PE.06 by default a GPIO pin, so, had you already configure this pin as PWM?
in addition, are you able to follow the sample in Topic 178959 for testing your pin?

I configured pin 33 as pwm and I haven’t touched any other pins as far as I remember.

As for the Topic you mentioned, I did indeed get it working just today.

When I attempted to run that code along with the adafruit library it would give me that error I mentioned above.

It’s likely the AdaFruit library sets the GPIO mode already to whatever they want it to be.
Which means that you can’t use that library, and set the mode to something else.
Given that it’s open source, I imagine you can open up the code and read through it to figure out what they’re doing, if you want to attempt to change it.


I ran down that rabbit hole. Afafruit sets it in tegra SOC mode in a file called

I’ve spent three days trying to make an l298n motor driver plus an Ada fruit 9826 16 channel pwm driver board work.

Pure. Hell.

I think it comes down to frequencies and once adafruit grabs the board you’re screwed because it will set the frequencies at about 50 and then the motor driver freaks out or doesn’t work.

Really really frustrated with this. All I want is a motor driver and some servos it doesn’t seem like it should be this hard.


Yea I totally agree, at least I wasn’t the only person with this problem. Did you manage to eventually make it work or no?

I was actually just about to sit down and give it about the second to last try…

So far and I’m sure I will miss some things I have tried this…

I set up the 16-channel pwm card via i2c and I got all the servos to run I wanted.

I connected a pwm to the motor driver and freaked out everything. I got a soft reply on adafruit message board that you can’t run them off the same board because of frequencies. Servos like 50 or 60 and motors like a thousand or something like that… so I fiddled around with the frequencies and found I could get intermittent working around 400 and pulled my hair out trying to make that work for a while unsuccessfully.

Next I decided to use the Jetson pwm pins and ran directly into the problem you found. If you really study the error you can track down the file and they set it In tegra SOC mode which is what the hell? Really?

Ok…So now you have to figure out the tegra names for those pins and it’s some obscure reference somewhere I managed to find great. So I called the pins and adfruit has grabbed not just the i2c but the whole gpio and now we’re back to frequency…

Currently I can make 16 servos tap dance. I’ve actually connected a Bluetooth controller and I can spin my wheels forward or backward. But I can’t do both.

Afafruit suggested two pwm boards, you can chain them and address them but the servokit library is angles and the motor kit library doesn’t work on that board.

Seriously someone above my pay grade needs to look at this #@&$@#.

1 Like

Okay, so I was doing some searching and found this.
I haven’t tried it yet but it looks like to bypass the one frequency cap you could use two of these boards…
It will look a little funky but it should work out in the end I’d hope so.

Biggest problem is the libraries won’t do both. I decided to chunk the whole adafruit thing and just use a pie zero to control the motor with the l298n and the servos with inherent software pwm. Downside is you have to deal with jitters. Upside is it works.

So turns out I managed a very hacky way around this. I used two PCA 9685 boards to hit both the high and low frequencies at the same time since you can only use one per board.
Here is my set up:

This will likely be a temporary measure until I find a more elegant way around this library problem. Please let me know if yall have any questions or possible solutions.

1 Like

Here’s my experience with Adafruit:

  • shipping and customer service is fine
  • hardware design is fine
  • documentation is fine
  • their libraries work well as documentation of how to bring-up the hardware
  • you will want to write your own drivers for their hardware, no matter what your host hardware is (e g, Arduino, Teensy, Jetson, PC) because their goals are not generally compatible with your own performance/integration goals

When it comes to motor drivers, the L298N is very low performance – high losses, runs warm, no built-in PWM, and so on. It’s a 1970’s level chip. There are many better options. I’d suggest using a smarter controller (e g, a RoboClaw or Robotek driver) but I understand that it’s more expensive, and if dollars spent are your top priority, you would instead perhaps want something like a DRV88 based driver from either Adafruit or Pololu.

For servos, I’ve given up on hobby servos using PWM. Anything that needs to respond in real time and have controllable torque, should use a better servo protocol. Either something like a Moteus controller or an ODrive, or an integrated servo motor + controller like the Robotis variants, is vastly preferable. Motion control is hard, and expensive, because it integrates with the real world, as opposed to “pure software” which is much simpler and cheaper.


@snarky lots of good info there. I finally got my project working with two 9685 boards and a l298n. Wasn’t really looking for industrial grade just cheap and working and I got that but I appreciate the heavier duty/functionality info for later. 😁👍

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.