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 "brew.py", line 4, in <module>
GPIO.setmode(GPIO.BOARD)
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 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?
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 pin.py.
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.
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.
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.
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. šš