Menu

PCA9685 PWM Driver - formal release and demos

Anobium
2018-07-14
2018-08-06
<< < 1 2 3 > >> (Page 2 of 3)
  • Anobium

    Anobium - 2018-07-23

    PCA9685_Initialise will init all devices that have a valid constant as shown above and repeated below for clarity.

    This example would init two devices on address 0x80 and x82.

               #define PCA9685_ADDRESS_1 0x80
               #define PCA9685_ADDRESS_2 0x82
              '    #define PCA9685_ADDRESS_3 0x84
              '    #define PCA9685_ADDRESS_4 0x86
    

    PCA9685_SetFreqency will set the frequency of one device that has a valid constant as shown above and repeated below for clarity. Where [, device IC2 Address] is an optional value. Where device IC2 Address is a valid I2C address.

    PCA9685_SetFreqency ( frequency_wordvalue [, device IC2 Address] )


    And, you have replace the .h file in your include folder? If not, do replace with the new version.


    Do us a favor. DO NOT POST code like that. Apart from the fact that it is incomplete code - I cannot view the post on my phone.

     

    Last edit: Anobium 2018-07-23
  • stan cartwright

    stan cartwright - 2018-07-23

    OK. It could have waited 'till after your hols,sorry to disturb.
    Are #define PCA9685_ADDRESS_1 0x80
    #define PCA9685_ADDRESS_2 0x82
    0x84, 0x86 only used?
    as the first extra board I soldered A0 link so it's address is 0x81....should I have soldered link 2 instead,so it's address is 0x82?
    I'm using :#define PCA9685_ADDRESS_1 0x80 and #define PCA9685_ADDRESS_1 0x81.
    0x80 is working not second board,0x81

     
  • Anobium

    Anobium - 2018-07-23

    You are kidding.   Each device has two adresses and you have that totally wrong. Each device would be two addresses   apart.

    And, always, always, always check the address with only one   device   on the i2c bus   using i2c discovery to your serial terminal.

    So, comfirm addresses.   Then, retry.

     
  • stan cartwright

    stan cartwright - 2018-07-23

    The "solder address jumper" on board 2 is normal and tech griff says it give device A0 soldered base address plus one. This is necessary??
    one device was easy to use with your subs then include. I am assuming the second device is working but no idea of correct commands to apply to use 2nd board ... presuming same led 0 to 15 for 2nd board.
    Please correct me as to hi2c use..no points for me trying clueless.
    At least you have a gcb tester. If I could sort it my self I would.
    errors on this please

    #chip mega328p,16
    #option Explicit
    #include <PCA9685.h>
    #define PCA9685_ADDRESS_1 0x80
    #define PCA9685_ADDRESS_2 0x81
    #define hi2c_BAUD_RATE 100
    #define hi2c_DATA PORTC.4
    #define hi2c_CLOCK PORTC.5
    hi2cMode Master
    
    'The call IS required to setup the device
    PCA9685_Initialise
    
    'Set the frequency using the Great Cow BASIC PWM constant
    #define PWM_Freq 50,PCA9685_ADDRESS_1 ;50Hz for servo
    PCA9685_SetFreqency ( 50,PCA9685_ADDRESS_1 )
    ;PCA9685_SetFreqency ( 50,PCA9685_ADDRESS_2 )
    dim servo as byte
    dim servopos as word ;servo angle
    dim deg0,deg180 as word
    
    deg180=520 ;2.41mS
    deg0=110 ;85=400 mS 140=650ms
    servo=0 ;servo degrees wanted
        servopos=scale (servo,0,179,deg0,deg180)
        PCA9685_WriteChannel (PCA9685_LED0 ,0, servopos , PCA9685_ADDRESS_1)
        PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos ,PCA9685_ADDRESS_1)
        PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos,PCA9685_ADDRESS_2 )
    '
    ;do
    ;loop
    

    using new include

     

    Last edit: stan cartwright 2018-07-23
  • Anobium

    Anobium - 2018-07-24

    OK. Here goes. Seriously thankful you are willing to test.

    1. Remove the devices from the I2C bus. Run I2C discovery you should have NO I2C devices shown.
    2. Take one device and attach to the I2C bus. Run I2C discovery you should one I2C device shown. Note this down - we will call this information PCA9685_ADDRESS_1
    3. Remove the device from the I2C bus.
    4. Take the oher device and attach to the I2C bus. Run I2C discovery you should one I2C device shown. Note this down - we will call this information PCA9685_ADDRESS_2

    What is really, really important at this point is that these address are at least two address apart. Where the theory is ABS( PCA9685_ADDRESS_2 - PCA9685_ADDRESS_1) > 1. You current have ABS( 0x81 - 0x81) with the result of 1, so, your addressing is invalid. But, completing steps 2 and 4 this will confirm the I2C address for each device.

    1. Remove the device from the I2C bus.
    2. Take device with the address PCA9685_ADDRESS_1. Attach to I2C bus. Test using the PWM code. Ensure the constant PCA9685_ADDRESS_1 is defined as determined at step #2.
    #chip mega328p,16
    #option Explicit
    #include <PCA9685.h>
    #define PCA9685_ADDRESS_1 0x80     'validate from step 2
    #define PCA9685_ADDRESS_2 0x82     'validate from step 4
    #define hi2c_BAUD_RATE 100
    #define hi2c_DATA PORTC.4
    #define hi2c_CLOCK PORTC.5
    hi2cMode Master
    
    'The call IS required to setup the device
    PCA9685_Initialise
    
    'Set the frequency using the Great Cow BASIC PWM constant
    #define PWM_Freq 50         '50Hz for servo
    
    PCA9685_SetFreqency ( 50,  PCA9685_ADDRESS_1 )
    PCA9685_SetFreqency ( 50,  PCA9685_ADDRESS_2 )
    
    dim servo as byte
    dim servopos as word ;servo angle
    dim deg0,deg180 as word
    
    deg180=520 ;2.41mS
    deg0=110 ;85=400 mS 140=650ms
    servo=0 ;servo degrees wanted
        servopos=scale (servo,0,179,deg0,deg180)
        PCA9685_WriteChannel (PCA9685_LED0 ,0, servopos , PCA9685_ADDRESS_1)
        PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos ,PCA9685_ADDRESS_1)
        PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos,PCA9685_ADDRESS_2 )
    
    do
    loop
    

    Note the results. Did it work? Do things happen as expected? If not we have an issue. No point in proceeding. Create a ZIP of the project - Source, ASM. LST file. Rename as PCA9685Device_1_Report.zip. Goto to step 11.

    1. Remove the device from the I2C bus.
    2. Take device with the address PCA9685_ADDRESS_2 Attach to I2C bus. Test using the PWM code. Ensure the constant PCA9685_ADDRESS_2 is defined as determined at step #4.

    Note the results. Did it work? Do things happen as expected? If not we have an issue. No point in proceeding. Create a ZIP of the project - Source, ASM. LST file. Rename as PCA9685Device_2_Report.zip. Goto to step 11.

    1. Add the second device from the I2C bus.
    2. Ensure the constantsdetermined at step #2 and #4 are correct.

    Note the results. Did it work? Do things happen as expected? If not stop here. No point in proceeding. Create a ZIP of the project - Source, ASM. LST file. Rename as PCA9685Device_12_Report.zip

    Lots to do. :-)

    1. If you do get issues at step 6 or 8 then I want you to repeat the tests. Within only one device device attached using the old .h, update the address - does that work?

    Even more to do.

     
  • stan cartwright

    stan cartwright - 2018-07-24

    first board i2c write 0x80,read 0x81.
    second board with A0 soldered write 0x81,read 0x82.
    unsoldered A0 and soldered A1. i2c address write 0x82,read 0x83
    neither board works with new pca9685.h

     
  • Anobium

    Anobium - 2018-07-24

    The   boards cannot have overlapping addresses.   Change until the addresses are   not overlapping. At the moment they do. Needs to be   always an even and odd address   per device.... you have second board on 0x81 & 0x82 needs to be changed.

     
  • stan cartwright

    stan cartwright - 2018-07-24

    I thought I zipped file with #include <PCA9685.h>

    define PCA9685_ADDRESS_1 0x80 --- board 0 no soldered links

    define PCA9685_ADDRESS_2 0x82 --- board 1 A1 link soldered.

    this caused syntax error but copy pasting identical line that passed syntax sorted.
    PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos, PCA9685_ADDRESS_2 )

     
    • Anobium

      Anobium - 2018-07-24

      Nope.   I have no idea what the post above   is about.

       
  • stan cartwright

    stan cartwright - 2018-07-24

    The boards cannot have overlapping addresses. Change until the addresses are not overlapping. At the moment they do.
    board 0 0x80 , board 1 0x82.
    is that ok? it is used in zip file as in

    define PCA9685_ADDRESS_1 0x80 --- board 0 no soldered links
    define PCA9685_ADDRESS_2 0x82 --- board 1 A1 link soldered.
    

    the big print just happened, forgot ~~~
    https://learn.adafruit.com/assets/2223 but using A1 for second board

     

    Last edit: stan cartwright 2018-07-24
  • Anobium

    Anobium - 2018-07-25

    OK.Repeat what I said yesterday.

    1. Remove the devices from the I2C bus. Run I2C discovery you should have NO I2C devices shown. You have not told me that you have proven the address using I2C discovery - are you using the board to estimate the address? and, do this with only one device attached
    2. Take one device and attach to the I2C bus. Run I2C discovery you should one I2C device shown. Note this down - we will call this information PCA9685_ADDRESS_1
    3. Remove the device from the I2C bus.
    4. Take the oher device and attach to the I2C bus. Run I2C discovery you should one I2C device shown. Note this down - we will call this information PCA9685_ADDRESS_2 You have not told me that you have proven the address using I2C discovery - are you using the board to estimate the address? and, do this with only one device attached

    What is really, really important at this point is that these address are at least two address apart. Where the theory is ABS( PCA9685_ADDRESS_2 - PCA9685_ADDRESS_1) > 1. You current have ABS( 0x81 - 0x81) with the result of 1, so, your addressing is invalid. But, completing steps 2 and 4 this will confirm the I2C address for each device.

    1. Remove the device from the I2C bus.
    2. Take device with the address PCA9685_ADDRESS_1. Attach to I2C bus. Test using the PWM code. Ensure the constant PCA9685_ADDRESS_1 is defined as determined at step #2.
      You used your own code. It has errors and is not the based code I recommended you use.
    #chip mega328p,16
    #option Explicit
    #include <PCA9685.h>
    #define PCA9685_ADDRESS_1 0x80     'validate from step 2
    #define PCA9685_ADDRESS_2 0x82     'validate from step 4
    #define hi2c_BAUD_RATE 100
    #define hi2c_DATA PORTC.4
    #define hi2c_CLOCK PORTC.5
    hi2cMode Master
    
    'The call IS required to setup the device
    PCA9685_Initialise
    
    'Set the frequency using the Great Cow BASIC PWM constant
    #define PWM_Freq 50         '50Hz for servo
    
    PCA9685_SetFreqency ( 50,  PCA9685_ADDRESS_1 )
    PCA9685_SetFreqency ( 50,  PCA9685_ADDRESS_2 )
    
    dim servo as byte
    dim servopos as word ;servo angle
    dim deg0,deg180 as word
    
    deg180=520 ;2.41mS
    deg0=110 ;85=400 mS 140=650ms
    servo=0 ;servo degrees wanted
        servopos=scale (servo,0,179,deg0,deg180)
        PCA9685_WriteChannel (PCA9685_LED0 ,0, servopos , PCA9685_ADDRESS_1)
        PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos ,PCA9685_ADDRESS_1)
        PCA9685_WriteChannel (PCA9685_LED15 ,0, servopos,PCA9685_ADDRESS_2 )
    
    do
    loop
    

    Note the results. Did it work? Do things happen as expected? If not we have an issue. No point in proceeding. Create a ZIP of the project - Source, ASM. LST file. Rename as PCA9685Device_1_Report.zip.
    Your ZIP is not using the reference code above and one contain a two device test - one device please

    1. Remove the device from the I2C bus.
    2. Take device with the address PCA9685_ADDRESS_2 Attach to I2C bus. Test using the PWM code. Ensure the constant PCA9685_ADDRESS_2 is defined as determined at step #4.

    Note the results. Did it work? Do things happen as expected? If not we have an issue. No point in proceeding. Create a ZIP of the project - Source, ASM. LST file. Rename as PCA9685Device_2_Report.zip.

    Your ZIP is not using the reference code above and one contain a two device test - one device please

    1. Add the second device from the I2C bus.
    2. Ensure the constantsdetermined at step #2 and #4 are correct.

    Note the results. Did it work? Do things happen as expected? If not stop here. No point in proceeding. Create a ZIP of the project - Source, ASM. LST file. Rename as PCA9685Device_12_Report.zip Your ZIP is not using the reference code above

    1. If you do get issues at step 6 or 8 then I want you to repeat the tests. Within only device device attached using the old .h, update the address - does that work? You sad it does not work. Does not work with only one device attached?
     
  • stan cartwright

    stan cartwright - 2018-07-25

    hi2c finder gives address as 0x80 for board 0 -- PCA9685_ADDRESS_1 -- no links soldered.
    hi2c finder gives address as 0x82 for board 1 -- PCA9685_ADDRESS_2 -- A1 link soldered.
    The code does nothing with board 0, board 1 or both.

     
  • stan cartwright

    stan cartwright - 2018-07-25

    In the new pca9685.h...is this containing typo?
    Sub PCA9685_WriteChannel( _localregister as byte, _localValueOn as word, _localValueOff as word, Optional In _localDevice as byte = PCA9685_ADDRESS_1 )

     
    • Anobium

      Anobium - 2018-07-25

      Where is the error? I cannot see it.

       
  • stan cartwright

    stan cartwright - 2018-07-25

    Optional In _localDevice as byte = PCA9685_ADDRESS_1
    elsewhere _localDevice is used.
    Sub PCA9685_WriteChannel( _localregister as byte, _localValueOn as word, _localValueOff as word, Optional In _localDevice as byte = PCA9685_ADDRESS_1 )

    'Requires Mode1.AI=1 and Mode1.OCH = 0 - these ARE MANDATED

    ~~~
    #ifdef HI2C_DATA
    do
    HI2CRESTART
    HI2CSend( _localDevice)
    ~~~

     
    • Anobium

      Anobium - 2018-07-25

      I am not being dim. But,   cannot make out the difference. Ping me on Google

       
  • stan cartwright

    stan cartwright - 2018-07-25

    Sub PCA9685_WriteChannel( _localregister as byte, _localValueOn as word, _localValueOff as word, Optional In _localDevice as byte = PCA9685_ADDRESS_1 )

    I am not being dim. But,.... Optional In _localDevice as byte = PCA9685_ADDRESS_1 )
    why is it defined as PCA9685_ADDRESS_1 ?

     
    • Anobium

      Anobium - 2018-07-25

      That is the default value. Optional means that is you do not provide that   parameter then the value will be set to address_1

      I   have used throughout to ensure that if you had one device all will work.

      I have inspected your ASM in the Zip. Everything   looks ok but it is clearly not.   Ping me on Google Chat so others do not to track our conversation.

       
  • stan cartwright

    stan cartwright - 2018-07-25

    Success!
    The i2c address solder links info could be clarified.
    This code attatchment works.runs a servo off each board.
    https://youtu.be/HFPG7Ra0uVQ
    with only 2 boards, changing/soldering the second boards address might be non conclusive without more boards on the bus...so I didn't bother. 32 servos is enough.??
    following on.. #define PWM_Freq 50,PCA9685_ADDRESS_1 ;50Hz for servo
    please clarify PCA9685_ADDRESS_1 from your previous description.
    I have this in working code

    'Set the frequency using the Great Cow BASIC PWM constant
    #define PWM_Freq 50,PCA9685_ADDRESS_1 ;50Hz for servo
    PCA9685_SetFreqency ( 50,PCA9685_ADDRESS_1 )
    PCA9685_SetFreqency ( 50,PCA9685_ADDRESS_2 )
    

    the line - #define PWM_Freq 50,PCA9685_ADDRESS_1 ;50Hz for servo
    can be erased - not needed.
    I hope this is all relevant. would others have made the same errors as me?
    I followed the instructions,read addresses weren't mentioned.data for arduino not relevant..but there.

     

    Last edit: stan cartwright 2018-07-25
  • stan cartwright

    stan cartwright - 2018-07-25

    thanks again for the pca9685.h and support time for users.
    from my code you can see me trying different values to calibrate the servo. .... you have to experiment with servos to comment. yawn

     
    • Anobium

      Anobium - 2018-07-26

      Good news. New library works.

      I will promote the new library to the release code tomorrow.

      Well done Stan.

       
  • stan cartwright

    stan cartwright - 2018-07-26

    Let users be wary of good intentioned arduino guides for this board. They don't take account of read addresses... but they're available.
    The advice for the solder links is first extra board solder A0.
    next extra board solder A1.
    next extra board solder A0 and A1.
    Using 2 boards -- first board don't solder any links. second board solder A0.
    connect both boards and use i2c finder to find addresses of both boards and use those values.
    ... or you'll be on a fools errand.

     
  • stan cartwright

    stan cartwright - 2018-07-29

    Not understanding why this doesn't work

    deg180=520 ;2.41mS
    deg0=110 ;85=400 mS 140=650ms
    servo=90 ;servo degrees wanted
    servopos=scale (servo,0,179,deg0,deg180)
    PCA9685_WriteChannel (PCA9685_led0 ,0, servopos, PCA9685_ADDRESS_1 )
    PCA9685_WriteChannel (PCA9685_LED1 ,0, servopos, PCA9685_ADDRESS_1 )
    PCA9685_WriteChannel (PCA9685_LED2 ,0, servopos, PCA9685_ADDRESS_1 )
    
    PCA9685_WriteChannel (PCA9685_led0 ,0, servopos, PCA9685_ADDRESS_2 )
    PCA9685_WriteChannel (PCA9685_LED1 ,0, servopos, PCA9685_ADDRESS_2 )
    PCA9685_WriteChannel (PCA9685_LED2 ,0, servopos, PCA9685_ADDRESS_2 )
    

    that works but is tedious for lots of leds.
    I tried

    dim pca9685_channel as word ; why word?
    for pca9685_channel = 0 to 2
        PCA9685_WriteChannel (PCA9685_channel ,0, servopos, PCA9685_ADDRESS_1 )
        PCA9685_WriteChannel (PCA9685_channel ,0, servopos, PCA9685_ADDRESS_2 )    
     next 
    

    doesn't work..gives zero ie servos swing total one way.
    I looked at the include code.
    I've been building a hexbot. Drill bit snapped and went through my thumb nail.
    Bought aluminium trim from screwfix..more on order. handy stuff.
    More pictures when the legs finished.

     
  • stan cartwright

    stan cartwright - 2018-07-30

    It's not working as it should. No one as one for comparison.
    psu for servos and psu for arduino??
    diy is not fun .. image

     
  • stan cartwright

    stan cartwright - 2018-07-31

    Hope it's ok for feed back here ..not open a topic.
    sometimes it locks up,needs arduino reset button pressed.
    first test https://youtu.be/YtKqmKKk4gk
    Thanks again for your time working on this Evan.

     
<< < 1 2 3 > >> (Page 2 of 3)

Log in to post a comment.