Datasheet
Library Reference
The driver consists of the following functions, which you can use to drive the underlying
hardware when writing your own application in Python:
Initialize Object
You can create a new object for each HAT with
pwm = PWM(0x40)
In this case, pwm (lowercase) is the object created, and PWM(0x40) is the creation call. By
default, all HATs are address 0x40, but by changing the address jumpers, you can create
objects that use other addresses such as 0x60, 0x42, etc.
setPWMFreq(self, freq)
Description
This function can be used to adjust the PWM frequency, which determines how many full
'pulses' per second are generated by the IC. Stated differently, the frequency determines
how 'long' each pulse is in duration from start to finish, taking into account both the high and
low segments of the pulse.
Frequency is important in PWM, since setting the frequency too high with a very small duty
cycle can cause problems, since the 'rise time' of the signal (the time it takes to go from 0V
to VCC) may be longer than the time the signal is active, and the PWM output will appear
smoothed out and may not even reach VCC, potentially causing a number of problems.
Arguments
freq: A number representing the frequency in Hz, between 40 and 1000
Example
The following code will set the PWM frequency to the maximum value of 1000Hz:
setPWM(self, channel, on, off)
Description
This function sets the start (on) and end (off) of the high segment of the PWM pulse on a
specific channel. You specify the 'tick' value between 0..4095 when the signal will turn on,
pwm.setPWMFreq(1000)
© Adafruit Industries
https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-
raspberry-pi
Page 18 of 25