找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 12782|回復(fù): 7
打印 上一主題 下一主題
收起左側(cè)

PCA9685引腳圖與16路舵機(jī)Arduino驅(qū)動(dòng)源程序pdf資料下載

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主


PCA9685引腳圖:


PCA9685 16路舵機(jī)驅(qū)動(dòng)原理圖:


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. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
16路舵機(jī)驅(qū)動(dòng).rar (692.97 KB, 下載次數(shù): 111)
PCA9685.pdf (1.14 MB, 下載次數(shù): 65)
PCA9685_20141121.pdf (37.53 KB, 下載次數(shù): 57)



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏4 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:281639 發(fā)表于 2018-6-26 10:38 | 只看該作者
xiexie分享
回復(fù)

使用道具 舉報(bào)

板凳
ID:359446 發(fā)表于 2018-6-26 16:02 | 只看該作者
謝謝分享。這玩意我滿世界找不到。
回復(fù)

使用道具 舉報(bào)

地板
ID:468627 發(fā)表于 2019-1-15 16:25 | 只看該作者
不錯(cuò),
回復(fù)

使用道具 舉報(bào)

5#
ID:465522 發(fā)表于 2019-1-19 15:09 | 只看該作者
不錯(cuò),下來(lái)看看
回復(fù)

使用道具 舉報(bào)

6#
ID:507262 發(fā)表于 2019-4-8 19:23 來(lái)自手機(jī) | 只看該作者
謝謝分享
回復(fù)

使用道具 舉報(bào)

7#
ID:527731 發(fā)表于 2019-5-6 14:34 | 只看該作者
有原理圖源文件嗎
回復(fù)

使用道具 舉報(bào)

8#
ID:1133976 發(fā)表于 2024-10-20 22:49 | 只看該作者
原理圖中C2電容的符號(hào)是pol2,并不是注釋的pol1,而且2.2uf設(shè)置不合理,控制多個(gè)舵機(jī)應(yīng)該濾低頻,采用更大容值的電容,平滑電源的低頻波動(dòng)和瞬態(tài)電流,確保舵機(jī)工作時(shí)電源穩(wěn)定。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表