Here is my testing code:
from periphery import PWM
import time
# Open PWM channel 0, pin 0
pwm = PWM(0,0)
# Set frequency to 1 kHz
pwm.frequency = 50
# Set duty cycle to 75%
pwm.duty_cycle = 0.02
pwm.enable()
print(pwm.period)
print(pwm.frequency)
print(pwm.enabled)
# Change duty cycle to 50%
pwm.duty_cycle = 0.05
pwm.close()
Problem is this part:
# Open PWM channel 0, pin 0
pwm = PWM(0,0)
I can see output when running PWM(0,0) PWM(0,1) PWM(0,2)
but I get the error messsage when trying to run the following:
PWM(1,1)
PWM(2,2)
mendel@elusive-jet:/sys/class/pwm$ sudo python3 /usr/lib/python3/dist-packages/edgetpuvision/testPWM.py
OSError: [Errno 19] No such device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/periphery/pwm.py", line 69, in _open
f_export.write("%d\n" % pin)
OSError: [Errno 19] No such device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/edgetpuvision/testPWM.py", line 5, in <module>
pwm = PWM(1,1)
File "/usr/local/lib/python3.5/dist-packages/periphery/pwm.py", line 44, in __init__
self._open(channel, pin)
File "/usr/local/lib/python3.5/dist-packages/periphery/pwm.py", line 71, in _open
raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror)
periphery.pwm.PWMError: [Errno 19] Exporting PWM pin: No such device
Based off the document from both Coral and the library site: https://coral.withgoogle.com/tutorials/devboard-gpio/
https://github.com/vsergeev/python-periphery
The
PWM(1,1)
PWM(2,2)
should have worked without issue, I can see the following directories existed:
"\sys\class\pwm\pwmchip0"
"\sys\class\pwm\pwmchip1"
"\sys\class\pwm\pwmchip2"
In the python-periphery source code https://github.com/vsergeev/python-periphery/blob/master/periphery/pwm.py
it should getting the path as following:
PWM(1,1) ===> /sys/class/pwm/pwmchip1/pwm1 if pwm1 not exists, then it should call the export to generate it.
So, My main question are:
- What is
channelandpinand how it is been used ? - Why I'm not able to get PWM(1,1) PWM(2,2) to work ?
Thank you in advance.
---------------2019.4.2 Update--------------------
I figured out the previous answer by myself (and thank you for anyone who provided help).
But as you can see from my own answer, I'm still not able to get the PWM to work as it is not output stable Voltage. (You can check out more detail below).
I'm currently running into another issue in which the output voltage are not stable at all. So, here is what I did to test:
I set up both Raspberry Pi 3+ Model B and the EdgeTPU Coral Board with 50hz PWM with 5% duty cycle. Since both device have GPIO output 3.3V, My theory is, their output should be identical, but they are NOT.
Here are the voltage measured by using a Arduino UNO board: Pi vs. EdgeTPU. (Note: all the voltage should be divide by 10). You can see there is a clear pattern(PWM) in the Pi output, alternating around 1.8v. but if you look at the EdgeTPU output, you can see the voltage is all over the places and it is much lower voltage (1.1v vs 1.8v).
it clearly to me something wrong with the EdgeTPU PWM output, So I did further research. found out from the (limited) document, it says
All GPIO pins have a 90k pull-down resistor inside the iMX8M SOC that is used by default during bootup, except for the I2C pins, which instead have a pull-up to 3.3V on the SOM. However, these can all be changed with a device tree overlay that loads after bootup.
Which lead me suspect the 90k pull-down resistor might have lower the output voltage due to the fact of this formula V=IR. So, I'm thinking change the device tree overlay at bootup as it instructed. but, guess what, there is no documents on how to change it besides the following line from the overlays.txt file:
# List of device tree overlays to load. Format: overlay=<dtbo name, no extenstion> <dtbo2> ...
overlay=
I have searched all over the place, there is no document regarding to how does Mendel Linux device tree overlay should be configured. so, I'm currently stuck, If you know the answer, please share it, I would much appreciated.
I will share this question to the Coral Support team as well to see if they will get me any response.(FYI, I did send something to them back when I posted the original question, haven't hear anything from them yet, even tho their website says We try to respond to inquiries within one business day — but often you'll get a response even quicker, usually a few hours.) so, wish me luck. Will keep this answer updated if hear anything back.
Here is the passage/question I would like to convey to Google/Google Cloud/Google EdgeTPU/Google Coral Board teams also:
- Why choose python-periphery as the default library to implement GPIO and PWM ?
- Why choose the Mendel Linux as the default OS, when there is no site/document or any sort to be found ?