PiServoHat_Py
Python for SFE Qwiic PiServoHat
Loading...
Searching...
No Matches
pi_servo_hat.PiServoHat Class Reference

SparkFun PiServoHat Initialise the qwiic_pca9685 python module at address with i2c_driver. More...

Inheritance diagram for pi_servo_hat.PiServoHat:

Public Member Functions

def __init__ (self, address=None, debug=None, min_pt=1, max_pt=2)
 This method initializes the class object. More...
 
def is_connected (self)
 Is an I2C connection established with the device? More...
 
def restart (self)
 Soft resets the chip and then clears the MODE1 register to restart the PWM functionality. More...
 
def get_pwm_frequency (self)
 Reads the PWM frequency used on outputs. More...
 
def set_pwm_frequency (self, frequency=None)
 Configures the PWM frequency used on outputs. More...
 
def get_pulse_time (self)
 Reads and returns the current min and max pulse times for servo movement. More...
 
def set_pulse_time (self, min_pulse_time, max_pulse_time)
 Updates the minimum and maximum pulse widths for the servos. More...
 
def move_servo_position (self, channel, position, swing=None)
 Moves servo to specified location in degrees. More...
 
def set_duty_cycle (self, channel, duty_cycle)
 Moves servo to specified location based on duty-cycle. More...
 
def get_servo_position (self, channel, swing=None)
 Reads the specified location for the servo in degrees. More...
 
def sleep (self)
 Set the SLEEP bit to 1, which will unpower the servos. More...
 
def wake (self)
 Set the SLEEP bit to 0, which will power the servos. More...
 

Public Attributes

 address
 
 debug
 
 PCA9685
 
 available_pwm_channels
 
 minimum_pulse_width
 
 maximum_pulse_width
 

Static Public Attributes

 device_name = _DEFAULT_NAME
 
 available_addresses = _AVAILABLE_I2C_ADDRESS
 
int gcAddr = 0x00
 
int acAddr = 0x70
 
int subAddr_1 = 0x71
 
int subAddr_2 = 0x72
 
int subAddr_3 = 0x74
 
 frequency = _DEFAULT_SERVO_FREQUENCY
 

Detailed Description

SparkFun PiServoHat Initialise the qwiic_pca9685 python module at address with i2c_driver.

Parameters
addressThe I2C address to use for the device. If not provided, the default address is used.
i2c_driverAn existing i2c driver object. If not provided a driver object is created.
Returns
Bool Constructor Initialization True- Successful False- Issue loading I2C driver

Constructor & Destructor Documentation

◆ __init__()

def pi_servo_hat.PiServoHat.__init__ (   self,
  address = None,
  debug = None,
  min_pt = 1,
  max_pt = 2 
)

This method initializes the class object.

If no 'address' or 'i2c_driver' are inputed 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
min_ptThe minimum pulse time of the servos in milliseconds. If not provided, default to 1 ms
max_ptThe maximum pulse time of the servos in milliseconds. If not provided, default to 2 ms

Member Function Documentation

◆ get_pulse_time()

def pi_servo_hat.PiServoHat.get_pulse_time (   self)

Reads and returns the current min and max pulse times for servo movement.

Returns: tuple: The minimum and maximum pulse times in milliseconds

◆ get_pwm_frequency()

def pi_servo_hat.PiServoHat.get_pwm_frequency (   self)

Reads the PWM frequency used on outputs.

50 Hz is recommended for most servos.

Returns
Integer PWM Frequency Range: 24 Hz to 1526 Hz

◆ get_servo_position()

def pi_servo_hat.PiServoHat.get_servo_position (   self,
  channel,
  swing = None 
)

Reads the specified location for the servo in degrees.

Parameters
channelChannel of Servo to Control Range: 0 to 15
swingRange of Servo Movement 90- 90 Degree Servo 180- 180 Degree Servo
Returns
Float Esitmated Position (Degrees)

◆ is_connected()

def pi_servo_hat.PiServoHat.is_connected (   self)

Is an I2C connection established with the device?

Returns
Bool Device Connection Status True- Connected False- Not Connected

