edlins / libPCA9685

superfast PCA9685 library for Debian platforms. developed on Raspbian on a Pi B+.
MIT License
13 stars 8 forks source link

Channels #68

Closed mbazzo closed 6 years ago

mbazzo commented 6 years ago

Hello, I would like to know how to connect only one channel of PCA9685 through this code. I am using "PCA9685_setAllPWM", and connect all channels, I would like to control the independent channels. Test like that and it did not work. setPWMVals (_pca, 0x40, 0, 1, 2000);

edlins commented 6 years ago

Hello! The following function documentation was accidentally left out of the README:

// set a single PWM channel with a 16-bit ON val and a 16-bit OFF val
int PCA9685_setPWMVal(int fd, unsigned char addr, unsigned char reg,
unsigned int on, unsigned int off);

Remember though, as with the other functions, only the low 12 bits of the 16-bit ON and OFF values are used on the PCA9685. Also keep in mind that this function does not use a combined transaction so it should be slower on a per-channel basis than the speedy PCA9685_setPWMVals().

Please let me know if this works for you or if your requirements are different.

edlins commented 6 years ago

Also, have a look at PCA9685demo. That shows how to set individual channels while still using setAllPWM(). You just keep track of all 16 of your values in an array and only change the values for the channels you want to adjust. Edit: Must not have finished my coffee.. From the quickstart example:

  unsigned int setOnVals[_PCA9685_CHANS] =
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  unsigned int setOffVals[_PCA9685_CHANS] =
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

  // blink endlessly 
  while (1) {
    // setup random values array (seizure mode)
    int i;
    for (i=0; i<_PCA9685_CHANS; i++) {
      int random = rand();
      int value = (float) random / (float) RAND_MAX * _PCA9685_MAXVAL;
      setOffVals[i] = value;
    }
    // set the on and off vals on the PCA9685
    PCA9685_setPWMVals(fd, addr, setOnVals, setOffVals);
}
pvint commented 6 years ago

If you check here you will see an example that worked: https://github.com/pvint/fade9685/commit/89578141407f9eb506f5fa170a79d237a063a882#diff-e1029dd5a7350ee44c988fd619e3baa4

(Note that this was just an early "proof of concept" and has since changed, but it worked)

edlins commented 6 years ago

Closing for lack of activity. Please open a new issue if you still require assistance.