import onionPwm
Since Omega firmware build 195, the Omega2 family supports up to 4 oboard PWM channels through the linux /sys interface. However, unlike the PWM Expansion Board, there was no Python 3 compatible library for interfacing with these channels. The onionPwm library does fix this problem by providing easy access to the PWM channels.
-
Change the frequency and duty cycle of each PWM channel (See Usage)
-
Provides methods to enable/disable each PWM channel (See Usage)
-
Context manager support
-
Python 3 compatible
channel = onionPwm.OnionPwm( channel , chip=0 , force=False )
-
If the PWM channel specified with
channeldoes not exist, you will getOSError: [Errno 19] No such device -
If the PWM chip specified with
chipdoes not exist, you will getFileNotFoundError -
force = Trueignores if the corresponding PWM chnnel is busy. Useful if the previous user forgot to call release(), but may lead to errors if the channel is still in use. -
When not using a context manager, call
release()at the end to release the PWM channel
channel.set_frequency( frequency in Hz )
- If the choosen frequency is not supported by the PWM chip, you will get
Permission Error: [Errno 1] Operation not permitted
channel.get_frequency() --> frequency in Hz
The result may slightly vary from the value set with setFrequency() due to rounding
channel.set_period( period in ns )
-
Similar to
set_frequency(), but instead accepts values in ns -
If
periodis zero or negative, you will getOSError: [Errno 22] Invalid argument -
When
periodis smaller than the current channel duty cycle, you will getOSError: [Errno 22] Invalid argument
Please use setFrequency() instead of setPeriod() for normal operation
channel.get_period() --> Period in ns
- Similar to
get_frequency(), but instead returns values in ns
channel.set_duty_cycle( dutyCycle in percent )
- When no frequency is set,
set_cycleandget_duty_cycle()will always set/reportchannel.get_duty_cycle()--> duty cycle in percent
channel.set_cycle( cycle in ns )
-
Similar to
set_duty_cycle(), but instead accepts values in ns -
When
cycleis negative, you will getOSError: [Errno 22] Invalid argument -
When
cycleis greater than the current channel period, you will getOSError: [Errno 22] Invalid argument
Please use setDutyCycle() instead of setCycle() for normal operation
channel.get_cycle() --> duty cycle in ns
- Similar to
get_duty_cycle(), but instead returns values in ns
The result may slightly vary from the value set with setDutyCycle() due to rounding
channel.enable()
channel.disable()
- enable / disable the channel
is_enabled() --> True or False
-
onionPwm.toNsec( frequency in Hz )converts a frequency in Hz into the corresponding period in ns -
onionPwm.toHz( period in ns )converts a period in ns into the corresponding frequency in Hz
- Python 3.5+
This project is licensed under the LGPL License - see the LICENSE file for details
- Armin W. Wer-Wolf
- Read the Article about the PWM on how to enabling the corresponding PWM pins