I have asked this question on the Discussions on the Jetbot GitHub but have received no response.
Presently Adafruit is using a PWM switching frequency of 50Hz which is fine for servos, but causes an annoying whine from my Jetbot’s DC motors.
Therefore I would like to know where in the Adafruit motor driver packages can I change the PWM switching frequency from 50Hz to around 2k-2.5kHz?
Apparently the Jetbot 0.4.3 image no longer stores the Adafruit_MotorHAT packages here: “/usr/local/lib/python3.6/dist-packages/Adafruit_MotorHAT-1.4.0-py3.6.egg/Adafruit_MotorHAT/Adafruit_MotorHAT_Motors.py” as the “dist-packages” directory is empty now.
Thanks for the information, but does not answer my requirement for where the Jetbot v 4.3 image is storing the Adafruit_MotorHAT package.
Jetbot uses the I2C bus to communicate with the PCA9685 IC on the Adafruit Featherwing motor controller so the Nano GPIO bus, in this case, has nothing to do with controlling a motor driver directly like the example above.
Prior to the Jebot v 0.4.3 image, the Adafruit_MotorHAT package was stored at “/usr/local/lib/python3.6/dist-packages/Adafruit_MotorHAT-1.4.0-py3.6.egg/Adafruit_MotorHAT/Adafruit_MotorHAT_Motors.py”. In the Jetbot v 0.4.3, “/usr/local/lib/python3.6/dist-packages/ is now empty and devoid of any packages. So where have the installed packages been moved to?
Thanks for the information, however my request has nothing to do with the Nano GPIO bus and the use of the GPIO bus to generate PWM signals for a motor driver.
The Jetbot v 0.4.3 image uses the Nano 4GB I2C bus to communicate with the PCA9685 servo driver on the Adafruit FeatherWing Motor Controller board. The Jetbot v 0.4.3 image communicates with the FeatherWing Motor Controller board using the Adafruit_MotorHAT library package. Prior to Jetbot v 0.4.3 the Adafruit_MotorHAT library package was stored at “/usr/local/lib/python3.6/dist-packages/Adafruit_MotorHAT-1.4.0-py3.6.egg/Adafruit_MotorHAT/Adafruit_MotorHAT_Motors.py” The Jetbot v 0.4.3 image no longer stores the Adafruit_MotorHAT library package at that location as “/usr/local/lib/python3.6/dist-packages/" is empty in the Jebot v 4.3 image.
jetbot@nano-4gb-jp45:/usr/local/lib/python3.6/dist-packages$ ls -al
total 8
drwxrwsr-x 2 root staff 4096 May 18 2018 .
drwxrwsr-x 3 root staff 4096 May 18 2018 …
jetbot@nano-4gb-jp45:/usr/local/lib/python3.6/dist-packages$
Therefore I would like to know where the Jetbot v 0.4.3 image is storing the Adafruit_MotorHAT library package so that I can adjust the PCA9685 servo board’s PWM switching frequency as I have stated above.
I’m not sure off hand where the python package for the JetBot v0.4.3 image are located, but the following command might help you discover this
python3 -c "import setuptools as _; print(_.__path__)"
On a side note, it seems that the Adafruit_MotorHat library actually exposes an API for setting the PWM frequency.
Another option might be to modify the JetBot library to call this as needed, and re-install the JetBot package. For example, I believe you could do this in the motor.py class and do this in the constructor.
Please let me know if this helps or you still run into any issues or questions.
When you say “frequency”, do you the actual PWM transmitted value or the PWM switching frequency which is the rate that the PWM value is transmitted at?
jetbot@nano-4gb-jp45:~$ python3 -c “import setuptools as ; print(.path)”
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘setuptools’
Also sending python3 -c “import Adafruit_MotorHAT as ; print(.path)” resulted in:
jetbot@nano-4gb-jp45:~$ python3 -c “import Adafruit_MotorHAT as ; print(.path)”
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘Adafruit_MotorHAT’
From what I can tell, the Jetbot 0.4.3 image was built using Docker and the Python code being run in the Jupyter Notebooks is located in the Docker environment.
Setup.py in the jetbot directory requires the installation of Adafruit_MotorHAT library and the Adafruit-SSD1306 library, however I have yet to determine where those libraries are installed in Docker or the Containers. I have searched the IoT, but no joy. Any suggestions will be greatly appreciated.
I have inspected both of the Jetbot Containers and have found that the Jetbot Repo should be in /opt/jetbot, however there is no Jetbot directory in the opt directory.
I had the same question as you had about where to find the Adafruit_MotorHAT package (in Jetbot 4.3) in order to change the motor.py file so the motors of my Waveshare Jetbot AI Kit would run more smoothly.
When I logged into the Jetbot using PuTTY I found, just like you, an empty Adafruit directory.
But when I used the $_Terminal within JupyterLab (under: + new launcher) I could locate the file you mention in your post:
/usr/local/lib/python3.6/dist-packages/Adafruit_MotorHAT-1.4.0-py3.6.egg/Adafruit_MotorHAT/Adafruit_MotorHAT_Motors.py
I found the motor.py file which I was looking for in:
/usr/local/lib/python3.6/dist-packages/jetbot-0.4.3-py3.6.egg/jetbot
I used the Vi editor within the JupiterLab notebook to change the motor.py file.
Thanks for the suggestion, but that is exactly what I did a while back only to find that the PWM frequency of the PCA9685 servo driver was already set at its maximum of 1,600 Hz. I tried lower switching frequencies but that did not reduce the motor whine when starting and running. Most good Motor Driver modules, like the Dimension Engineer Sabertooth line, use PWM switching frequencies above 20kHz. I may try putting a 100 pf ceramic capacitor across the motor terminals as they are being driven by a L298N motor driver module.
Looking into the Adafruit_MotorHAT library, which has the calls for the motor controller, I can set the PWM using the following call. This call works because the Robot class instantiates an Adafruit_MotorHAT object. This object has a set PWMFreq method, which we can call right after instantiating the robot object:
A PWM frequency of 100 Hz seems to stop the whining!