PCA9685 PWM expansion - mcworkshop

MC   WORKSHOP
Vai ai contenuti

Menu principale:

PCA9685 PWM expansion

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
etc...


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() {
   Serial.begin(115200);

   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
}

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


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

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() {
 Wire.begin();
 Wire.setClock(400000);
 driver.resetDevices();
 driver.init(B000000);
 driver.setPWMFrequency(50);
}
void loop() {
 delay(500);
 driver.setChannelPWM(1, pwmServo.pwmForAngle(60));//basso anteriore sn pronto per spinta
 delay(500);
 driver.setChannelPWM(2, pwmServo.pwmForAngle(0));//alto anteriore sn alza
 delay(500);
 driver.setChannelPWM(3, pwmServo.pwmForAngle(-70));//basso anteriore dx pronto per spinta
 delay(500);
 driver.setChannelPWM(4, pwmServo.pwmForAngle(0));//alto anteriore dx alza
 delay(500);
 driver.setChannelPWM(5, pwmServo.pwmForAngle(-40));//basso posteriore dx pronto per spinta
 delay(500);
 driver.setChannelPWM(6, pwmServo.pwmForAngle(0)); //alto posteriore dx alza
 delay(500);
 driver.setChannelPWM(7, pwmServo.pwmForAngle(40));//basso posteriore sn pronto per spinta
 delay(500);
 driver.setChannelPWM(8, pwmServo.pwmForAngle(0)); //alto posteriore sn alza
 //....
}
 
Copyright 2015. All rights reserved.
Torna ai contenuti | Torna al menu