Buenos días
Intento mover 12 servomotores desde un solo Arduino.
Para esto conseguí el módulo PCA9685
Estoy siguiendo este tutorial y realicé esta conexión en primer lugar:
Controlando un motor no hay ningún inconveniente y si conecto dos o tres motores no hay problema tampoco
El problema radica cuando intento hacer más conexiones de esta forma:
Al realizar la conexión de 4 o más motores siempre sucede lo mismo: al comienzo los motores se mueven correctamente (ya sea uno a uno o por ejemplo 4 motores al tiempo) pero después de un tiempo se evidencia que los motores pierden "fuerza" y en lugar de hacer un recorrido completo, por ejemplo de los 180°, hace solo un pequeño barrido para finalmente quedarse detenido y no vuelve a funcionar con ninguna otra orden, hasta desconectar el circuito del Arduino y de la fuente de alimentación
El circuito de alimentación que estoy usando es el siguiente (con un L7805CV):
El Vin lo estoy sacando de una batería como esta:
- 12 V
- 1.2 Ah
L7805CV
datasheet
Servo Motor Futaba S3003
datasheet
Quisiera saber si me pueden ayudar con este inconveniente ya que no entiendo qué puede estar sucediendo
Anexo los códigos con los que he probado el PCA:
Ejemplo de la librería de Adafruit
/***************************************************
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(servonum, 0, pulselen);
}
delay(500);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(servonum, 0, pulselen);
}
delay(500);
servonum ++;
if (servonum > 15) servonum = 0;
}
Código propio manejado con un HC-05
#include <SoftwareSerial.h>
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
SoftwareSerial BT(10, 11); //10 RX, 11 TX.
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVO0 140
#define SERVO180 600
#define SERVO90 370
const int led = 13;
int estadoo = LOW;
int estado = LOW;
int num = 0;
void setup()
{
BT.begin(9600);
pwm.begin();
pwm.setPWMFreq(60);
pinMode(led, OUTPUT);
}
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
pulselength = 1000000;
pulselength /= 60;
pulselength /= 4096;
pulse *= 1000;
pulse /= pulselength;
pwm.setPWM(n, 0, pulse);
}
void loop()
{
while (BT.available() > 0)
{
int pos = BT.parseInt();
if (pos == 0)
{
estadoo = digitalRead(led);
if (estadoo == LOW)
{
estado = HIGH;
}
else
estado = LOW;
digitalWrite(led, estado);
}
if (pos == 1)
{
pwm.setPWM(0, 0, SERVO0);
}
if (pos == 2)
{
pwm.setPWM(0, 0, SERVO90);
}
if (pos == 3)
{
pwm.setPWM(0, 0, SERVO180);
}
if (pos == 4)
{
pwm.setPWM(1, 0, SERVO0);
}
if (pos == 5)
{
pwm.setPWM(1, 0, SERVO90);
}
if (pos == 6)
{
pwm.setPWM(1, 0, SERVO180);
}
if (pos == 7)
{
pwm.setPWM(2, 0, SERVO0);
}
if (pos == 8)
{
pwm.setPWM(2, 0, SERVO90);
}
if (pos == 9)
{
pwm.setPWM(2, 0, SERVO180);
}
if (pos == 10)
{
pwm.setPWM(3, 0, SERVO0);
}
if (pos == 11)
{
pwm.setPWM(3, 0, SERVO90);
}
if (pos == 12)
{
pwm.setPWM(3, 0, SERVO180);
}
if (pos == 100)
{
for(num=0;num<4;num++)
{
pwm.setPWM(num, 0, SERVO0);
}
}
if (pos == 101)
{
for(num=0;num<4;num++)
{
pwm.setPWM(num, 0, SERVO90);
}
}
if (pos == 110)
{
for(num=0;num<4;num++)
{
pwm.setPWM(num, 0, SERVO180);
}
}
}
}