16-channel 12-bit I2C PWM Servo Driver and initial servo pos

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
msousa
 
Posts: 15
Joined: Tue Apr 30, 2013 1:01 pm

16-channel 12-bit I2C PWM Servo Driver and initial servo pos

Post by msousa »

I've embellished the servo example as seen below. This is so I might experiment with just one servo. With everything hooked up (servo brd connected to arduino, power to 16-channel I2C brd, one servo connected to the brd), when I apply power from the PC to the arduino (through the USB cable) the servo moves almost 45 degrees. This is before I upload the program below. Any idea why this might happen?

Thanks...
/***************************************************************
Control of the servos on the UAS
***************************************************************/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// 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  200 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  300 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;
uint8_t servo1 = 0;

void setup() {
  Serial.begin(9600);
  delay(3000);
  Serial.println("16 channel Servo test!");

  pwm.begin();
  
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
}

void loop()
{
  pwm.setPWM(0,0,225);
  delay(2000); // two seconds
  pwm.setPWM(0,0,475);
  return;
}

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by adafruit_support_mike »

Servos are controlled by a continuous stream of pulses. Any time the pulse stream changes, the servo will move to the appropriate position.

In this case, it sounds like the servo is moving to a 'home' position when it senses the first electrical connection from the shield.

msousa
 
Posts: 15
Joined: Tue Apr 30, 2013 1:01 pm

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by msousa »

Thanks adafruit_support_mike. With the initial motion I've reset the arm on the servo and that does appear to be home. When I start up the arduino and servo driver it appears that it runs before I do an upload. Is it possible that the I2C pulses are still running on the pwm_servo_driver? Is there a certain sequence of powering up the system ( right now, it's 1st arduino, 2nd pwm_servo_driver, 3rd servo power to V+)?

Thanks...

User avatar
adafruit_support_bill
 
Posts: 88155
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by adafruit_support_bill »

If you wait to power the servos until the driver board is initialized, the servos should seek to that initial position on power-up.

User avatar
helio.b.teixeira
 
Posts: 9
Joined: Mon May 06, 2013 6:27 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by helio.b.teixeira »

Hi,

Is there any possibility to turn off the power of one specific channel? I noticed that (in Python), servo only moves when we call setPWM(), even both the servo power supply is connected...What would happen if we set both start and end of "Pin High" at 0 like this -> setPWM([channel], 0, 0)

User avatar
adafruit_support_bill
 
Posts: 88155
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by adafruit_support_bill »

What would happen if we set both start and end of "Pin High" at 0 like this -> setPWM([channel], 0, 0)
That won't turn off the power to the servo, but it will stop sending a pulse. Most servos will stop active control at that point, so the motor will be idle.

User avatar
helio.b.teixeira
 
Posts: 9
Joined: Mon May 06, 2013 6:27 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by helio.b.teixeira »

Thank you very much,

I noticed on other posts that you refer an OE (Output Enable) pin. How can i set it to low?

User avatar
adafruit_support_bill
 
Posts: 88155
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by adafruit_support_bill »

The Output Enable pin is active LOW and is pulled low by default. You can drive it high with any GPIO pin to suppress output to all channels simultaneously.

User avatar
helio.b.teixeira
 
Posts: 9
Joined: Mon May 06, 2013 6:27 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by helio.b.teixeira »

Can I find any additional tutorial/info on this?
(I'm only used to Adafruit's Python library).

User avatar
adafruit_support_bill
 
Posts: 88155
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by adafruit_support_bill »

There is no tutorial specifically for that. The data sheet describes how it works: http://www.adafruit.com/datasheets/PCA9685.pdf

In any case, it is not complicated. Just connect it to a GPIO pin. Set the pin HIGH to disable outputs. Set it LOW to enable them.

User avatar
helio.b.teixeira
 
Posts: 9
Joined: Mon May 06, 2013 6:27 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by helio.b.teixeira »

I've found this on the data sheet:
Screen Shot 2014-11-06 at 01.48.53.png
Screen Shot 2014-11-06 at 01.48.53.png (75.04 KiB) Viewed 696 times
I'm using a RaspberryPi so the voltage GPIO (3.3V) is within the allowed voltages, right?
Will I need a resistor?

User avatar
adafruit_support_bill
 
Posts: 88155
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-channel 12-bit I2C PWM Servo Driver and initial servo

Post by adafruit_support_bill »

Yes. 3.3v is fine. When controlling it from the Pi, the i2c bus voltage is 3.3v.

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

Return to “Other Products from Adafruit”