So,Im a bit of a beginner, but im enjoying trying to build the hardware part of this excellent project: Silicone Skin 3D Printed Realistic Animatronic Heart but I cant get the servos to move. I'm running the IDE provided, the serial monitor shows me that the signal is produced from the code... but nothing moves. I swapped the driver board in case it was done for, see image, to no avail. Tried a more powerful source of power, and nothing changes.
What am I missing?
//Nilheim Mechatronics Servo Heart Mechanism Code
//Make sure you have the Adafruit servo driver library installed >>>>> https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
//Potentiometer Pin = A0
#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);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(&Wire, 0x40);
// 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 140 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 520 // this is the 'maximum' pulse length count (out of 4096)
// our servo # counter
uint8_t servonum = 0;
int sensorValue = 0; // value read from the pot
int outputValue = 0;
int xval;
int timePeriod = 1000;
float y=0;
float t=0;
float d=330;
void setup() {
Serial.begin(9600);
Serial.println("8 channel Servo test!");
pinMode(A0, INPUT);
pinMode(2, INPUT);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
delay(10);
}
// 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 *= 1000000; // convert to us
pulse /= pulselength;
Serial.println(pulse);
// pwm.setPWM(n, 0, pulse);
}
void loop() {
/*pwm.setPWM(0, 0, 330);
pwm.setPWM(1, 0, 330);
pwm.setPWM(2, 0, 380);
delay(50);*/
float i;
timePeriod = map(analogRead(sensorValue), 0, 1023, 2000, 300);
for (i=0; i<(3*timePeriod/40); i++) {
y=sin(i/(timePeriod/20));
d = 430-(y*100);
t=350+y*50;
Serial.print(d);
Serial.print(" ");
Serial.print(t);
pwm.setPWM(0, 0, d);
pwm.setPWM(1, 0, d);
pwm.setPWM(2, 0, t);
Serial.println(" ");
delay(10);
}
// i=0;
for (i=0; i<(3*timePeriod/400); i++) {
y=sin(i/(timePeriod/20));
d=430;
t=350;
Serial.print(d);
Serial.print(" ");
Serial.print(t);
pwm.setPWM(0, 0, d);
pwm.setPWM(2, 0, t);
Serial.println(" ");
delay(10);
}
for (i=0; i<((7*timePeriod)/400); i++) {
y=sin(i/(timePeriod/20));
d=430;
//t=350+y*50;
Serial.print(d);
Serial.print(" ");
Serial.print(t);
pwm.setPWM(1, 0, d);
pwm.setPWM(2, 0, t
);
Serial.println(" ");
delay(10);
}
}