Skip to content

Latest commit

 

History

History
133 lines (105 loc) · 4.54 KB

README.md

File metadata and controls

133 lines (105 loc) · 4.54 KB

Qwiic_PCA9685_Py

follow on Twitter

SparkFun Servo pHAT for the Raspberry Pi

Python module for the PCA9685 PWM controller, which is part of the SparkFun Servo pHAT for Raspberry Pi and SparkFun Pi Servo HAT

This package should be used in conjunction with the overall SparkFun qwiic Python Package. New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.

Contents

Supported Platforms

The qwiic PCA9685 Python package current supports the following platforms:

Dependencies

This package depends on the qwiic I2C driver: Qwiic_I2C_Py

Documentation

The SparkFun qwiic PCA9685 module documentation is hosted at ReadTheDocs

Installation

PyPi Installation

This repository is hosted on PyPi as the sparkfun-qwiic-pca9685 package. On systems that support PyPi installation via pip, this library is installed using the following commands

For all users (note: the user must have sudo privileges):

sudo pip install sparkfun-qwiic-pca9685

For the current user:

pip install sparkfun-qwiic-pca9685

Local Installation

To install, make sure the setuptools package is installed on the system.

Direct installation at the command line:

python setup.py install

To build a package for use with pip:

python setup.py sdist

A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.

cd dist
pip install sparkfun_qwiic_pca9685-<version>.tar.gz
  

Example Use

See the examples directory for more detailed use examples.

import qwiic_pca9685
import time
import math
import sys

def runExample():

	print("\nSparkFun PCA9685 Example 1\n")
	mySensor = qwiic_pca9685.QwiicPCA9685()

	if mySensor.is_connected() == False:
		print("The Qwiic PCA9685 device isn't connected to the system. Please check your connection", \
			file=sys.stderr)
		return

	mySensor.begin()
  
	# Sets PWM Frequency to 50 Hz
	mySensor.set_pre_scale(50)
  
	# Sets start time of PWM pulse on Channel 0 to 0s
	mySensor.set_channel_word(0, 1, 0)


	while True:
		# Increments start time of PWM pulse on Channel 0 to i (1ms to 2ms)
		for i in range(205, 410):
			fun.set_channel_word(0, 0, i)
			# Delay .05 s
			time.sleep(.1)

		# Decrements start time of PWM pulse on Channel 0 to i (2ms to 1ms)
		for i in range(410, 205, -1):
			fun.set_channel_word(0, 0, i)
			# Delay .05 s
			time.sleep(.1)
		
		time.sleep(1)

SparkFun - Start Something