PCA9685 programming help
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jeffmorris
- Posts: 10
- Joined: Mon Sep 12, 2022 11:12 am
PCA9685 programming help
I bought the PCA9685 board but I need help. If I don't use the board and connect the servos to an Arduino board, I can use servo.write(degrees). When I connect the servos to PCA9685 board, I have to use setPWM((uint8_t num, uint16_t on, uint16_t off) and SetPin((uint8_t num, uint16_t val, bool invert=false). These functions confuse me. I wish that I could use a function like servo.write(degrees) on PCA9685 board. Is it possible?
- dastels
- Posts: 15674
- Joined: Tue Oct 20, 2015 3:22 pm
Re: PCA9685 programming help
Not using the PCA9685 library. It's a 16 channel PWM board, not strictly a servo board.
The guide does have a code snippet for converting from an angle to pulse width: https://learn.adafruit.com/16-channel-p ... th-1825151.
Reading the entire guide should help with understanding those functions: https://learn.adafruit.com/16-channel-pwm-servo-driver.
Dave
The guide does have a code snippet for converting from an angle to pulse width: https://learn.adafruit.com/16-channel-p ... th-1825151.
Reading the entire guide should help with understanding those functions: https://learn.adafruit.com/16-channel-pwm-servo-driver.
Dave
- jeffmorris
- Posts: 10
- Joined: Mon Sep 12, 2022 11:12 am
Re: PCA9685 programming help
I found the tutorial at https://rootsaid.com/pca9685-servo-driver/ and it worked.
- dastels
- Posts: 15674
- Joined: Tue Oct 20, 2015 3:22 pm
Re: PCA9685 programming help
Cool. Don't frget about tweaking the MIN/MAX pulse values to reduce wear & tear on the servos.
Dave
Dave
- jeffmorris
- Posts: 10
- Joined: Mon Sep 12, 2022 11:12 am
Re: PCA9685 programming help
My robot has two different servos that need to have different MIN/MAX pulse values.
int pulseWidth(int angle)
{
int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
//Serial.println(analog_value);
return analog_value;
}
I think that I need to have two pulseWidth functions.
int pulseWidth(int angle)
{
int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
//Serial.println(analog_value);
return analog_value;
}
I think that I need to have two pulseWidth functions.
- dastels
- Posts: 15674
- Joined: Tue Oct 20, 2015 3:22 pm
Re: PCA9685 programming help
Either that or pass in the MIN/MAX to use. That would be the better way.
Dave
Dave
Please be positive and constructive with your questions and comments.