0

Adafruit 16-Channel PWM / Servo HAT Coding
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by adafruit_support_bill on Sun May 15, 2016 12:59 pm

Please post the exact code you are using.

adafruit_support_bill
 
Posts: 74687
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by mclemens7 on Sun May 15, 2016 3:19 pm

Code: Select all | TOGGLE FULL SIZE
#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

  yield();
}

// 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 > 7) servonum = 0;
}
Last edited by franklin97355 on Sun May 15, 2016 4:39 pm, edited 1 time in total.
Reason: Added code tags

mclemens7
 
Posts: 13
Joined: Sat May 14, 2016 8:29 pm

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by adafruit_support_bill on Sun May 15, 2016 5:05 pm

What do you get when you run the i2cScanner code?
http://playground.arduino.cc/Main/I2cScanner

adafruit_support_bill
 
Posts: 74687
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by mclemens7 on Sun May 15, 2016 5:39 pm

so i tried it and the servo started to jitter then i stopped it. tried another code and it didnt work then i went back to the one u gave me and it didnt work

mclemens7
 
Posts: 13
Joined: Sat May 14, 2016 8:29 pm

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by franklin97355 on Sun May 15, 2016 6:08 pm

Running the scanner code should print data to the serial monitor not move the servos. What was the output of the scanner program?

franklin97355
 
Posts: 21229
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by mclemens7 on Sun May 15, 2016 6:16 pm

I2C Device foundat address 0x40
I2C Device found at address 0x70

mclemens7
 
Posts: 13
Joined: Sat May 14, 2016 8:29 pm

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by adafruit_support_bill on Mon May 16, 2016 5:59 am

I2C Device foundat address 0x40
I2C Device found at address 0x70

That is the correct output.
so i tried it and the servo started to jitter then i stopped it.

That sounds like either a power problem, or a connection problem.

Please post some close up photos showing your soldering to the front and back of the board.

adafruit_support_bill
 
Posts: 74687
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by mclemens7 on Tue May 17, 2016 11:57 am

here
Attachments
IMG_1998.JPG
IMG_1998.JPG (98.61 KiB) Viewed 383 times
IMG_1994.JPG
IMG_1994.JPG (65.71 KiB) Viewed 383 times
IMG_1998.JPG
IMG_1998.JPG (98.61 KiB) Viewed 383 times

mclemens7
 
Posts: 13
Joined: Sat May 14, 2016 8:29 pm

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by mclemens7 on Tue May 17, 2016 11:58 am

and more
Attachments
IMG_1998.JPG
IMG_1998.JPG (98.61 KiB) Viewed 383 times
IMG_1993.JPG
IMG_1993.JPG (65.54 KiB) Viewed 383 times
IMG_1990.JPG
IMG_1990.JPG (89.01 KiB) Viewed 383 times

mclemens7
 
Posts: 13
Joined: Sat May 14, 2016 8:29 pm

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by mclemens7 on Tue May 17, 2016 12:01 pm

soldering side
Attachments
IMG_1991.JPG
IMG_1991.JPG (82.17 KiB) Viewed 383 times

mclemens7
 
Posts: 13
Joined: Sat May 14, 2016 8:29 pm

Re: Adafruit 16-Channel PWM / Servo HAT Coding

by adafruit_support_bill on Tue May 17, 2016 12:24 pm

There are some possible problem joints there. Especially the servo header joints on the back side. A few appear to be cold joints and some appear not to have flowed onto the solder pads. Please have a look at this guide for some tips on fixing those: https://learn.adafruit.com/adafruit-gui ... n-problems

adafruit_support_bill
 
Posts: 74687
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.