hi all,
for model railway issues i have a lot of servos to manage with Arduino Mega,
but use A.Nano for test of PWM over PCA9685.
Have 2 pieces of PCA9685,called Modules in progress, individually run correctly !
One Servo (SG90) is connected to PIN 0 of module1,
two Servos(SG90) are connected to PIN 0 and 1 of module2
A0 is jumpered on module2.
All wires are checked for correct connections between
A.Nano I2C-Pins and the modules.
But in mdules chained, the servos don't move !
the red LED's on PCA are lighted pwm1 led illuminates continously strong ,
but on pwm2 illuminates sometimes and not so strong
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
//--- multi_pwm_test_adaf_chain_1
//- created : 30.06.2023
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40); //setup the board address 0
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41); //setup the board address 0
// 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(0x40, Wire);
// 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)
//#define USMIN 600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
//#define USMAX 2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
//- auch damit wird der Angle kleiner
//#define SERVOMIN 50 // This is the 'minimum' pulse length count (out of 4096)
//#define SERVOMAX 300 // This is the 'maximum' pulse length count (out of 4096)
//-- try to modify Angle
#define USMIN 100 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX 700 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates
#define MY_DELAY 1500
uint8_t p1_servonum = 0;
uint8_t p2_servonum = 1;
uint16_t pulselen = SERVOMIN;
uint8_t my_angle = 50;
void setup() {
Serial.begin(9600);
Serial.println("Setup Start Servo test mit 2 Modulen !");
pwm1.begin();
pwm2.begin();
pwm1.setOscillatorFrequency(27000000);
pwm1.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
pwm2.setOscillatorFrequency(27000000);
pwm2.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
delay(10);
//Wire.setClock(400000);
Serial.println("Setup ready !");
}
void loop()
{
my_angle = 50;
Serial.println("PWM_port : 1 Servo "+String(p1_servonum)+" : Angle : "+String(my_angle));
pwm1.setPWM(p1_servonum, 0, my_angle);
elapse_servo_time(1);
delay(MY_DELAY);
my_angle = 200;
Serial.println("PWM_port : 1 Servo "+String(p1_servonum)+" : Angle : "+String(my_angle));
pwm1.setPWM(p1_servonum, 0, my_angle);
elapse_servo_time(1);
delay(MY_DELAY);
my_angle = SERVOMAX;
Serial.println("PWM_port : 2 Servo "+String(p2_servonum)+" : Angle : "+String(my_angle));
pwm2.setPWM(p2_servonum, 0, my_angle);
elapse_servo_time(2);
delay(MY_DELAY);
my_angle = 120;
Serial.println("PWM_port : 2 Servo "+String(p2_servonum)+" : Angle : "+String(my_angle));
pwm2.setPWM(p2_servonum, 0, my_angle);
elapse_servo_time(2);
delay(MY_DELAY);
my_angle = SERVOMAX-50;
Serial.println("PWM_port : 2 Servo "+String(p2_servonum+1)+" : Angle : "+String(my_angle));
pwm2.setPWM(p2_servonum+1, 0, my_angle);
elapse_servo_time(2);
delay(MY_DELAY);
my_angle = 160;
Serial.println("PWM_port : 2 Servo "+String(p2_servonum+1)+" : Angle : "+String(my_angle));
pwm2.setPWM(p2_servonum+1, 0, my_angle);
elapse_servo_time(2);
}
void elapse_servo_time(uint8_t serv_pwm_num)
{
for (uint16_t microsec = USMAX; microsec > USMIN; microsec--)
{
if(serv_pwm_num == 1)
pwm1.writeMicroseconds(p1_servonum, microsec);
if(serv_pwm_num == 2)
{
pwm2.writeMicroseconds(p2_servonum, microsec);
pwm2.writeMicroseconds(p2_servonum+1, microsec);
}
}
}
i'm not experienced with this module..