Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 0 additions & 95 deletions Adafruit_PWM_Servo_Driver/Adafruit_I2C.py

This file was deleted.

67 changes: 0 additions & 67 deletions Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py

This file was deleted.

1 change: 1 addition & 0 deletions Adafruit_PWM_Servo_Driver/Adafruit_PWM_Servo_Driver.py
9 changes: 9 additions & 0 deletions Adafruit_PWM_Servo_Driver/ada.pca9685/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changelog
=========

0.1-dev (unreleased)
--------------------

- Initialize egg.

- Move existing Python code into egg, add symlinks.
2 changes: 2 additions & 0 deletions Adafruit_PWM_Servo_Driver/ada.pca9685/CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Daniel Havlik, Egg-packaging
Adafruit Industries, Code/Cool hardware
14 changes: 14 additions & 0 deletions Adafruit_PWM_Servo_Driver/ada.pca9685/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. contents::

Introduction
============

This is a Library supporting the Adafruit PWM Servo Driver. (PCA9685
Breakout).

The code requires python-smbus to be installed on the system.

For further documentation see
<learn.adafruit.com
`http://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/using-the-adafruit-library`>.

43 changes: 43 additions & 0 deletions Adafruit_PWM_Servo_Driver/ada.pca9685/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from setuptools import setup, find_packages
import os

version = '0.1'

long_description = (
open('README.txt').read()
+ '\n' +
'Contributors\n'
'============\n'
+ '\n' +
open('CONTRIBUTORS.txt').read()
+ '\n' +
open('CHANGES.txt').read()
+ '\n')

setup(name='ada.pca9685',
version=version,
description="Python library for interfacing the "Adafruit" PCA9685 16-Channel 12-bit PWM/Servo Driver.",
long_description=long_description,
# Get more strings from
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Programming Language :: Python",
],
keywords='',
author='Daniel Havlik',
author_email='[email protected]',
url='https://github.com/dhavlik/Adafruit-Raspberry-Pi-Python-Code',
license='bsd',
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['ada'],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
# -*- Extra requirements: -*-
],
entry_points="""
# -*- Entry points: -*-
""",
)
1 change: 1 addition & 0 deletions Adafruit_PWM_Servo_Driver/ada.pca9685/src/ada/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
68 changes: 68 additions & 0 deletions Adafruit_PWM_Servo_Driver/ada.pca9685/src/ada/pca9685/9685.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#coding:utf8

import i2c
import math
import time

DEFAULT = []

SUBADR1 = 0x02
SUBADR2 = 0x03
SUBADR3 = 0x04
MODE1 = 0x00
PRESCALE = 0xFE
LED0_ON_L = 0x06
LED0_ON_H = 0x07
LED0_OFF_L = 0x08
LED0_OFF_H = 0x09
ALLLED_ON_L = 0xFA
ALLLED_ON_H = 0xFB
ALLLED_OFF_L = 0xFC
ALLLED_OFF_H = 0xFD


class PWM(object):
"""API for interfacing an PCA9685."""

i2c = None

def __init__(self, address=0x40, bus=DEFAULT, debug=False):
params = dict(address=address, bus=bus)
if bus == DEFAULT:
# Urks: Use default bus specified in Adafruit_I2C.__init__
# signature.
# Better refactor the I2C class to take only port number.
del params['bus']
self.i2c = i2c.Adafruit_I2C(**params)
self.address = address
self.debug = debug
if (self.debug):
print "Reseting PCA9685"
self.i2c.write8(MODE1, 0x00)

def setPWMFreq(self, freq):
"""Sets the PWM frequency."""
prescaleval = 25000000.0 # 25MHz
prescaleval /= 4096.0 # 12-bit
prescaleval /= float(freq)
prescaleval -= 1.0
if (self.debug):
print "Setting PWM frequency to %d Hz" % freq
print "Estimated pre-scale: %d" % prescaleval
prescale = math.floor(prescaleval + 0.5)
if (self.debug):
print "Final pre-scale: %d" % prescale
oldmode = self.i2c.readU8(MODE1)
newmode = (oldmode & 0x7F) | 0x10 # sleep
self.i2c.write8(MODE1, newmode) # go to sleep
self.i2c.write8(PRESCALE, int(math.floor(prescale)))
self.i2c.write8(MODE1, oldmode)
time.sleep(0.005)
self.i2c.write8(MODE1, oldmode | 0x80)

def setPWM(self, channel, on, off):
"""Sets a single PWM channel."""
self.i2c.write8(LED0_ON_L + 4 * channel, on & 0xFF)
self.i2c.write8(LED0_ON_H + 4 * channel, on >> 8)
self.i2c.write8(LED0_OFF_L + 4 * channel, off & 0xFF)
self.i2c.write8(LED0_OFF_H + 4 * channel, off >> 8)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#init
Loading