Does anyone have an example of a Python program using PWM? For example pwm with frequency of 1000Hz and duty cycle of 50%. I installed the pwm overlay but no idea how to do the Python program. I know exatly how to do the pwm program in Raspberry pi, pic etc etc
Are you using a BBB and where are the files located for pwm?
Are the pwm files on Linux located at /dev/bone/pwm/
?
Seth
It gets pretty simple and straitforward, when using libpruio. Check example pwm_cap in syntax python.
The board is BeagleY-AI
The files are not at /dev/bone/pwm. I am not sure where they are. I dont want to use the Adafruit library. I just want to know how to implement PWM on BeagleY-AI using Pyrhon
I guess it rather at /dev/hat/pwm
Try the docs pwm example
Unfortunately its not in Python, also did not work on BeagleY-AI
Just go through the tutorial carefully. Don’t miss the overlays
part.
To check loaded overlays use:
debian@BeagleBone:~$ sudo beagle-version | grep UBOOT
UBOOT: Booted Device-Tree:[k3-am67a-beagley-ai.dts]
UBOOT: Loaded Overlay:[k3-am67a-beagley-ai-pwm-epwm1-gpio20.kernel]
Export header pin 38
(GPIO20) and set the period
and duty_cycle
in nanoseconds. Then enable it:
debian@BeagleBone:~$ sudo beagle-pwm-export --pin hat-38
debian@BeagleBone:~$ echo 20000000 > /dev/hat/pwm/GPIO20/period
debian@BeagleBone:~$ echo 1500000 > /dev/hat/pwm/GPIO20/duty_cycle
debian@BeagleBone:~$ echo 1 > /dev/hat/pwm/GPIO20/enable
With Python File Write api:
def write_file(path, value):
f = open(path, "w")
f.write(str(value))
f.close()
write_file("/dev/hat/pwm/GPIO20/period", 20000000)
write_file("/dev/hat/pwm/GPIO20/duty_cycle", 1500000)
write_file("/dev/hat/pwm/GPIO20/enable", 1)
Hi Illia
I have included the overlay at the end of file /boot/firmware/extlinux/extlinux.conf” as:
fdtoverlays /overlays/k3-am67a-beagley-ai-pwm-epwm1-gpio20.dtbo
but I cannot see the overlay in UBOOT command. I only see the: UBOOT: Booted Device-Tree:[k3-am67a-beagley-ai.dts]
Any ideas? What am I doing wrong?
Hi Illia
Its all working now, thanks a lot for your help.