Hey everyone, I am building a project names animatronic Robot head, and using mg90s servos for movements.
The problem is that when I Centered the servo by connecting it directly to the Arduino, it centered at a position.
But when I connect the servo to PCA9685 servo driver and then try to center it, then it centers at different position. Can anyone help me with that problem. Here are the both codes:
#include <Servo.h>
Servo myServo; // Create a servo object
void setup() {
myServo.attach(9); // Attach the servo to pin 9 (use the pin connected to the servo signal wire)
myServo.write(90); // Set servo to center position (90 degrees)
}
void loop() {
// Nothing to do in the loop for now
}
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// Initialize the PCA9685 using the default address (0x40)
Adafruit_PWMServoDriver pca9685 = Adafruit_PWMServoDriver();
// PWM settings
#define SERVOMIN 150 // Minimum pulse length out of 4096
#define SERVOMAX 600 // Maximum pulse length out of 4096
#define CENTER_PULSE 375 // Center pulse length out of 4096, roughly the middle between SERVOMIN and SERVOMAX
// Set the channel number for the servo you want to center
int servoChannel = 0; // Change this to the actual channel number connected to your servo
void setup() {
Serial.begin(9600);
Serial.println("Centering Servo...");
// Initialize PCA9685
pca9685.begin();
pca9685.setPWMFreq(50); // Standard servo frequency
// Center the servo
pca9685.setPWM(servoChannel, 0, CENTER_PULSE);
Serial.println("Servo should be centered.");
}
void loop() {
// Nothing needed in loop for centering
}