API Reference¶
pi_servo_hat¶
Python module for the [SparkFun Pi Servo HAT](https://www.sparkfun.com/products/14328) and [SparkFun Servo pHAT for Raspberry Pi](https://www.sparkfun.com/products/15316). This package should be used in conjunction with the sparkfun_pca9685 package.
-
class
pi_servo_hat.
PiServoHat
(address=None, debug=None)[source]¶ SparkFun PiServoHat Initialise the qwiic_pca9685 python module at
address
withi2c_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: Constructor Initialization True- Successful False- Issue loading I2C driver rtype: Bool -
get_pwm_frequency
()[source]¶ Reads the PWM frequency used on outputs. 50 Hz is recomended for most servos.
Returns: PWM Frequency Range: 24 Hz to 1526 Hz Return type: Integer
-
get_servo_position
(channel, swing=None)[source]¶ Reads the specified location for the servo in degrees.
Parameters: - channel – Channel of Servo to Control Range: 0 to 15
- swing – Range of Servo Movement 90- 90 Degree Servo 180- 180 Degree Servo
Returns: Esitmated Position (Degrees)
Return type: Float
-
move_servo_position
(channel, position, swing=None)[source]¶ Moves servo to specified location in degrees.
Parameters: - channel – Channel of Servo to Control Range: 0 to 15
- position – Position (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.
- swing – Range of Servo Movement 90- 90 Degree Servo 180- 180 Degree Servo
-
restart
()[source]¶ 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
(channel, duty_cycle)[source]¶ Moves servo to specified location based on duty-cycle.
Parameters: - channel – Channel of Servo to Control Range: 0 to 15
- duty_cycle – Duty-Cycle (Percentage) Float Range: 0 to 100 (%) Resolution: 1/4096
-
set_pwm_frequency
(frequency=None)[source]¶ Configures the PWM frequency used on outputs. 50 Hz is the default and recomended for most servos.
Parameters: frequency – PWM Frequency Range: 24 Hz to 1526 Hz Returns: Function Operation True- Successful False- Issue in Execution Return type: Bool 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.)
-