PCA9685 programming help

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jeffmorris
 
Posts: 10
Joined: Mon Sep 12, 2022 11:12 am

PCA9685 programming help

Post by jeffmorris »

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?

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: PCA9685 programming help

Post by dastels »

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

User avatar
jeffmorris
 
Posts: 10
Joined: Mon Sep 12, 2022 11:12 am

Re: PCA9685 programming help

Post by jeffmorris »

I found the tutorial at https://rootsaid.com/pca9685-servo-driver/ and it worked.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: PCA9685 programming help

Post by dastels »

Cool. Don't frget about tweaking the MIN/MAX pulse values to reduce wear & tear on the servos.

Dave

User avatar
jeffmorris
 
Posts: 10
Joined: Mon Sep 12, 2022 11:12 am

Re: PCA9685 programming help

Post by jeffmorris »

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.

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: PCA9685 programming help

Post by dastels »

Either that or pass in the MIN/MAX to use. That would be the better way.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”