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
Traceback (most recent call last):
File "brew.py", line 4, in <module>
File "/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py", 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.
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 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 #@&$@#.
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.
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. 😁👍