找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 10680|回复: 6
打印 上一主题 下一主题
收起左侧

PCA9685引脚图与16路舵机Arduino驱动源程序pdf资料下载

  [复制链接]
跳转到指定楼层
楼主


PCA9685引脚图:


PCA9685 16路舵机驱动原理图:


PCA9685管脚功能定义:




Arduino源程序如下:
  1. /***************************************************
  2.   This is a library for our Adafruit 16-channel PWM & Servo driver
  3.   Pick one up today in the adafruit shop!
  4.   These displays use I2C to communicate, 2 pins are required to  
  5.   interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

  6.   Adafruit invests time and resources providing this open source code,
  7.   please support Adafruit and open-source hardware by purchasing
  8.   products from Adafruit!

  9.   Written by Limor Fried/Ladyada for Adafruit Industries.  
  10.   BSD license, all text above must be included in any redistribution
  11. ****************************************************/

  12. #include <Adafruit_PWMServoDriver.h>
  13. #include <Wire.h>
  14. #if defined(__AVR__)
  15. #define WIRE Wire
  16. #elif defined(CORE_TEENSY) // Teensy boards
  17. #define WIRE Wire
  18. #else // Arduino Due
  19. #define WIRE Wire1
  20. #endif

  21. // Set to true to print some debug messages, or false to disable them.
  22. #define ENABLE_DEBUG_OUTPUT false

  23. Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(uint8_t addr) {
  24.   _i2caddr = addr;
  25. }

  26. void Adafruit_PWMServoDriver::begin(void) {
  27. WIRE.begin();
  28. reset();
  29. }


  30. void Adafruit_PWMServoDriver::reset(void) {
  31. write8(PCA9685_MODE1, 0x0);
  32. }

  33. void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
  34.   //Serial.print("Attempting to set freq ");
  35.   //Serial.println(freq);
  36.   freq *= 0.9;  // Correct for overshoot in the frequency setting (see issue #11).
  37.   float prescaleval = 25000000;
  38.   prescaleval /= 4096;
  39.   prescaleval /= freq;
  40.   prescaleval -= 1;
  41.   if (ENABLE_DEBUG_OUTPUT) {
  42.     Serial.print("Estimated pre-scale: "); Serial.println(prescaleval);
  43.   }
  44.   uint8_t prescale = floor(prescaleval + 0.5);
  45.   if (ENABLE_DEBUG_OUTPUT) {
  46.     Serial.print("Final pre-scale: "); Serial.println(prescale);
  47.   }
  48.   
  49.   uint8_t oldmode = read8(PCA9685_MODE1);
  50.   uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
  51.   write8(PCA9685_MODE1, newmode); // go to sleep
  52.   write8(PCA9685_PRESCALE, prescale); // set the prescaler
  53.   write8(PCA9685_MODE1, oldmode);
  54.   delay(5);
  55.   write8(PCA9685_MODE1, oldmode | 0xa1);  //  This sets the MODE1 register to turn on auto increment.
  56.                                           // This is why the beginTransmission below was not working.
  57.   //  Serial.print("Mode now 0x"); Serial.println(read8(PCA9685_MODE1), HEX);
  58. }

  59. void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
  60.   //Serial.print("Setting PWM "); Serial.print(num); Serial.print(": "); Serial.print(on); Serial.print("->"); Serial.println(off);

  61.   WIRE.beginTransmission(_i2caddr);
  62.   WIRE.write(LED0_ON_L+4*num);
  63.   WIRE.write(on);
  64.   WIRE.write(on>>8);
  65.   WIRE.write(off);
  66.   WIRE.write(off>>8);
  67.   WIRE.endTransmission();
  68. }

  69. // Sets pin without having to deal with on/off tick placement and properly handles
  70. // a zero value as completely off.  Optional invert parameter supports inverting
  71. // the pulse for sinking to ground.  Val should be a value from 0 to 4095 inclusive.
  72. void Adafruit_PWMServoDriver::setPin(uint8_t num, uint16_t val, bool invert)
  73. {
  74.   // Clamp value between 0 and 4095 inclusive.
  75.   val = min(val, 4095);
  76.   if (invert) {
  77.     if (val == 0) {
  78.       // Special value for signal fully on.
  79.       setPWM(num, 4096, 0);
  80.     }
  81.     else if (val == 4095) {
  82.       // Special value for signal fully off.
  83.       setPWM(num, 0, 4096);
  84.     }
  85.     else {
  86.       setPWM(num, 0, 4095-val);
  87.     }
  88.   }
  89.   else {
  90.     if (val == 4095) {
  91.       // Special value for signal fully on.
  92.       setPWM(num, 4096, 0);
  93.     }
  94.     else if (val == 0) {
  95.       // Special value for signal fully off.
  96.       setPWM(num, 0, 4096);
  97.     }
  98.     else {
  99.       setPWM(num, 0, val);
  100.     }
  101.   }
  102. }

  103. ……………………

  104. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
16路舵机驱动.rar (692.97 KB, 下载次数: 104)
PCA9685.pdf (1.14 MB, 下载次数: 60)
PCA9685_20141121.pdf (37.53 KB, 下载次数: 53)



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏4 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:281639 发表于 2018-6-26 10:38 | 只看该作者
xiexie分享
回复

使用道具 举报

板凳
ID:359446 发表于 2018-6-26 16:02 | 只看该作者
谢谢分享。这玩意我满世界找不到。
回复

使用道具 举报

地板
ID:468627 发表于 2019-1-15 16:25 | 只看该作者
不错,
回复

使用道具 举报

5#
ID:465522 发表于 2019-1-19 15:09 | 只看该作者
不错,下来看看
回复

使用道具 举报

6#
ID:507262 发表于 2019-4-8 19:23 来自手机 | 只看该作者
谢谢分享
回复

使用道具 举报

7#
ID:527731 发表于 2019-5-6 14:34 | 只看该作者
有原理图源文件吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表