查看: 7811|回复: 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有些文字没有被虚化
    您需要登录后才可以回帖 登录 | 立即注册  

    本版积分规则

    热门推荐

    KittenBot杯第六届开源硬件开发大赛启动啦
    KittenBot杯第六届开源硬
    大赛简介: 第六届开源硬件开发大赛由Arduino中文社区发起 由KittenBot冠名赞助
    【原创】制作一套USB电流采样板
    【原创】制作一套USB电流
    以前用 0.1Ω(R1J)曾经做过一个 USB 电流采集器,基本原理和 USB 电流表一致, 唯一
    arduino数字输出端低电平不稳定
    arduino数字输出端低电平
    我在做的功能: 用一个光电开关(买好的现成元件),发出高电平信号输入给arduino,然
    [Arduino物联网开发实战2]数据反馈
    [Arduino物联网开发实战2]
    [md]上一篇:(https://www.arduino.cn/thread-83177-1-1.html) ### 添加DIY组件
    博哥零基础教你玩转ESP8266(十四) ESP8266HTTPClient 连接世界
    博哥零基础教你玩转ESP826
    帖子导航帖 博哥零基础教你玩转ESP8266(一) 重识ESP8266 博哥零基础教你玩转ESP8266
    Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   ( 蜀ICP备14017632号-3 )
    快速回复 返回顶部 返回列表