我用的是arduino uno r3的板子 使用pca9685的过程中遇到一些问题,求告知。
按以下方式连接
+5v -> VCC
GND -> GND
Analog 4 -> SDA
Analog 5 -> SCL
外接电源
使用自带的例程(只接2个舵机):
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
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); // Analog servos run at ~60 Hz updates
}
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() {
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
pwm.setPWM(0, 0, pulselen);
pwm.setPWM(1, 0, pulselen);
}
delay(500);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(0, 0, pulselen);
pwm.setPWM(1, 0, pulselen);
}
delay(500);
}
编译通不过的话,要添加库:程序->导入库->Add Library ->添加例程目录中的Adafruit_PWMServoDriver.
但是编译通过上传成功,舵机还是无法转动。如果给为大佬有什么好的解决办法告诉小弟一声。想通过pca9685控制五个舵机的转动。
本人 微信 bangzhouwang
|