查看: 6681|回复: 14

[未解决] PCA9685 16-channel, 12-bit PWM 舵机驱动模块使用

[复制链接]

该用户从未签到

发表于 2016-3-28 16:16 | 显示全部楼层 |阅读模式
求助这种舵机驱动版该怎么编程呢?如何使舵机动起来?谢谢了

该用户从未签到

发表于 2016-9-9 09:23 | 显示全部楼层
我也想知道怎么用,同求
  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-15 10:38 | 显示全部楼层
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>

    // called this way, it uses the default address 0x40
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
    // you can also call it with a different address you want
    //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

    // Depending on your servo make, the pulse width min and max may vary, you
    // want these to be as small/large as possible without hitting the hard stop
    // for max range. You'll have to tweak them as necessary to match the servos you
    // have!
    #define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
    #define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

    // our servo # counter
    //uint8_t servonum = 0;

    void setup() {
      Serial.begin(9600);
      Serial.println("16 channel Servo test!");

      pwm.begin();
      
      pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
    }

    // you can use this function if you'd like to set the pulse length in seconds
    // e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
    void setServoPulse(uint8_t n, double pulse) {
      double pulselength;
      
      pulselength = 1000000;   // 1,000,000 us per second
      pulselength /= 60;   // 60 Hz
      Serial.print(pulselength); Serial.println(" us per period");
      pulselength /= 4096;  // 12 bits of resolution
      Serial.print(pulselength); Serial.println(" us per bit");
      pulse *= 1000;
      pulse /= pulselength;
      Serial.println(pulse);
      pwm.setPWM(n, 0, pulse);
    }

    void loop() {
      // Drive each servo one at a time
      //Serial.println(servonum);
      for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
        pwm.setPWM(0, 0, pulselen);
        pwm.setPWM(1, 0, pulselen);
        pwm.setPWM(2, 0, pulselen);
        pwm.setPWM(3, 0, pulselen);
        pwm.setPWM(4, 0, pulselen);
        pwm.setPWM(5, 0, pulselen);
        pwm.setPWM(6, 0, pulselen);
        pwm.setPWM(7, 0, pulselen);
        pwm.setPWM(8, 0, pulselen);
        pwm.setPWM(9, 0, pulselen);
        pwm.setPWM(10, 0, pulselen);
        pwm.setPWM(11, 0, pulselen);
        pwm.setPWM(12, 0, pulselen);
        pwm.setPWM(13, 0, pulselen);
        pwm.setPWM(14, 0, pulselen);
      }
      delay(500);
      for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
        pwm.setPWM(0, 0, pulselen);
        pwm.setPWM(0, 0, pulselen);
        pwm.setPWM(1, 0, pulselen);
        pwm.setPWM(2, 0, pulselen);
        pwm.setPWM(3, 0, pulselen);
        pwm.setPWM(4, 0, pulselen);
        pwm.setPWM(5, 0, pulselen);
        pwm.setPWM(6, 0, pulselen);
        pwm.setPWM(7, 0, pulselen);
        pwm.setPWM(8, 0, pulselen);
        pwm.setPWM(9, 0, pulselen);
        pwm.setPWM(10, 0, pulselen);
        pwm.setPWM(11, 0, pulselen);
        pwm.setPWM(12, 0, pulselen);
        pwm.setPWM(13, 0, pulselen);
        pwm.setPWM(14, 0, pulselen);
      }
      delay(500);
    }


  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-15 10:39 | 显示全部楼层
    我也买了一个和你一样的
  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-15 10:40 | 显示全部楼层
    百度收索的
  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-15 10:43 | 显示全部楼层
    我试了一下,是可以的喔

    该用户从未签到

    发表于 2017-2-20 20:51 | 显示全部楼层

    为什么编写的时候出现错误呢??

    sketch_feb20a:4: error: 'Adafruit_PWMServoDriver' does not name a type
    sketch_feb20a.cpp: In function 'void setup()':
    sketch_feb20a:22: error: 'pwm' was not declared in this scope
    sketch_feb20a.cpp: In function 'void setServoPulse(uint8_t, double)':
    sketch_feb20a:42: error: 'pwm' was not declared in this scope
    sketch_feb20a.cpp: In function 'void loop()':
    sketch_feb20a:49: error: 'pwm' was not declared in this scope
    sketch_feb20a:67: error: 'pwm' was not declared in this scope
  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-22 10:47 | 显示全部楼层
    哦好像.//的那个
  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-22 10:50 | 显示全部楼层

    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>

    it uses the default address 0x40
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();


    #define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
    #define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)


    void setup() {
      Serial.begin(9600);
      Serial.println("16 channel Servo test!");

      pwm.begin();
      
      pwm.setPWMFreq(60);  
    }


    void setServoPulse(uint8_t n, double pulse) {
      double pulselength;
      
      pulselength = 1000000;  
      pulselength /= 60;  
      Serial.print(pulselength); Serial.println(" us per period");
      pulselength /= 4096;
      Serial.print(pulselength); Serial.println(" us per bit");
      pulse *= 1000;
      pulse /= pulselength;
      Serial.println(pulse);
      pwm.setPWM(n, 0, pulse);
    }

    void loop() {
      
      for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
        pwm.setPWM(0, 0, pulselen);
        pwm.setPWM(1, 0, pulselen);
        pwm.setPWM(2, 0, pulselen);
        pwm.setPWM(3, 0, pulselen);
        pwm.setPWM(4, 0, pulselen);
        pwm.setPWM(5, 0, pulselen);
        pwm.setPWM(6, 0, pulselen);
        pwm.setPWM(7, 0, pulselen);
        pwm.setPWM(8, 0, pulselen);
        pwm.setPWM(9, 0, pulselen);
        pwm.setPWM(10, 0, pulselen);
        pwm.setPWM(11, 0, pulselen);
        pwm.setPWM(12, 0, pulselen);
        pwm.setPWM(13, 0, pulselen);
        pwm.setPWM(14, 0, pulselen);
      }
      delay(500);
      for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
        pwm.setPWM(0, 0, pulselen);
        pwm.setPWM(0, 0, pulselen);
        pwm.setPWM(1, 0, pulselen);
        pwm.setPWM(2, 0, pulselen);
        pwm.setPWM(3, 0, pulselen);
        pwm.setPWM(4, 0, pulselen);
        pwm.setPWM(5, 0, pulselen);
        pwm.setPWM(6, 0, pulselen);
        pwm.setPWM(7, 0, pulselen);
        pwm.setPWM(8, 0, pulselen);
        pwm.setPWM(9, 0, pulselen);
        pwm.setPWM(10, 0, pulselen);
        pwm.setPWM(11, 0, pulselen);
        pwm.setPWM(12, 0, pulselen);
        pwm.setPWM(13, 0, pulselen);
        pwm.setPWM(14, 0, pulselen);
      }
      delay(500);

    }
  • TA的每日心情
    开心
    2017-1-20 11:34
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    发表于 2017-2-22 10:52 | 显示全部楼层
    用新版的arduino有些文字没有被虚化
    您需要登录后才可以回帖 登录 | 立即注册  

    本版积分规则

    热门推荐

    IDE 用arbuBlok下载不了程序。
    IDE 用arbuBlok下载不了程
    点击下载到板子就出现红字体 版本是1.8.7
    初学arduino求助
    初学arduino求助
    大佬们,我想问一下,我现在想做一个程序:按下开关持续时间t,延迟7.77t后点亮led0.
    吸顶灯接入物联网(基于Blinker与wifi开发板)
    吸顶灯接入物联网(基于Bli
    暑假开始接触Blinker和esp8266开发板,一直在捣鼓。。开学是肯定没空碰了,于是趁现在
    原创 drawbot平面关节机械臂 教程直播贴
    原创 drawbot平面关节机械
    这个项目上个月就在做了,结构和代码反反复复改了多次,加上自己又太懒,一直没来得及
    创客集结号之光控LED实验
    创客集结号之光控LED实验
    本次实验是在创客集结号上分享出来的,是做一个光控LED实验。 1.实验器件: Arduino
    Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
    快速回复 返回顶部 返回列表