I have been playing around with the PCA9685, trying to get it to drive a armature of servos, and I noticed that the libraries that are currently out there for interfacing with that component just aren't very well written, contain various bugs, and are far from fully functioned.
I would love it if somebody could take a look at it and make some suggestions for improvement, or if you have a PCA9685 controller, try out my library to see if it works any better.
I've made a ton of modifications and additions to the original fork, including adding all sorts of bells and whistles. The PWN phase range values actually are correct this time around (previous libraries were cutting them off), and does a bit more advanced load balancing. It's much more full featured, taking into account all the proxy'ing and daisy chaining features.
Overall, it's much better than any other library out there that I have found, even including the Adafruit supplied library.
Also, if anybody does use it and find it useful, I would love to hear so.
Hmm! I'm unsure! What would be some of the things to make it friendly? I haven't tried it on a lot of other devices, but given that the address pathways I'm using are quite similar to the Adafruit library, I'm sure it would work fairly well.
As long as it can do a bit of floating point math and can support a 400k baud rate on the TWI line, I'm sure it should be okay.
NachtRaveVL:
I've also added another assistant class to more easily control Servos through the PWM driver board, which is what I'm using mine for.
I have never used a library for this device just the data sheet and the I2C commands. Have you found a way of using the same chip for both a servo and LED's at the same time?
I found that this was impossible without putting an inverter on one of the outputs, either servo or LEDs. Otherwise the global chip parameter stopped one or other working correctly.
Grumpy_Mike:
I have never used a library for this device just the data sheet and the I2C commands. Have you found a way of using the same chip for both a servo and LED's at the same time?
I found that this was impossible without putting an inverter on one of the outputs, either servo or LEDs. Otherwise the global chip parameter stopped one or other working correctly.
From the programming side, the frequency of the output PWMs is global to the entire module, so for both Servos and LEDs at the same time it would likely only work if the LEDs also worked correctly on 50Hz, or whatever output frequency was set to run for the Servos.
Otherwise, I do not see what would stop them from working together properly, but I don't profess to be an electronics person.
Otherwise, I do not see what would stop them from working together properly
Oh so you have not attempted to actually use the servo and LEDs at the same time on the same chip.
Basically the servo pulse is upside down if the chip is first set up for LEDs and you have to invert them. I found this out doing this project for the Raspberry Pi, but you will get the same problem using an Arduino.
This is nothing to do with the PWM rate but the direct connection current sink mode for the LED drivers verses the pulse width and polarity you need for the servos. While you can get a static situation to work any proportional change gets screwed up.
The project video is here and it contains a link to the schematic and software I used.
The bad part about those libraries is that they are very poorly coded and do not expose the entire functionality of the chip. The library I have adapted from and modified fixes a lot of those issues while exposing the entire functionality the chip provides.
For example, with the Adafruit library, you absolutely must set the PWM frequency for the library to work. If you do not do that then it never sets the auto-increment value correctly for the other functions to work. It also sets the prescaler value incorrectly, and sets it using extra commands that are unnecessary and makes for a delay of 3ms instead of the 0.5ms clearly stated in the datasheet (for the oscillator to get up and running). Additionally, it does not do load distributing across the entire phase width, thus causing a large sink across all channels at the start of the phase cycle. It also forces you to use Wire1 for the Due/Zero/etc. instead of allowing you to specify which i2c line you wish to use.
Grumpy_Mike:
Oh so you have not attempted to actually use the servo and LEDs at the same time on the same chip.
Basically the servo pulse is upside down if the chip is first set up for LEDs and you have to invert them. I found this out doing this project for the Raspberry Pi, but you will get the same problem using an Arduino.
This is nothing to do with the PWM rate but the direct connection current sink mode for the LED drivers verses the pulse width and polarity you need for the servos. While you can get a static situation to work any proportional change gets screwed up.
The project video is here and it contains a link to the schematic and software I used. Meet Mulder in Mike's Pi Bakery on Vimeo
Hmm, well, one of the things I noticed with other codebases is that some were attempting to distribute out the high side of the square wave so that the sink was more widely distributed across the entirety of the phase width. I'm also doing something similar with my library.
Additionally, the boards being used have the option of installing a capacitor. The default one installed that I had was a 10v 1000uF cap, but I installed a bigger 10v 3300uF cap (dunno if it helped or hindered tho, since I'm not an electronics person :p). Below is a pic of the different cap I replaced on the board I'm using.
Grumpy_Mike:
The board uses I2C so for a
N ATtiny85 you will have to use a soft I2C bus driver.
Okay, I actually went ahead and programmed this in this afternoon. I haven't tested it on an ATtiny, since I don't have one, but one thing I noticed right away is that you'll need at least a 4MHz processor to run the minimum baud rate of 100kHz that the module requires.