Qwiic_PCA9685_Py  packaging_test1-3-g6c29c10
Python for SFE Qwiic PCA9685
Loading...
Searching...
No Matches
qwiic_pca9685.QwiicPCA9685 Class Reference
Inheritance diagram for qwiic_pca9685.QwiicPCA9685:

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
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
addressThe 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
debugDesignated whether or not to print debug statements. 0- Don't print debug statements 1- Print debug statements
i2c_driverAn existing i2c driver object. If not provided a driver object is created from the 'qwiic_i2c' I2C driver of the SparkFun Qwiic library.

Member Function Documentation

◆ __readBit__()

def qwiic_pca9685.QwiicPCA9685.__readBit__ (   self,
  byte,
  bit_number 
)

This method returns the value of a specific bit in a byte.

Parameters
byteInteger or Hex value.
bit_numberThe index number of the bit you are interested in, starting from LSB = 0 to MSB = 7.
Returns
Integer Value of bit at bit_number location. (0 or 1)
:example:
    byte = 0x12 (HEX), 12h, or 16 (DEC)
    Binary: 0001 0010
    index:  7654 3210
            |       |
           MSB     LSB
    bit_number = 4
    returns: 1

◆ __writeBit__()

def qwiic_pca9685.QwiicPCA9685.__writeBit__ (   self,
  byte,
  bit_number,
  value 
)

This method modifies a specific bit in a byte, with a specified value.

Parameters
byteInteger or Hex value.
bit_numberThe index number of the bit you are interested in, starting from LSB = 0.
valueValue to be set at specific bit location (0 or 1).
Returns
Integer Value of modified byte
: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

◆ begin()

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).

Returns
Bool Function Operation True- Successful False- Issue in Execution

◆ clear_restart_bit()

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.

Returns
Integer Value of RESTART bit after changes. 0- Restart Disabled (Default) 1- Restart Enabled

NOTE: Other actions that will clear the RESTART bit are:

  1. Power cycle.
  2. I2C Software Reset command.
  3. If the MODE2 OCH bit is logic 0, write to any PWM register then issue an I2C-bus STOP.
  4. If the MODE2 OCH bit is logic 1, write to all four PWM registers in any PWM channel. Likewise, if the user does an orderly shutdown [1] of all the PWM channels before setting the SLEEP bit, the RESTART bit will be cleared. If this is done the contents of all PWM registers are invalidated and must be reloaded before reuse. [1] Two methods can be used to do an orderly shutdown. The fastest is to write a logic 1 to bit 4 in register ALL_LED_OFF_H. The other method is to write logic 1 to bit 4 in each active PWM channel LEDn_OFF_H register.

◆ enable_extclock_bit()

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.

◆ get_addr_bit()

def qwiic_pca9685.QwiicPCA9685.get_addr_bit (   self,
  addr_bit = None 
)

Reads the value of a specified address bit in MODE 1 register.

Parameters
addr_bitSpecify address bit. 0- ALLCALL Bit (Default) 1- SUB1 Bit 2- SUB2 Bit 3- SUB3 Bit
Returns
Integer Value of specified address bit. 0- Normal Mode 1- Low Power Mode; Oscillator Off. (Default)

◆ get_auto_increment_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).

Returns
Integer Value of AI bit. 0- Auto-Increment Disabled (Default) 1- Auto-Increment Enabled

◆ get_channel_word()

def qwiic_pca9685.QwiicPCA9685.get_channel_word (   self,
  channel = None,
  on_off = None 
)

Reads the ON/OFF timing for the specified PWM channel.

Parameters
channelPWM channel. 0 to 16
on_offOn or Off setting. 0- OFF Start timing (end of ON timing) 1- ON Start timing (anything greater than 0 is considered a delay)
Returns
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).

◆ get_extclock_bit()

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)
Returns
Integer Value of EXTCLK bit. 0- Use Internal Clock (Default) 1- Use EXTCLK Pin Clock.

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.

◆ get_invrt_bit()

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.

Returns
Integer Value of INVRT bits. 0- Outputs change on STOP command. 1- Outputs change on ACK.

◆ get_och_bit()

def qwiic_pca9685.QwiicPCA9685.get_och_bit (   self)

Reads the value of OCH bit in MODE 2 register.

Determines when the outputs change.

Returns
Integer 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.

◆ get_outdrv_bit()

def qwiic_pca9685.QwiicPCA9685.get_outdrv_bit (   self)

Reads the value of OUTDRV bit in MODE 2 register.

Determines how the outputs are driven.

Returns
Integer Value of OUTDRV bits. 0- Outputs are configured with an open-drain structure 1- Outputs are configured with a totem-pole structure

◆ get_outne_bits()

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.

Returns
Integer 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

◆ get_pre_scale()

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)

Returns
Integer prescale_value

NOTE: Range: 24 Hz to 1526 Hz or (0x03 to 0xFF, Default: 0x1E = 200Hz).

◆ get_restart_bit()

