用PCA9685舵机驱动板驱动舵机无反应-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8572|回复: 5

[已解决] 用PCA9685舵机驱动板驱动舵机无反应

[复制链接]
发表于 2018-3-2 20:53 | 显示全部楼层 |阅读模式
本帖最后由 青梅煮猹 于 2018-5-10 09:09 编辑

板子是mega2560,接线图如下(5V-VCC GND-GND SDA-SDA SCL-SCL)
V+接口接了外部电源
现在问题是下载驱动板附带的例程之后舵机毫无反应,连颤动都没有,网上有人说是因为I2C地址不是0X40而是0X80但是我改了之后也没有任何效果,希望能有大神解答一下,折腾了一晚上舵机都没动现在很绝望

例程如下:
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 16 servos, one after the other

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815

  These displays use I2C to communicate, 2 pins are required to  
  interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

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

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

#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);

}

QQ图片20180302205055.jpg
发表于 2018-3-3 08:58 | 显示全部楼层
外接电源的GND和5V的GND有接到一起吗?
发表于 2018-3-3 10:10 | 显示全部楼层
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);   
它的地址可以有好几个,你搜一下 IIC scan 的程序,先扫一下,就能确认是不是地址的问题了。
http://playground.arduino.cc/Main/I2cScanner
 楼主| 发表于 2018-5-10 08:58 | 显示全部楼层
谢谢来帮助的小伙伴,已经解决了,是因为我们的舵机功率比较大单片机供电带不动,更换成外接电源之后就可以了!忘记回复了,抱歉!
发表于 2019-12-25 20:49 | 显示全部楼层
请问如果pca9685带16个舵机的话,每个输出口能有多少电流?电流太大的话,pca9685会停止工作吗?
发表于 2022-1-13 11:46 | 显示全部楼层
青梅煮猹 发表于 2018-5-10 08:58
谢谢来帮助的小伙伴,已经解决了,是因为我们的舵机功率比较大单片机供电带不动,更换成外接电源之后就可以 ...

我遇到了相同的情况,不过因为手头没有外接电源,用一个STM32的5V和GND引脚当外接电源。。。可是就是不动。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 17:49 , Processed in 0.228233 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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