PCA9685 PWM expansion - mcworkshop

Vai ai contenuti

PCA9685 PWM expansion

Technical Pages
Wiring diagram I
PCA 9685
Connection: SCL to A5 and SDA to A4

Select addresses to add more expansions
A0 open = 0x40
A0 close = 0x41
A0 open but A1 close = 0x42
A0 close and A1 close = 0x43

Example library
Library to control a PCA9685 16-channel PWM driver module from an Arduino board.
Licensed under the copy-left GNU GPL v3 license.
Created by Kasper Skårhøj, August 3rd, 2012.
Forked by Vitska, June 18th, 2016.
Forked by NachtRaveVL, July 29th, 2016.

#include <Wire.h>
#include "PCA9685.h"

PCA9685 pwmController;                  // Library using default Wire and default linear phase balancing scheme

void setup() {

   Wire.begin();                       // Wire must be started first
   Wire.setClock(400000);              // Supported baud rates are 100kHz, 400kHz, and 1000kHz

   pwmController.resetDevices();       // Software resets all PCA9685 devices on Wire line

   pwmController.init(B000000);        // Address pins A5-A0 set to B000000
   pwmController.setPWMFrequency(100); // Default is 200Hz, supports 24Hz to 1526Hz

   pwmController.setChannelPWM(0, 128 << 4); // Set PWM to 128/255, but in 4096 land

   Serial.println(pwmController.getChannelPWM(0)); // Should output 2048, which is 128 << 4

Software License Agreement (BSD License)
Copyright (c) 2012, Adafruit Industries
All rights reserved.

NXP Semiconductor
16-channel, 12-bit PWM Fm+ I2C-bus LED controller
Rev. 4 — 16 April 2015 Product data sheet

All servomotor 0 degree angle

// all servomotor 0 degree angle
//by MCW 2018
//public domain code GNU
#include <Wire.h>
#include "PCA9685.h"
PCA9685 driver;
PCA9685_ServoEvaluator pwmServo(100, 300, 500);
void setup() {
void loop() {
 driver.setChannelPWM(1, pwmServo.pwmForAngle(60));//basso anteriore sn pronto per spinta
 driver.setChannelPWM(2, pwmServo.pwmForAngle(0));//alto anteriore sn alza
 driver.setChannelPWM(3, pwmServo.pwmForAngle(-70));//basso anteriore dx pronto per spinta
 driver.setChannelPWM(4, pwmServo.pwmForAngle(0));//alto anteriore dx alza
 driver.setChannelPWM(5, pwmServo.pwmForAngle(-40));//basso posteriore dx pronto per spinta
 driver.setChannelPWM(6, pwmServo.pwmForAngle(0)); //alto posteriore dx alza
 driver.setChannelPWM(7, pwmServo.pwmForAngle(40));//basso posteriore sn pronto per spinta
 driver.setChannelPWM(8, pwmServo.pwmForAngle(0)); //alto posteriore sn alza
Torna ai contenuti