Control Servo Motor with GPIO pins and PWM

I’m looking to control a Servo motor using my Libre Le Potato and the pins that support PWM. Can you provide some guidance for how to control a servo motor by hardware driven PWM via ldto tool? and is the tool only available through command line, or is there a python wrapper?

I’m really struggling with my AML-S905X-CC and using PWM on GPIO pins.

Can someone post a simple, working example of everything I need to do to use, say, pin 33 to send a simple PWM signal to a DC motor driver from a fresh install of Ubuntu (I’m using this image: ubuntu-22.04.1-preinstalled-server-arm64+aml-s905x-cc.img)?

Here’s where I’m currently stuck (connecting to the Le Potato via ssh from a Ubuntu 20.04 laptop):

ubuntu@potato:~$ sudo ldto enable pwm-a
Overlay pwm-a: applied
ubuntu@potato:~$ ls -al /sys/class/pwm/
total 0
drwxr-xr-x  2 root root 0 Jan  1  1970 .
drwxr-xr-x 76 root root 0 Jan  1  1970 ..
lrwxrwxrwx  1 root root 0 Jan  3 18:18 pwmchip0 -> ../../devices/platform/soc/c1100000.bus/c1108550.pwm/pwm/pwmchip0
ubuntu@potato:~$ echo {0,1} > /sys/class/pwm/pwmchip0/export
-bash: /sys/class/pwm/pwmchip0/export: Permission denied
ubuntu@potato:~$ sudo echo {0,1} > /sys/class/pwm/pwmchip0/export
-bash: /sys/class/pwm/pwmchip0/export: Permission denied

I’ve tried to do this as the root user (e.g. sudo su -) with the same results.

For context, I’m trying to use python-periphery (both Python v3 and Periphery were installed via apt) to tell a DC motor driver to turn a DC motor.

ubuntu@potato:~$ python3 ./testmotor.py 
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/periphery/pwm.py", line 65, in _open
    with open(os.path.join(chip_path, "export"), "w") as f_export:
PermissionError: [Errno 13] Permission denied: '/sys/class/pwm/pwmchip0/export'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/./testmotor.py", line 5, in <module>
    pwm = PWM(0,1)
  File "/usr/lib/python3/dist-packages/periphery/pwm.py", line 39, in __init__
    self._open(chip, channel)
  File "/usr/lib/python3/dist-packages/periphery/pwm.py", line 68, in _open
    raise PWMError(e.errno, "Exporting PWM channel: " + e.strerror)
periphery.pwm.PWMError: [Errno 13] Exporting PWM channel: Permission denied

Anyway, I appreciate any suggestions anyone can provide.

Thanks!

You need to echo 0 or 1.

For ROC-RK3328-CC, I am not seeing any PWM overlays, just i2c0, spi0-cs1-spidev, spi0-cs1, spi0 . Is this something that has to be manually created for the Renegade?

1 Like