What kind of servo library is needed when using the Wave Shi

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

What kind of servo library is needed when using the Wave Shi

Post by isaace »

I am using the Wave Shield, PCA 9685 and an Arduino Uno. The Wave Shield works wonderfully.

But I want to use servos, too and servo.h isn't compatible with the Wave shield libraries. I want to move servo motors at the exact same time it is playing wave files (animated cheesy robot that will talk and move its arms - this community understands the coolness of something like that).

I purchased a PCA 9685 for this purpose. What servo library should I use?

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_bill »

This is the library for the PCA9865 shield and breakout: https://github.com/adafruit/Adafruit-PW ... er-Library

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: What kind of servo library is needed when using the Wave

Post by isaace »

Thanks. I took a look at the library and the sample sketches. I want to use 10 servos (upper torso of the robot). Can I just use my Arduino Uno (with the wave shield) to control another Arduino Uno? That seems like it would be easier to code. I am used to writing code in the servo.h library.

I think that may be a better approach than using the PCA9685 on this project. Is there a tutorial for using two Arduinos?

Isaac

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_mike »

I'm afraid we don't have any tutorials like that.

Give the PCA9685 a try. It can control up to 16 servos at once, and does the moment-by-moment signal generation on its own. The Arduino only has to send control signals when it wants a servo to change position.

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: What kind of servo library is needed when using the Wave

Post by isaace »

Thank you, but how can I use Arduino code to control the servo on the PCA? Can I do it like this?

Code: Select all

void loop() 
{ 
  myservo.write(180);
  delay(500);
  myservo.write(0);
  delay(500);

It seems that the two Arduino approach would be easier. Arduino A code would have a list of cases and then tell Arduino B which case to do. Each case would be like the code I wrote above.

Isaac
Last edited by adafruit_support_bill on Thu Oct 02, 2014 6:02 am, edited 1 time in total.
Reason: Please use the '</>' button when posting code. Paste your code between the [code] tags.

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_bill »

The equivalent code for the PCA9865 is not that complicated.

Code: Select all

int ServoPulse(degrees)
{
    return map(degrees, 0, 180, SERVOMIN, SERVOMAX);
}

void loop()
{
      pwm.setPWM(servonum, 0, ServoPulse(180));
      delay(500);
      pwm.setPWM(servonum, 0, ServoPulse(0));
      delay(500);
}

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: What kind of servo library is needed when using the Wave

Post by isaace »

I tried it and it says

'degrees' was not declared in the scope

Here is my code:

Code: Select all

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

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

uint8_t servonum = 0;
 
Servo ServoPulse;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int ServoPulse(degrees)
{
    return map(degrees, 0, 180, SERVOMIN, SERVOMAX);
} 
void setup() 
{ 
  ServoPulse.attach(0);  // attaches the servo on pin 9 to the servo object 
  
    Serial.begin(9600);
  Serial.println("16 channel Servo test!");

  pwm.begin();
  
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  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()
{
      pwm.setPWM(servonum, 0, ServoPulse(180));
      delay(500);
      pwm.setPWM(servonum, 0, ServoPulse(0));
      delay(500);
}
  } 

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_bill »

Sorry - i forgot to specify the parameter type. That should be:

Code: Select all

int ServoPulse(int degrees)
{
    return map(degrees, 0, 180, SERVOMIN, SERVOMAX);
} 

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: What kind of servo library is needed when using the Wave

Post by Franklin97355 »

You need to add a "int degrees;" line before you call "int ServoPulse(degrees)"

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: What kind of servo library is needed when using the Wave

Post by isaace »

Thank you. I am getting closer and I am using the sample sketch that came with the library (Servo). I have one servo hooked up to pin 0 on the PCA board now, but it only twitches. I can't get it to run a full sweep, even if the coordinates are 0 and 180 degrees.

Here is my code. It is pretty much the sample sketch with your recommended changes in there.

Code: Select all

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

int degrees;

int ServoPulse(int degrees)
{
    return map(degrees, 0, 180, SERVOMIN, SERVOMAX);
} 

// 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 = 180;
*/  
      pwm.setPWM(servonum, 180, ServoPulse(180));
      delay(1000);
      pwm.setPWM(servonum, 0, ServoPulse(0));
      delay(1000);
}

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_bill »

Please post photos showing your soldering and connections to the board.

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: What kind of servo library is needed when using the Wave

Post by isaace »

By the way, the transistor on the PCA is extremely hot! The soldering on this board is extremely simple. Trust me, I don't have a soldering problem. I checked and double checked my hookup and it is simple and consistent with the PCA tutorial on your website.

I think the PCA is pulsing at a frequency that is making that transistor very angry. Can you see this in the code? I don't know what to look for. Using a servo in this way is new to me.

Isaac

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_bill »

Servo frequencies are very low (60 Hz). If something is overheating, it is more likely there is a short circuit somewhere. Please post photos.

User avatar
isaace
 
Posts: 48
Joined: Mon Sep 08, 2014 11:18 pm

Re: What kind of servo library is needed when using the Wave

Post by isaace »

I followed the tutorial found here: https://learn.adafruit.com/16-channel-p ... king-it-up

See the three images.

Isaac
Attachments
DSC03557.JPG
DSC03557.JPG (280.3 KiB) Viewed 336 times
DSC03554.JPG
DSC03554.JPG (343.93 KiB) Viewed 336 times
DSC03551.JPG
DSC03551.JPG (268.52 KiB) Viewed 336 times

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

Re: What kind of servo library is needed when using the Wave

Post by adafruit_support_bill »

The soldering looks fine. Which component is getting hot?

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

Return to “Arduino”