PWM/servo driver

Hi
I need to do project using PWM/servo driver ( http://www.adafruit.com/product/815 ) to run servo motor (http://www.adafruit.com/product/154 ). I downloaded library for it, however there is not enough information about usage of library functions. For example for servo libraries there is reference page showing functions and usages of it (http://arduino.cc/en/Reference/Servo ). However, for pwm/servo library i can’t find anything, expect example program of library which doesn’t explain everything. Could anyone suggest me where i can get more information about it?

KInd regards

http://playground.arduino.cc/Learning/SingleServoExample

Hi, try this link or at the top of this page is a green menu, click Learning, then click Playground.

Tom....... :)

At the bottom of the description, the Adafruit page says:

Check out our tutorial with Arduino and you can get our documented Arduino library which has both PWM and Servo examples from github!

The github repository gives a couple of examples, and this one seems to show how to drive a servo:

/***************************************************
This is an example for our Adafruit 16-channel PWM & Servo driver
Servo test - this will drive 16 servos, one after the other

Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/815

These displays use I2C to communicate, 2 pins are required to
interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// 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)

// our servo # counter
uint8_t servonum = 0;

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

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

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;
  
  pulselength = 1000000; // 1,000,000 us per second
  pulselength /= 60; // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period");
  pulselength /= 4096; // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit");
  pulse *= 1000;
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {
  // Drive each servo one at a time
  Serial.println(servonum);
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
    pwm.setPWM(servonum, 0, pulselen);
  }
  delay(500);
  for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
    pwm.setPWM(servonum, 0, pulselen);
  }
  delay(500);

  servonum ++;
  if (servonum > 15) servonum = 0;
}

You can also see some comments about the use of I2C pins in the header file.

It’s not brilliant documentation IMO, but it does seem to give enough info to connect the hardware and run the examples.

It clearly says on the product page that your servo can be controlled by the regular servo library.

Look at the servo examples that come with the Arduino IDE.

Because yours is a continuous rotation servo you control the speed rather than the position.

The myServo.write(90); should make the servo stop (it's the centre position) and (for example) myServo.write(100); should make it go in one direction and myServo.write(80); should make it go in the other direction.

You may have to experiment with numbers around 90 to find the correct stop position for your servo.

You will have finer control using myServo.writeMcroseconds(1500). 1500 microseconds corresponds with 90 degrees, 1000 = 0 deg and 2000 = 180 deg.

...R