![]() |
Qwiic_PCA9685_Py
packaging_test1-3-g6c29c10
Python for SFE Qwiic PCA9685
|
Public Member Functions | |
def | __init__ (self, address=None, debug=None, i2c_driver=None) |
This method initializes the class object. More... | |
def | __readBit__ (self, byte, bit_number) |
This method returns the value of a specific bit in a byte. More... | |
def | __writeBit__ (self, byte, bit_number, value) |
This method modifies a specific bit in a byte, with a specified value. More... | |
def | is_connected (self) |
This method checks if the "i2c_driver" can connect to the device at the specified or default address. More... | |
def | get_addr_bit (self, addr_bit=None) |
Reads the value of a specified address bit in MODE 1 register. More... | |
def | set_addr_bit (self, addr_bit, value) |
Writes the value to a specified address bit in MODE 1 register. More... | |
def | get_sleep_bit (self) |
Reads the value of SLEEP bit in MODE 1 register. More... | |
def | set_sleep_bit (self, value=None) |
Changes the value of SLEEP bit in MODE 1 register. More... | |
def | get_auto_increment_bit (self) |
Reads the value of AI bit in MODE 1 register. More... | |
def | set_auto_increment_bit (self, value=None) |
Changes value of AI bit in MODE 1 register. More... | |
def | get_extclock_bit (self) |
Reads the value of EXTCLK bit in MODE 1 register. More... | |
def | get_restart_bit (self) |
Reads the value of RESTART bit in MODE 1 register. More... | |
def | write_restart_bit (self, value=None) |
Writes values to RESTART bit in MODE 1 register. More... | |
def | get_outne_bits (self) |
Reads the value of OUTNE bits in MODE 2 register. More... | |
def | set_outne_bit (self, value=None) |
Reads the value of OUTNE bits in MODE 2 register. More... | |
def | get_outdrv_bit (self) |
Reads the value of OUTDRV bit in MODE 2 register. More... | |
def | set_outdrv_bit (self, value=None) |
Reads value of OUTDRV bits in MODE 2 register. More... | |
def | get_och_bit (self) |
Reads the value of OCH bit in MODE 2 register. More... | |
def | set_och_bit (self, value=None) |
Reads the value of OCH bits in MODE 2 register. More... | |
def | get_invrt_bit (self) |
Reads the value of INVRT bit in MODE 2 register. More... | |
def | set_invrt_bit (self, value=None) |
Configures value of INVRT bits in MODE 2 register. More... | |
def | get_channel_word (self, channel=None, on_off=None) |
Reads the ON/OFF timing for the specified PWM channel. More... | |
def | set_channel_word (self, channel=None, on_off=None, value=None) |
Configures the on/off timing for the specified PWM channel. More... | |
def | begin (self) |
This method checks if there is an I2C connection then enables the Auto-Increment bit for the writing/reading of words (for the output timing). More... | |
def | soft_reset (self) |
Software Reset Call: Allows all the devices in the I2C bus to be reset to the power-up state value through a specific formatted I2C bus command. More... | |
def | restart (self) |
Restarts the PCA9685 after the soft reset. More... | |
def | get_pre_scale (self) |
Reads the frequency at which the output are modulated. More... | |
def | set_pre_scale (self, frequency=None, ext=None) |
Configures the 'prescale_value', which defines the frequency at which the output are modulated. More... | |
def | clear_restart_bit (self) |
If RESTART bit is a logic 1, it clears RESTART bit in MODE 1 register by writing a logic 1. More... | |
def | restart_pwm_channels (self) |
Restarts all of the previously active PWM channels with a few I2C-bus cycles. More... | |
def | enable_extclock_bit (self) |
Changes value of EXTCLK bit in MODE 1 register to enable EXTCLK pin. More... | |
Public Attributes | |
address | |
debug | |
channel | |
Static Public Attributes | |
device_name = _DEFAULT_NAME | |
available_addresses = _AVAILABLE_I2C_ADDRESS | |
available_pwm_channels = _AVAILABLE_PWM_CHANNELS | |
SparkFunPCA9685
Initialise the PCA9685 chip at address
with i2c_driver
.
@param address: The I2C address to use for the device. If not provided, the default address is used. @param i2c_driver: An existing i2c driver object. If not provided a driver object is created. @return **Bool** Constructor Initialization True- Successful False- Issue loading I2C driver
def qwiic_pca9685.QwiicPCA9685.__init__ | ( | self, | |
address = None , |
|||
debug = None , |
|||
i2c_driver = None |
|||
) |
This method initializes the class object.
If no 'address' or 'i2c_driver' are inputted or 'None' is specified, the method will use the defaults.
address | The I2C address to use for the device. If not provided, the method will default to the first address in the 'available_addresses' list. Default = 0x40 |
debug | Designated whether or not to print debug statements. 0- Don't print debug statements 1- Print debug statements |
i2c_driver | An existing i2c driver object. If not provided a driver object is created from the 'qwiic_i2c' I2C driver of the SparkFun Qwiic library. |
def qwiic_pca9685.QwiicPCA9685.__readBit__ | ( | self, | |
byte, | |||
bit_number | |||
) |
This method returns the value of a specific bit in a byte.
byte | Integer or Hex value. |
bit_number | The index number of the bit you are interested in, starting from LSB = 0 to MSB = 7. |
:example: byte = 0x12 (HEX), 12h, or 16 (DEC) Binary: 0001 0010 index: 7654 3210 | | MSB LSB bit_number = 4 returns: 1
def qwiic_pca9685.QwiicPCA9685.__writeBit__ | ( | self, | |
byte, | |||
bit_number, | |||
value | |||
) |
This method modifies a specific bit in a byte, with a specified value.
byte | Integer or Hex value. |
bit_number | The index number of the bit you are interested in, starting from LSB = 0. |
value | Value to be set at specific bit location (0 or 1). |
:example: Original Byte: byte = 0x12 (HEX), 12h, or 16 Binary: 0001 0010 index: 7654 3210 | | MSB LSB Change: bit_number = 4 value = 0 Output Byte: returns: 2 Binary: 0000 0010
def qwiic_pca9685.QwiicPCA9685.begin | ( | self | ) |
This method checks if there is an I2C connection then enables the Auto-Increment bit for the writing/reading of words (for the output timing).
def qwiic_pca9685.QwiicPCA9685.clear_restart_bit | ( | self | ) |
If RESTART bit is a logic 1, it clears RESTART bit in MODE 1 register by writing a logic 1.
NOTE: Other actions that will clear the RESTART bit are:
def qwiic_pca9685.QwiicPCA9685.enable_extclock_bit | ( | self | ) |
Changes value of EXTCLK bit in MODE 1 register to enable EXTCLK pin.
Once enabled, it allows for an external clock signal. It also affects the refresh rate:
EXTCLK refresh_rate = ---------------------- 4096 x (prescale +1)
NOTE: This EXTCLK bit is a "sticky bit", that is, it cannot be cleared by writing a logic 0 to it. The EXTCLK can only be cleared by a power cycle or software reset.
def qwiic_pca9685.QwiicPCA9685.get_addr_bit | ( | self, | |
addr_bit = None |
|||
) |
Reads the value of a specified address bit in MODE 1 register.
addr_bit | Specify address bit. 0- ALLCALL Bit (Default) 1- SUB1 Bit 2- SUB2 Bit 3- SUB3 Bit |
def qwiic_pca9685.QwiicPCA9685.get_auto_increment_bit | ( | self | ) |
Reads the value of AI bit in MODE 1 register.
When enabled, it allows users to write of multiple bytes (i.e. words).
def qwiic_pca9685.QwiicPCA9685.get_channel_word | ( | self, | |
channel = None , |
|||
on_off = None |
|||
) |
Reads the ON/OFF timing for the specified PWM channel.
channel | PWM channel. 0 to 16 |
on_off | On or Off setting. 0- OFF Start timing (end of ON timing) 1- ON Start timing (anything greater than 0 is considered a delay) |
NOTE: There are two 12-bit registers per LED output. Both registers will hold a value from 0 to 4095. One 12-bit register will hold a value for the ON time and the other 12-bit register will hold the value for the OFF time.
The ON and OFF times are compared with the value of a 12-bit counter that will be running continuously from 0000h to 0FFFh (0 to 4095 decimal).
def qwiic_pca9685.QwiicPCA9685.get_extclock_bit | ( | self | ) |
Reads the value of EXTCLK bit in MODE 1 register.
When enabled, it allows for an external clock signal. It also affects the refresh rate:
EXTCLK refresh_rate = ---------------------- 4096 x (prescale +1)
NOTE: This bit is a "sticky bit", that is, it cannot be cleared by writing a logic 0 to it. The EXTCLK can only be cleared by a power cycle or software reset.
def qwiic_pca9685.QwiicPCA9685.get_invrt_bit | ( | self | ) |
Reads the value of INVRT bit in MODE 2 register.
Determines how the outputs are driven. See Section 7.7 "Using the PCA9685 with and without external drivers" of the datasheet.
def qwiic_pca9685.QwiicPCA9685.get_och_bit | ( | self | ) |
Reads the value of OCH bit in MODE 2 register.
Determines when the outputs change.
def qwiic_pca9685.QwiicPCA9685.get_outdrv_bit | ( | self | ) |
Reads the value of OUTDRV bit in MODE 2 register.
Determines how the outputs are driven.
def qwiic_pca9685.QwiicPCA9685.get_outne_bits | ( | self | ) |
Reads the value of OUTNE bits in MODE 2 register.
When the active LOW output (OE pin) is enabled, this setting allows users to enable or disable all the LED outputs at the same time.
def qwiic_pca9685.QwiicPCA9685.get_pre_scale | ( | self | ) |
Reads the frequency at which the output are modulated.
The prescale value is determined by Eq 1 (below).
Eq 1: osc_clock prescale value = round(-------------------—) - 1 (4096 * update_rate)
NOTE: Range: 24 Hz to 1526 Hz or (0x03 to 0xFF, Default: 0x1E = 200Hz).
def qwiic_pca9685.QwiicPCA9685.get_restart_bit | ( | self | ) |
Reads the value of RESTART bit in MODE 1 register.
def qwiic_pca9685.QwiicPCA9685.get_sleep_bit | ( | self | ) |
Reads the value of SLEEP bit in MODE 1 register.
When enabled, it the chip there is no PWM control.
def qwiic_pca9685.QwiicPCA9685.is_connected | ( | self | ) |
This method checks if the "i2c_driver" can connect to the device at the specified or default address.
def qwiic_pca9685.QwiicPCA9685.restart | ( | self | ) |
Restarts the PCA9685 after the soft reset.
(Clears MODE1 register.)
def qwiic_pca9685.QwiicPCA9685.restart_pwm_channels | ( | self | ) |
Restarts all of the previously active PWM channels with a few I2C-bus cycles.
NOTE: Only if the PCA9685 was operating and the user put the chip to sleep (setting MODE1 bit 4) without stopping any of the PWM channels, the RESTART bit (MODE1 bit 7) will be set to logic 1 at the end of the PWM refresh cycle. The contents of each PWM register are held valid when the clock is off. Uses the following steps:
def qwiic_pca9685.QwiicPCA9685.set_addr_bit | ( | self, | |
addr_bit, | |||
value | |||
) |
Writes the value to a specified address bit in MODE 1 register.
addr_bit | Specify address bit. 0- ALLCALL Bit 1- SUB1 Bit 2- SUB2 Bit 3- SUB3 Bit |
value | Specify address bit. 0- Disables specified address (Default on SUB1, SUB2, SUB3) 1- Enables specified address (Default on ALLCALL) |
def qwiic_pca9685.QwiicPCA9685.set_auto_increment_bit | ( | self, | |
value = None |
|||
) |
Changes value of AI bit in MODE 1 register.
When enabled, it allows users to write of multiple bytes (i.e. words).
value | Value to set AI bit. 0- Auto-Increment Disabled (Default) 1- Auto-Increment Enabled |
def qwiic_pca9685.QwiicPCA9685.set_channel_word | ( | self, | |
channel = None , |
|||
on_off = None , |
|||
value = None |
|||
) |
Configures the on/off timing for the specified PWM channel.
channel | PWM channel. 0 to 16 |
on_off | ON/OFF setting. 0- OFF Start timing (end of ON timing) 1- ON Start timing (anything greater than 0 is considered a delay) |
value | Value to be entered into the ON/OFF 12-bit register for the specified LED output. Word (2 bytes) |
NOTE: There are two 12-bit registers per LED output. Both registers will hold a value from 0 to 4095. One 12-bit register will hold a value for the ON time and the other 12-bit register will hold the value for the OFF time. The ON and OFF times are compared with the value of a 12-bit counter that will be running continuously from 0000h to 0FFFh (0 to 4095 decimal).
def qwiic_pca9685.QwiicPCA9685.set_invrt_bit | ( | self, | |
value = None |
|||
) |
Configures value of INVRT bits in MODE 2 register.
Configures how the outputs are driven. See Section 7.7 "Using the PCA9685 with and without external drivers" of the datasheet.
value | Value of INVRT bits. 0- Outputs change on STOP command. 1- Outputs change on ACK. |
def qwiic_pca9685.QwiicPCA9685.set_och_bit | ( | self, | |
value = None |
|||
) |
Reads the value of OCH bits in MODE 2 register.
Configures when the outputs change.
value | Value of OCH bits. 0- Outputs change on STOP command. NOTE: Change of the outputs at the STOP command allows synchronizing outputs of more than one PCA9685. Applicable to registers from 06h (LED0_ON_L) to 45h (LED15_OFF_H) only. 1 or more registers can be written, in any order, before STOP. 1- Outputs change on ACK. NOTE: Update on ACK requires all 4 PWM channel registers to be loaded before outputs will change on the last ACK. |
def qwiic_pca9685.QwiicPCA9685.set_outdrv_bit | ( | self, | |
value = None |
|||
) |
Reads value of OUTDRV bits in MODE 2 register.
Configures how the outputs are driven.
value | Value of OUTDRV bits. 0- Outputs are configured with an open-drain structure 1- Outputs are configured with a totem-pole structure |
def qwiic_pca9685.QwiicPCA9685.set_outne_bit | ( | self, | |
value = None |
|||
) |
Reads the value of OUTNE bits in MODE 2 register.
When the active LOW output (OE pin) is enabled, this setting allows users to enable or disable all the LED outputs at the same time.
value | Value of OUTNE bits. When OE = 1: 0- LEDn = 0 1- If OUTDRV = 1 then LEDn = 1 If OUTDRV = 0 then LEDn = high-impedence (same as OUTNE[1:0] = b'10') 2 to 3- LEDn = high-impedence |
def qwiic_pca9685.QwiicPCA9685.set_pre_scale | ( | self, | |
frequency = None , |
|||
ext = None |
|||
) |
Configures the 'prescale_value', which defines the frequency at which the output are modulated.
The prescale value is determined by Eq 1 (below). Additionally, the hardware enforces a minimum value that can be loaded into this register is '3'.
Eq 1: osc_clock prescale value = round(-------------------—) - 1 (4096 * update_rate)
frequency | PWM Frequency (Hz) Range: 24 to 1526 Hz |
ext | External Clock Frequency (Hz) Default = None; uses internal clock frequency (25 MHz) |
PWM Frequency Range: 24 Hz to 1526 Hz or (0x03 to 0xFF, Default: 0x1E = 200Hz) Internal Clock: 25 MHz (Default)
def qwiic_pca9685.QwiicPCA9685.set_sleep_bit | ( | self, | |
value = None |
|||
) |
Changes the value of SLEEP bit in MODE 1 register.
value | Value to set SLEEP bit. 0- Normal Mode 1- Low Power Mode; Oscillator Off. (Default) |
def qwiic_pca9685.QwiicPCA9685.soft_reset | ( | self | ) |
Software Reset Call: Allows all the devices in the I2C bus to be reset to the power-up state value through a specific formatted I2C bus command.
General Call Address | SWRST data byte 1 Start | | Stop | | | | [S][0000 0000][A][0000 0110][A][P] | | Acknowledge from Slave | Acknowledge from Slave
PCA9685 then resets to the default value (power-up value) and is ready to be addressed again within the specified bus free time. A failure or non-acknowledge from the PCA9685 (at any time) should be interpreted as an "SWRST Call Abort".
def qwiic_pca9685.QwiicPCA9685.write_restart_bit | ( | self, | |
value = None |
|||
) |
Writes values to RESTART bit in MODE 1 register.
value | Value to write to Restart Mode bit. 0 or 1 |
NOTE: Value aren't set, just written. The bit is set by the state of the chip and its current operation.
qwiic_pca9685.QwiicPCA9685.address |
|
static |
|
static |
qwiic_pca9685.QwiicPCA9685.channel |
qwiic_pca9685.QwiicPCA9685.debug |
|
static |