def qwiic_pca9685.QwiicPCA9685.get_restart_bit (   self)

Reads the value of RESTART bit in MODE 1 register.

Returns
Integer Value of Restart Mode bit. 0- Restart Disabled (Default) 1- Restart Enabled

◆ get_sleep_bit()

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.

Returns
Integer Value of SLEEP bit. 0- Normal Mode 1- Low Power Mode; Oscillator Off. (Default)

◆ is_connected()

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.

Returns
Bool Device Connection True- Successful False- Can't find device

◆ restart()

def qwiic_pca9685.QwiicPCA9685.restart (   self)

Restarts the PCA9685 after the soft reset.

(Clears MODE1 register.)

◆ restart_pwm_channels()

def qwiic_pca9685.QwiicPCA9685.restart_pwm_channels (   self)

Restarts all of the previously active PWM channels with a few I2C-bus cycles.

Returns
Integer Value of RESTART bit after changes. 0- Restart Disabled (Default) 1- Restart Enabled

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:

  1. Read MODE1 register.
  2. Check that bit 7 (RESTART) is a logic 1. If it is, clear bit 4 (SLEEP). Allow time for the oscillator to stabilize (500us).
  3. Write logic 1 to bit 7 of MODE1 register. All PWM channels will restart and the RESTART bit will clear. Remark: The SLEEP bit must be logic 0 for at least 500us, before a logic 1 is written into the RESTART bit.

◆ set_addr_bit()

def qwiic_pca9685.QwiicPCA9685.set_addr_bit (   self,
  addr_bit,
  value 
)

Writes the value to a specified address bit in MODE 1 register.

Parameters
addr_bitSpecify address bit. 0- ALLCALL Bit 1- SUB1 Bit 2- SUB2 Bit 3- SUB3 Bit
valueSpecify address bit. 0- Disables specified address (Default on SUB1, SUB2, SUB3) 1- Enables specified address (Default on ALLCALL)

◆ set_auto_increment_bit()

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).

Parameters
valueValue to set AI bit. 0- Auto-Increment Disabled (Default) 1- Auto-Increment Enabled

◆ set_channel_word()

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.

Parameters
channelPWM channel. 0 to 16
on_offON/OFF setting. 0- OFF Start timing (end of ON timing) 1- ON Start timing (anything greater than 0 is considered a delay)
valueValue to be entered into the ON/OFF 12-bit register for the specified LED output. Word (2 bytes)
Returns
Bool Function Operation True- Successful False- Issue in Execution

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).

◆ set_invrt_bit()

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.

Parameters
valueValue of INVRT bits. 0- Outputs change on STOP command. 1- Outputs change on ACK.

◆ set_och_bit()

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.

Parameters
valueValue 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.

◆ set_outdrv_bit()

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.

Parameters
valueValue of OUTDRV bits. 0- Outputs are configured with an open-drain structure 1- Outputs are configured with a totem-pole structure

◆ set_outne_bit()

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.

Parameters
valueValue 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
Returns
Bool Function Operation True- Successful False- Issue in Execution

◆ set_pre_scale()

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)

Parameters
frequencyPWM Frequency (Hz) Range: 24 to 1526 Hz
extExternal Clock Frequency (Hz) Default = None; uses internal clock frequency (25 MHz)
Returns
Bool Function Operation True- Successful False- Issue in Execution

PWM Frequency Range: 24 Hz to 1526 Hz or (0x03 to 0xFF, Default: 0x1E = 200Hz) Internal Clock: 25 MHz (Default)

◆ set_sleep_bit()

def qwiic_pca9685.QwiicPCA9685.set_sleep_bit (   self,
  value = None 
)

Changes the value of SLEEP bit in MODE 1 register.

Parameters
valueValue to set SLEEP bit. 0- Normal Mode 1- Low Power Mode; Oscillator Off. (Default)

◆ soft_reset()

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".

◆ write_restart_bit()

def qwiic_pca9685.QwiicPCA9685.write_restart_bit (   self,
  value = None 
)

Writes values to RESTART bit in MODE 1 register.

Parameters
valueValue to write to Restart Mode bit. 0 or 1
Returns
Integer Value of RESTART bit after changes. 0- Restart Disabled (Default) 1- Restart Enabled

NOTE: Value aren't set, just written. The bit is set by the state of the chip and its current operation.

Member Data Documentation

◆ address

qwiic_pca9685.QwiicPCA9685.address

◆ available_addresses

qwiic_pca9685.QwiicPCA9685.available_addresses = _AVAILABLE_I2C_ADDRESS
static

◆ available_pwm_channels

qwiic_pca9685.QwiicPCA9685.available_pwm_channels = _AVAILABLE_PWM_CHANNELS
static

◆ channel

qwiic_pca9685.QwiicPCA9685.channel

◆ debug

qwiic_pca9685.QwiicPCA9685.debug

◆ device_name

qwiic_pca9685.QwiicPCA9685.device_name = _DEFAULT_NAME
static

The documentation for this class was generated from the following file: