Go Down

Topic: How do I test a board ? (Read 768 times) previous topic - next topic

hextejas

I think this is the 3rd one of these that I have and maybe I have ruined it as well.  Anyhow I have tried 3 different PWM example sketches and none of them work. The servos are ok as I can get them to work using a GPIO pin.
Code: [Select]
Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685


UKHeliBob

Please post a complete sketch used to test the servos with the Adafruit servo driver and describe what happens when you run it
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

TomGeorge

#2
Oct 31, 2020, 01:59 pm Last Edit: Oct 31, 2020, 01:59 pm by TomGeorge
Hi,

Can you please post a copy of your circuit showing how you connected the board to the controller, in CAD or a picture of a hand drawn circuit in jpg, png?
How do you know you have ruined the board?

Have you got a DMM?

What model Arduino are you using?

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

hextejas

#3
Oct 31, 2020, 03:23 pm Last Edit: Oct 31, 2020, 03:25 pm by hextejas
Sorry, the board is a Feather Huzzah ESP8266.
Again these are the ADAfruit PWM example sketches and what they do is nothing other than light the lights on the board showing power. The power via a VOM shows 5.25v. The power at the + and gnd pins of the 16 servo connectors show 5v whereas the PWM pin to gnd shows what looks like a sine wave with interference and about 3v.

Here is one.
Code: [Select]
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  PWM test - this will drive 16 PWMs in a 'wave'

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

  These drivers use I2C to communicate, 2 pins are required to  
  interface.

  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);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);

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

  pwm.begin();
  /*
   * In theory the internal oscillator (clock) is 25MHz but it really isn't
   * that precise. You can 'calibrate' this by tweaking this number until
   * you get the PWM update frequency you're expecting!
   * The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
   * is used for calculating things like writeMicroseconds()
   * Analog servos run at ~50 Hz updates, It is importaint to use an
   * oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
   * 1) Attach the oscilloscope to one of the PWM signal pins and ground on
   *    the I2C PCA9685 chip you are setting the value for.
   * 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
   *    expected value (50Hz for most ESCs)
   * Setting the value here is specific to each individual I2C PCA9685 chip and
   * affects the calculations for the PWM update frequency.
   * Failure to correctly set the int.osc value will cause unexpected PWM results
   */
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency

  // if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
  // some i2c devices dont like this so much so if you're sharing the bus, watch
  // out for this!
  Wire.setClock(400000);
}

void loop() {
  // Drive each PWM in a 'wave'
  for (uint16_t i=0; i<4096; i += 8) {
    for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) {
      pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
    }
#ifdef ESP8266
    yield();  // take a breather, required for ESP8266
#endif
  }
}

and here is another
Code: [Select]
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815
  
  These drivers use I2C to communicate, 2 pins are required to  
  interface.

  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);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);

// 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)
#define USMIN  600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX  2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates

// our servo # counter
uint8_t servonum = 0;

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

  pwm.begin();
  /*
   * In theory the internal oscillator (clock) is 25MHz but it really isn't
   * that precise. You can 'calibrate' this by tweaking this number until
   * you get the PWM update frequency you're expecting!
   * The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
   * is used for calculating things like writeMicroseconds()
   * Analog servos run at ~50 Hz updates, It is importaint to use an
   * oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
   * 1) Attach the oscilloscope to one of the PWM signal pins and ground on
   *    the I2C PCA9685 chip you are setting the value for.
   * 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
   *    expected value (50Hz for most ESCs)
   * Setting the value here is specific to each individual I2C PCA9685 chip and
   * affects the calculations for the PWM update frequency.
   * Failure to correctly set the int.osc value will cause unexpected PWM results
   */
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(SERVO_FREQ);  // Analog servos run at ~50 Hz updates

  delay(10);
}

// 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. It's not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;
  
  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= SERVO_FREQ;   // Analog servos run at ~60 Hz updates
  Serial.print(pulselength); Serial.println(" us per period");
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit");
  pulse *= 1000000;  // convert input seconds to us
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {
  // Drive each servo one at a time using setPWM()
  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);

  // Drive each servo one at a time using writeMicroseconds(), it's not precise due to calculation rounding!
  // The writeMicroseconds() function is used to mimic the Arduino Servo library writeMicroseconds() behavior.
  for (uint16_t microsec = USMIN; microsec < USMAX; microsec++) {
    pwm.writeMicroseconds(servonum, microsec);
  }

  delay(500);
  for (uint16_t microsec = USMAX; microsec > USMIN; microsec--) {
    pwm.writeMicroseconds(servonum, microsec);
  }

  delay(500);

  servonum++;
  if (servonum > 7) servonum = 0; // Testing the first 8 servo channels
}

