PCA9685 turning all outputs on / off


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default PCA9685 turning all outputs on / off

    I'm working on a project that uses the PCA9685 chip. The chip is set up using the following code, which I confess was provided for me by a friend, but I get the gist of things in that it resets the chip and sets a pre-scaler or something !

    Code:
    'Initialize the PCA9685
    
    i2cControl      var BYTE                'Used for PCA chip control
    i2cReadAddress  var BYTE
    i2cWriteAddress var BYTE
    pcaAddress      var BYTE
    oldMode         var BYTE
    newMode         var BYTE
    pcaChannel      var BYTE
    
    i2cReadAddress = pcaAddress << 1
    i2cWriteAddress = i2cReadAddress | 1
    i2cControl = $0                                                     ;Reset
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[$0]              ;PCA9685_MODE1 $0
    i2cControl = $0                                                     'PCA9685_MODE1 $0
    I2CREAD SDApin,SCLpin,i2cReadAddress,i2cControl,[oldMode]           ;Get old mode
    newMode = (oldMode & $7F) | $10                                     ;MODE1 Sleep
    i2cControl = $0
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[newMode]         ;PCA9685_MODE1 $0
    i2cControl = $FE                                                    ;PCA9685_PRESCALE $FE
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[6]               ;Prescaler is now 6 was 11
    i2cControl = $0                                                     ;PCA9685_MODE1 $0
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[oldMode]         ;Set old mode
    i2cControl = $0                                                     ;PCA9685_MODE1 $0
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[oldMode | $A1 ]   ;Set MODE1 AutoIncrementOn | $A1
    Using word variables (CH1_PWM, CH2_PWN etc) for the 0 to 4095 PWM levels the following code performs the setting of channel brightness, (the value for pcaChannel runs through from 0 to 15 for the 16 channels with each increment of CHx_PWM variable if that makes sense ?)

    Code:
    pcaChannel = 0                                            
    i2cControl = $6 + 4*pcaChannel                            
    I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,CH1_PWM.lowbyte,CH1_PWM.highbyte]

    The above code is called when a time condition is matched, so each channel is has its own on/off time in a 24 hour period. But I want to have a manual over-ride so that if a button is pressed it jumps to a gosub routine which makes all the outputs of the PCA chip turn on. Looking at the datasheet https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf there is register setting to turn all the LEDs on or off (FA, FB, FC and FD) but I don't know how to implement this in the code, so wondered if anyone has some suggestions ?

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: PCA9685 turning all outputs on / off

    Well I got a work around

    Code:
    override:
    LCDOUT $FE,$D4,"All On "
    
    A=4095
    For B = 0 to 15
    pcaChannel = B                                           
        i2cControl = $6  + 4*pcaChannel                                                       
     I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,A.lowbyte,A.highbyte]
    next B 
    
    
    If IncButton=0 then
    A=0
    For B = 0 to 15
    pcaChannel = B 
    i2cControl = $6  + 4*pcaChannel 
        I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,A.lowbyte,A.highbyte]
    next B
    	Gosub SetButtonRelease
    	n=0
    LCDOUT $FE,$D4,"       "
    endif

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: PCA9685 turning all outputs on / off

    table 4 p 13 ...

    registers 250 to 255 ...

    What else ??? (Nespresso ? )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. PCA9685 control
    By Scampy in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th April 2016, 20:36
  2. Turning a smoke machine on/off with a triac
    By The Master in forum Off Topic
    Replies: 5
    Last Post: - 9th January 2011, 14:16
  3. Replies: 2
    Last Post: - 6th May 2010, 09:06
  4. turning leds on and off
    By mertkon in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th April 2007, 04:20
  5. Turning on & off multiple interrupts
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th June 2005, 17:50

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts