Adafruit PCA9685 Library Documentation

Similar documents
Adafruit NeoPixel Library Documentation

Adafruit 16-Channel Servo Driver with Arduino

Adafruit 8-Channel PWM or Servo FeatherWing

Adafruit 16-Channel Servo Driver with Arduino

Adafruit SGP30 TVOC/eCO2 Gas Sensor

Adafruit 16-channel PWM/Servo Shield

Adafruit 16-Channel Servo Driver with Arduino

CodeBug I2C Tether Documentation

Adafruit 16-channel PWM/Servo Shield

Adafruit 16 Channel Servo Driver with Raspberry Pi

Servo click. PID: MIKROE 3133 Weight: 32 g

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

Motor Driver HAT User Manual

I2C Demonstration Board LED Dimmers and Blinkers PCA9531 and PCA9551

Introduction to the Arduino Kit

LED Driver 5 click. PID: MIKROE 3297 Weight: 25 g

EVDP610 IXDP610 Digital PWM Controller IC Evaluation Board

ESE 350 HEXAWall v 2.0 Michelle Adjangba Omari Maxwell

Micropython on ESP8266 Workshop Documentation

Hello, and welcome to this presentation of the FlexTimer or FTM module for Kinetis K series MCUs. In this session, you ll learn about the FTM, its

ZKit-51-RD2, 8051 Development Kit

System Board 6219 MAXREFDES89#: MAX14871 Full-Bridge DC Motor Driver MBED Shield

LED Driver 4 click. PID: MIKROE 3037 Weight: 25 g

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

RGB Driver click. PID: MIKROE 3078 Weight: 28 g

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Lab Timer: Blinking LED Lights and Pulse Generator

RB-Dev-03 Devantech CMPS03 Magnetic Compass Module

I 2 C RedBot & DC Motor Servo Motor Control

MD04-24Volt 20Amp H Bridge Motor Drive

Training Schedule. Robotic System Design using Arduino Platform

LP3943/LP3944 as a GPIO Expander

PAK-VIIIa Pulse Coprocessor Data Sheet by AWC

ZIO Python API. Tutorial. 1.1, May 2009

P01A BAROMETER MODULE Version: 1.1

Course Introduction. Content 20 pages 3 questions. Learning Time 30 minutes

DALI slave, one to four channels PWM and I2C output

Micropython on ESP8266 Workshop Documentation

LM4: The timer unit of the MC9S12DP256B/C

INA3221 Breakout Board

1. Introduction Block diagram 5

RX23T inverter ref. kit

NI 272x Help. Related Documentation. NI 272x Hardware Fundamentals

DEMO CIRCUIT 976 LT3476EUHF. Quadruple High Power LED Driver in Buck Mode DESCRIPTION. PERFORMANCE SUMMARY Specifications are at TA = 25 C

Castle Creations, INC.

Gravity: 12-Bit I2C DAC Module SKU: DFR0552

Variable Frequency Drive / Inverter (0.4 ~ 280kW)

Learning Objectives. References 10/26/11. Using servos with an Arduino. EAS 199A Fall 2011

Lab Exercise 9: Stepper and Servo Motors

MD03-50Volt 20Amp H Bridge Motor Drive

Using Servos with an Arduino

MiniProg Users Guide and Example Projects

STPDRV-1 Stepper Motor Driver Data Sheet (R1.0) BFF Design Ltd

Introduction. Theory of Operation

Activity 4: Due before the lab during the week of Feb

Lab 12: Timing sequencer (Version 1.3)

J. La Favre Controlling Servos with Raspberry Pi November 27, 2017

PAK-Vb/c PWM Coprocessor Data Sheet by AWC

ArduCAM USB Camera Shield

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Laboratory Exercise 1 Microcontroller Board with Driver Board

Fixed-function (FF) implementation for PSoC 3 and PSoC 5 devices

L13: (25%), (20%), (5%) ECTE333

Debugging a Boundary-Scan I 2 C Script Test with the BusPro - I and I2C Exerciser Software: A Case Study

Brushless 5 click. PID: MIKROE 3032 Weight: 25 g

IS31FL3236A 36-CHANNEL LED DRIVER; SELECTABLE PWM FREQUENCY IS31FL3236A. February 2018

PWM Guide: Zen Buzzer and Tri-Colour LEDs For Linux Kernel 4.1+ Table of Contents. by Brian Fraser Last update: November 17, 2017

EVAL-ADM8843. Evaluation Board for Charge Pump Driver for LCD White LED Backlights. Preliminary Technical Data

THE IMPORTANCE OF PLANNING AND DRAWING IN DESIGN

Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor

Copley ASCII Interface Programmer s Guide

7 OUT1 8 OUT2 9 OUT3 10 OUT4 11 OUT5 12 OUT6 13 OUT7 14 OUT8 15 OUT9 16 OUT10 17 OUT11 18 OUT12 19 OUT13 20 OUT14 21 OUT15 22 OUT16 OUT17 23 OUT18

IS31FL3209 IS31FL CHANNELS LED DRIVER; 1/24 DC SCALING WHITE BALANCE. December 2017

Rochester Institute of Technology Real Time and Embedded Systems: Project 2a

DC Brushed Motor Controller Module EDP-AM-MC1

ASCII Programmer s Guide

Pi Servo Hat Hookup Guide

WifiBotics. An Arduino Based Robotics Workshop

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

For more information on these functions and others please refer to the PRONET-E User s Manual.

Fading a RGB LED on BeagleBone Black

ESP32 Utility Driver

IS31FL3190 IS31FL CHANNEL FUN LED DRIVER. Preliminary Information November 2015

APDS-9960 RGB and Gesture Sensor Hookup Guide

DC Motor and Servo motor Control with ARM and Arduino. Created by:

Digital Fundamentals 8/25/2016. Summary. Summary. Floyd. Chapter 1. Analog Quantities

Hardware Flags. and the RTI system. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Group #17 Arian Garcia Javier Morales Tatsiana Smahliuk Christopher Vendette

USER S GUIDE POLOLU A4988 STEPPER MOTOR DRIVER CARRIER USING THE DRIVER POWER CONNECTIONS

µchameleon 2 User s Manual

IS31FL3206 IS31FL CHANNEL LED DRIVER; SELECTABLE PWM FREQUENCY. Preliminary Information May 2018

RGB strips.

I2C Encoder. HW v1.2

IS31FL3208A 18-CHANNEL LED DRIVER; SELECTABLE PWM FREQUENCY. August 2018

16 Channels LED Driver

PWM System. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Direct Current Waveforms

Data Conversion and Lab Lab 3 Spring Analog to Digital Converter

Design Document. Team 63: Anthony Shvets and Zhe Tang TA: Zipeng Wang ECE 445 Spring 2018

LC-10 Chipless TagReader v 2.0 August 2006

Transcription:

Adafruit PCA9685 Library Documentation Release 1.0 Radomir Dopieralski Aug 25, 2018

Contents 1 Dependencies 3 2 Usage Example 5 3 Contributing 7 4 Building locally 9 4.1 Sphinx documentation.......................................... 9 5 Table of Contents 11 5.1 Simple test................................................ 11 5.2 adafruit_pca9685......................................... 13 5.2.1 Implementation Notes..................................... 14 6 Indices and tables 15 Python Module Index 17 i

ii

Adafruit PCA9685 Library Documentation, Release 1.0 Driver for the PCA9685, a 16-channel, 12-bit PWM chip Contents 1

Adafruit PCA9685 Library Documentation, Release 1.0 2 Contents

CHAPTER 1 Dependencies This driver depends on: Adafruit CircuitPython Bus Device Register Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle. 3

Adafruit PCA9685 Library Documentation, Release 1.0 4 Chapter 1. Dependencies

CHAPTER 2 Usage Example See examples/pca9685_simpletest.py for a demo of the usage. 5

Adafruit PCA9685 Library Documentation, Release 1.0 6 Chapter 2. Usage Example

CHAPTER 3 Contributing Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming. 7

Adafruit PCA9685 Library Documentation, Release 1.0 8 Chapter 3. Contributing

CHAPTER 4 Building locally To build this library locally you ll need to install the circuitpython-build-tools package. python3 -m venv.env source.env/bin/activate pip install circuitpython-build-tools Once installed, make sure you are in the virtual environment: source.env/bin/activate Then run the build: circuitpython-build-bundles --filename_prefix adafruit-circuitpython-pca9685 -- library_location. 4.1 Sphinx documentation Sphinx is used to build the documentation based on rst files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above): python3 -m venv.env source.env/bin/activate pip install Sphinx sphinx-rtd-theme Now, once you have the virtual environment activated: cd docs sphinx-build -E -W -b html. _build/html This will output the documentation to docs/_build/html. Open the index.html in your browser to view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to locally verify it will pass. 9

Adafruit PCA9685 Library Documentation, Release 1.0 10 Chapter 4. Building locally

CHAPTER 5 Table of Contents 5.1 Simple test Ensure your device works with this simple test. Listing 1: examples/pca9685_simpletest.py 1 # This simple test outputs a 50% duty cycle PWM single on the 0th channel. Connect an LED and 2 # resistor in series to the pin to visualize duty cycle changes and its impact on brightness. 3 4 from board import SCL, SDA 5 import busio 6 7 # Import the PCA9685 module. 8 from adafruit_pca9685 import PCA9685 9 10 # Create the I2C bus interface. 11 i2c_bus = busio.i2c(scl, SDA) 12 13 # Create a simple PCA9685 class instance. 14 pca = PCA9685(i2c_bus) 15 16 # Set the PWM frequency to 60hz. 17 pca.frequency = 60 18 19 # Set the PWM duty cycle for channel zero to 50%. duty_cycle is 16 bits to match other PWM objects 20 # but the PCA9685 will only actually give 12 bits of resolution. 21 pca.channels[0].duty_cycle = 0x7fff 11

Adafruit PCA9685 Library Documentation, Release 1.0 Listing 2: examples/calibration.py 1 # This advanced example can be used to compute a more precise reference_clock_speed. Use an 2 # oscilloscope or logic analyzer to measure the signal frequency and type the results into the 3 # prompts. At the end it'll give you a more precise value around 25 mhz for your reference clock 4 # speed. 5 6 import time 7 8 from board import SCL, SDA 9 import busio 10 11 # Import the PCA9685 module. 12 from adafruit_pca9685 import PCA9685 13 14 # Create the I2C bus interface. 15 i2c_bus = busio.i2c(scl, SDA) 16 17 # Create a simple PCA9685 class instance. 18 pca = PCA9685(i2c_bus) 19 20 # Set the PWM frequency to 100hz. 21 pca.frequency = 100 22 23 input("press enter when ready to measure default frequency.") 24 25 # Set the PWM duty cycle for channel zero to 50%. duty_cycle is 16 bits to match other PWM objects 26 # but the PCA9685 will only actually give 12 bits of resolution. 27 print("running with default calibration") 28 pca.channels[0].duty_cycle = 0x7fff 29 time.sleep(1) 30 pca.channels[0].duty_cycle = 0 31 32 measured_frequency = float(input("frequency measured: ")) 33 print() 34 35 pca.reference_clock_speed = pca.reference_clock_speed * (measured_frequency / pca. frequency) 36 # Set frequency again so we can get closer. Reading it back will produce the real value. 37 pca.frequency = 100 38 39 input("press enter when ready to measure coarse calibration frequency.") 40 pca.channels[0].duty_cycle = 0x7fff 41 time.sleep(1) 42 pca.channels[0].duty_cycle = 0 43 measured_after_calibration = float(input("frequency measured: ")) 44 print() 45 46 reference_clock_speed = measured_after_calibration * 4096 * pca.prescale_reg 47 48 print("real reference clock speed: {0:.0f}".format(reference_clock_speed)) 12 Chapter 5. Table of Contents

Adafruit PCA9685 Library Documentation, Release 1.0 Listing 3: examples/servo.py 1 # This example moves a servo its full range (180 degrees by default) and then back. 2 3 from board import SCL, SDA 4 import busio 5 6 # Import the PCA9685 module. 7 from adafruit_pca9685 import PCA9685 8 9 # This example also relies on the Adafruit motor library available here: 10 # https://github.com/adafruit/adafruit_circuitpython_motor 11 from adafruit_motor import servo 12 13 i2c = busio.i2c(scl, SDA) 14 15 # Create a simple PCA9685 class instance. 16 pca = PCA9685(i2c) 17 pca.frequency = 50 18 19 # To get the full range of the servo you will likely need to adjust the min_pulse and max_pulse to 20 # match the stall points of the servo. 21 # This is an example for the Sub-micro servo: https://www.adafruit.com/product/2201 22 # servo7 = servo.servo(pca.channels[7], min_pulse=580, max_pulse=2480) 23 # This is an example for the Micro Servo - High Powered, High Torque Metal Gear: 24 # https://www.adafruit.com/product/2307 25 # servo7 = servo.servo(pca.channels[7], min_pulse=600, max_pulse=2400) 26 # This is an example for the Standard servo - TowerPro SG-5010-5010: 27 # https://www.adafruit.com/product/155 28 # servo7 = servo.servo(pca.channels[7], min_pulse=600, max_pulse=2500) 29 # This is an example for the Analog Feedback Servo: https://www.adafruit.com/product/ 1404 30 # servo7 = servo.servo(pca.channels[7], min_pulse=600, max_pulse=2600) 31 32 # The pulse range is 1000-2000 by default. 33 servo7 = servo.servo(pca.channels[7]) 34 35 for i in range(180): 36 servo7.angle = i 37 for i in range(180): 38 servo7.angle = 180 - i 39 pca.deinit() 5.2 adafruit_pca9685 Driver for the PCA9685 PWM control IC. Its commonly used to control servos, leds and motors. See also: The Adafruit CircuitPython Motor library can be used to control the PWM outputs for specific uses instead of generic duty_cycle adjustments. Author(s): Scott Shawcroft 5.2. adafruit_pca9685 13

Adafruit PCA9685 Library Documentation, Release 1.0 5.2.1 Implementation Notes Hardware: Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685 (Product ID: 815) Software and Dependencies: Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: circuitpython/releases Adafruit s Bus Device library: https://github.com/adafruit/adafruit_circuitpython_busdevice Adafruit s Register library: https://github.com/adafruit/adafruit_circuitpython_register https://github.com/adafruit/ class adafruit_pca9685.pca9685(i2c_bus, *, address=64, reference_clock_speed=25000000) Initialise the PCA9685 chip at address on i2c_bus. The internal reference clock is 25mhz but may vary slightly with environmental conditions and manufacturing variances. Providing a more precise reference_clock_speed can improve the accuracy of the frequency and duty_cycle computations. See the calibration.py example for how to derive this value by measuring the resulting pulse widths. Parameters i2c_bus (I2C) The I2C bus which the PCA9685 is connected to. address (int) The I2C address of the PCA9685. reference_clock_speed (int) The frequency of the internal reference clock in Hertz. channels = None Sequence of 16 PWMChannel objects. One for each channel. deinit() Stop using the pca9685. frequency The overall PWM frequency in Hertz. reference_clock_speed = None The reference clock speed in Hz. reset() Reset the chip. class adafruit_pca9685.pcachannels(pca) Lazily creates and caches channel objects as needed. Treat it like a sequence. class adafruit_pca9685.pwmchannel(pca, index) A single PCA9685 channel that matches the PWMOut API. duty_cycle 16 bit value that dictates how much of one cycle is high (1) versus low (0). 0xffff will always be high, 0 will always be low and 0x7fff will be half high and then half low. frequency The overall PWM frequency in Hertz (read-only). A PWMChannel s frequency cannot be set individually. All channels share a common frequency, set by PCA9685.frequency. 14 Chapter 5. Table of Contents

CHAPTER 6 Indices and tables genindex modindex search 15

Adafruit PCA9685 Library Documentation, Release 1.0 16 Chapter 6. Indices and tables

Python Module Index a adafruit_pca9685, 13 17

Adafruit PCA9685 Library Documentation, Release 1.0 18 Python Module Index

Index A adafruit_pca9685 (module), 13 C channels (adafruit_pca9685.pca9685 attribute), 14 D deinit() (adafruit_pca9685.pca9685 method), 14 duty_cycle (adafruit_pca9685.pwmchannel attribute), 14 F frequency (adafruit_pca9685.pca9685 attribute), 14 frequency (adafruit_pca9685.pwmchannel attribute), 14 P PCA9685 (class in adafruit_pca9685), 14 PCAChannels (class in adafruit_pca9685), 14 PWMChannel (class in adafruit_pca9685), 14 R reference_clock_speed (adafruit_pca9685.pca9685 attribute), 14 reset() (adafruit_pca9685.pca9685 method), 14 19