Hello, Hello Hello, Hello,
Topic moved !! Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.
I don't think that anybody can say anything useful about this if you don't post the sketch with for the PCA9685.
You will also have to explain what "it didn't work" means.
Quite a reasonable guess. Install the Adafruit library for the PCA9685 and use that.
Excellent resource...
Before when I tried this sketch
If you take a look into the adafruit--servo-demo-sketch
/***************************************************
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
}
In this adafruit-servo-demo-sketch
do you see any lines of code containing
No !
the library
#include <Servo.h>
uses io-pins of the microcontroller DIRECTLY
the library
#include <Adafruit_PWMServoDriver.h>
uses the I2C-bus to send control-command to the Adafruit PCA9685 16-Channel Servo Driver
which is something completely different.
explained with pictures
you have this kind of screws
servo.h
and you try to drive the screws above with this tool
Adafruit_PWMServoDriver.h
this can not work. NEVER !
So take the adafruit-servo-demo-code as your base and modify it to your needs
and don't know how to write it.
make an own attempt to add the random-function into the adafruit-sketch.
Make this attempt even if you feel totally unsecure if this will be correct.
Then post the un-modified sketch and the modified sketch
post in which line-numbers youmodified the code
write a description what your modified sketch does with the servos.
"does not work" is wayyyyy toooo unprecise.
examples for more precision:
"servo1 does a short move for estimated 5 degrees then stands still
servo2, servo 3 do not move at all
Because you "talk" like you are an absolute novice, I will hold your hand for a little while...
The site shows you how to use the mux to address a channel to send an angle to a servo.
Your homework is to figure out what random(16)
and random(180)
mean.
Drop your "I demand answers in a wrapped package" and do some learning.
Show me the exact post where I said those exact words.
I asked for help not for some one to hold my hand. If you would have said
"use the mux to address a channel to send an angle to a servo.
Your homework is to figure out what random(16)
and random(180)
mean" that would have helped a lot.
Yes, I am an almost complete novice at this. I can work with some of the code and make them work but this one has been a problem.
This is you expecting a just-for-you, drop-in-ready, sketch.
This is you being typical... finding ways to be offensive then deny it through this "exactly" crap.
Yes you did... and you repeated it... here...
You are far from ever giving me instructions in anything. Also, had I not said "that," I would not have conveyed to you what "I" think of the style of your communication. Be agreeable, or you get what you give. I'm here to help.
No! Bad boy.
I'm fine with that. 100%. I have shown many hundreds how to do many things technical, construction, mechanical, agricultural... most of them far removed from programing. This is a new playground for me. I quit a life of high-tech long ago, and have started again with only tinkering. You will have fun. So will I.
Download the PCA9685 datasheet and open the PCA9685 library files (PCA9685.h and PCA9685.CPP) which will show you the guts of the library, how you send data to and retrieve data from the "instance/object" you created with the library.
Do some work, then ask questions. Include what you did and what you observed. See Post #7 for lots of good information. You will get what you need... just supply what we need to get you there.