UKHeliBob

Quote
I think this is the 3rd one of these that I have and maybe I have ruined it as well.
What happened to the first 2 to ruin them ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

TomGeorge

#5
Nov 01, 2020, 07:35 am Last Edit: Nov 01, 2020, 07:37 am by TomGeorge
Hi,

Can you please post a copy of your circuit showing how you connected the board to the controller, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a picture of your assembled  project please?

Check ALL your gnd connections, have you got the gnd of the servo  and both BOTH boards connected together?

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

runaway_pancake

Hard to believe as Adafruit is all about Tutorials and laying all the information out.

https://learn.adafruit.com/16-channel-pwm-servo-driver/hooking-it-up
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

hextejas

I am still working on this so it is not forgotten.. in the interim I got a new oscilloscope as a gift so I have been trying to learn it to help in figuring out this board.

hextejas

#8
Nov 04, 2020, 03:20 pm Last Edit: Nov 04, 2020, 03:27 pm by hextejas
This is the sketch.
Code: [Select]
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  PWM test - this will drive 16 PWMs in a 'wave'

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

  These drivers use I2C to communicate, 2 pins are required to  
  interface.

  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);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);

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

  pwm.begin();
  /*
   * In theory the internal oscillator (clock) is 25MHz but it really isn't
   * that precise. You can 'calibrate' this by tweaking this number until
   * you get the PWM update frequency you're expecting!
   * The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
   * is used for calculating things like writeMicroseconds()
   * Analog servos run at ~50 Hz updates, It is importaint to use an
   * oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
   * 1) Attach the oscilloscope to one of the PWM signal pins and ground on
   *    the I2C PCA9685 chip you are setting the value for.
   * 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
   *    expected value (50Hz for most ESCs)
   * Setting the value here is specific to each individual I2C PCA9685 chip and
   * affects the calculations for the PWM update frequency.
   * Failure to correctly set the int.osc value will cause unexpected PWM results
   */
  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency

  // if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
  // some i2c devices dont like this so much so if you're sharing the bus, watch
  // out for this!
  Wire.setClock(400000);
}

void loop() {
  // Drive each PWM in a 'wave'
  for (uint16_t i=0; i<4096; i += 8) {
    for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) {
      pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
    }
#ifdef ESP8266
    yield();  // take a breather, required for ESP8266
#endif
  }
}

and here are the setups. What I did was wire up an UNO and the sketch worked. I switched the 4 wires to a Feather Huzzah and it doesnt work.
The 4 colored wires are:
White: SDA
Yellow: SCL
Orange: 5v from the processor.
Green: Ground from the processor.
=========
Separate Red and Yellow to a desktop power supply 5V and Gnd.

The probe goes from one of the 16 pins on the PCA9685, PWM and GND pins, to the scope.
The Feather scope shows flat line whereas the UNO shows what I want to see.
I think the Feather is ok as it runs Blink ok, though I am not sure that is a fair test.
Feather Huzzah

No good

With the UNO

Proper results

TomGeorge

#9
Nov 05, 2020, 06:32 am Last Edit: Nov 05, 2020, 06:36 am by TomGeorge
Hi,
Check the SDA and SCL signals with the scope.
Do you have 4k7 pullup resistors on your SDA and SCL lines?

Sorry but your project pictures are out of focus for us to see anything.
When you post scope pictures can you please state the vertical and horizontal setting.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....


hextejas

Hi,
Check the SDA and SCL signals with the scope.
Do you have 4k7 pullup resistors on your SDA and SCL lines?

Sorry but your project pictures are out of focus for us to see anything.
When you post scope pictures can you please state the vertical and horizontal setting.

Tom... :)
No pull-up resistor and I don't know why the pictures are out of focus. They look ok from my side.
Here is a picture of the Adafruit wiring .

hextejas

This is the wiring


TomGeorge

Hi,
Have you tried pullup resistors on the SDA and SCL lines?
If not please try.

Your pictures lack any resolution, they are to small and when you zoom in there is no detail. Sorry.
Please down load image_1330 from the forum and have a look.

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

hextejas

Hi,
Have you tried pullup resistors on the SDA and SCL lines?
If not please try.

Your pictures lack any resolution, they are to small and when you zoom in there is no detail. Sorry.
Please down load image_1330 from the forum and have a look.

Tom... :)
Ok Tom, I will try the pullup resistors as soon as I can figure out what it is. Off to do some reading........
Ok, I now know what they are. Though the videos that I saw led me to ask this. If I put +5v on SDA & SCL  what happens when the Sketch also tries to control those pins ? Should it be a pull-down resistor maybe. Sigh, more testing.

Go Up