◆ move_servo_position()

def pi_servo_hat.PiServoHat.move_servo_position (   self,
  channel,
  position,
  swing = None 
)

Moves servo to specified location in degrees.

Parameters
channelChannel of Servo to Control Range: 0 to 15
positionPosition (Degrees) Range: Open, but should between 0 and specified servo 'swing'. The range is not regulated because most servos have extra room for play (i.e. a 90 degree servo may have a +120 degree usable swing). If 'None' is specified, the default setting is 90 degrees.
swingRange of Servo Movement 90- 90 Degree Servo 180- 180 Degree Servo

◆ restart()

def pi_servo_hat.PiServoHat.restart (   self)

Soft resets the chip and then clears the MODE1 register to restart the PWM functionality.

The PWM frequency is returned to the default 50 Hz setting.

◆ set_duty_cycle()

def pi_servo_hat.PiServoHat.set_duty_cycle (   self,
  channel,
  duty_cycle 
)

Moves servo to specified location based on duty-cycle.

Parameters
channelChannel of Servo to Control Range: 0 to 15
duty_cycleDuty-Cycle (Percentage) Float Range: 0 to 100 (%) Resolution: 1/4096

◆ set_pulse_time()

def pi_servo_hat.PiServoHat.set_pulse_time (   self,
  min_pulse_time,
  max_pulse_time 
)

Updates the minimum and maximum pulse widths for the servos.

Args: min_pulse_time (float): The new minimum pulse width in ms max_pulse_time (float): The new maximum pulse width in ms

Returns: bool: Returns true if update was successful, false if an error was encountered

◆ set_pwm_frequency()

def pi_servo_hat.PiServoHat.set_pwm_frequency (   self,
  frequency = None 
)

Configures the PWM frequency used on outputs.

50 Hz is the default and recommended for most servos.

Parameters
frequencyPWM Frequency Range: 24 Hz to 1526 Hz
Returns
Bool Function Operation True- Successful False- Issue in Execution

NOTE: Changing PWM frequency affects timing for servo positioning. Additionally, the servo position needs to be reset for the output control (on all channels). The output on all channels is initially turned off after the frequency change, but is re-enabled after any of the channels is reconfigured. However, the new PWM frequency will be in affect, so the timing of the outputs on the other channels will be off. (i.e. if a PWM frequency is doubled; the timing of that signal may be halfed.)

◆ sleep()

def pi_servo_hat.PiServoHat.sleep (   self)

Set the SLEEP bit to 1, which will unpower the servos.

This preserves the life of the servos.

◆ wake()

def pi_servo_hat.PiServoHat.wake (   self)

Set the SLEEP bit to 0, which will power the servos.

Member Data Documentation

◆ acAddr

int pi_servo_hat.PiServoHat.acAddr = 0x70
static

◆ address

pi_servo_hat.PiServoHat.address

◆ available_addresses

pi_servo_hat.PiServoHat.available_addresses = _AVAILABLE_I2C_ADDRESS
static

◆ available_pwm_channels

pi_servo_hat.PiServoHat.available_pwm_channels

◆ debug

pi_servo_hat.PiServoHat.debug

◆ device_name

pi_servo_hat.PiServoHat.device_name = _DEFAULT_NAME
static

◆ frequency

pi_servo_hat.PiServoHat.frequency = _DEFAULT_SERVO_FREQUENCY
static

◆ gcAddr

int pi_servo_hat.PiServoHat.gcAddr = 0x00
static

◆ maximum_pulse_width

pi_servo_hat.PiServoHat.maximum_pulse_width

◆ minimum_pulse_width

pi_servo_hat.PiServoHat.minimum_pulse_width

◆ PCA9685

pi_servo_hat.PiServoHat.PCA9685

◆ subAddr_1

int pi_servo_hat.PiServoHat.subAddr_1 = 0x71
static

◆ subAddr_2

int pi_servo_hat.PiServoHat.subAddr_2 = 0x72
static

◆ subAddr_3

int pi_servo_hat.PiServoHat.subAddr_3 = 0x74
static

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