PCA9685 PWM Driver

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

PCA9685 PWM Driver

Post by deshipu » Mon Jun 27, 2016 9:06 pm

This chip is actually used in two different modules. First it's used in the 16-channel I²C servo (and LED) drivers. Second, it's also used in Adafruit's motor shield. That's why apart from the main module, which lets you control the chip directly, there are also two others, specifically for the servos and the DC motors.

The source code is at https://bitbucket.org/thesheep/micropython-pca9685/src

User avatar
VisualEcho
Posts: 17
Joined: Mon Jul 04, 2016 7:49 pm
Location: Ann Arbor, Michigan
Contact:

Re: PCA9685 PWM Driver

Post by VisualEcho » Wed Jul 06, 2016 2:53 am

[quote="deshipu"]used in the 16-channel I²C servo (and LED) drivers[/quote]

Yes it is, and this is useful, thanks!

User avatar
VisualEcho
Posts: 17
Joined: Mon Jul 04, 2016 7:49 pm
Location: Ann Arbor, Michigan
Contact:

Re: PCA9685 PWM Driver

Post by VisualEcho » Mon Jul 25, 2016 1:54 pm

I think there may be a bug in the servo.py file. In class init, setting period before calling _us2duty() (to set the min and max duty) seems like a good idea.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: PCA9685 PWM Driver

Post by deshipu » Mon Jul 25, 2016 2:28 pm

Argh, you are right. Sorry about it, I rearranged the lines for better reading and didn't test it afterwards.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: PCA9685 PWM Driver

Post by pidou46 » Wed Sep 07, 2016 7:25 am

Hi,

Thanks for this useful library.
As I'm a newbie a minimal code sample would be helpful for me.

I'm able to create a servo object, but I'm not able to make it move.

I have not understand what the "index" parameter stand for ? I guess it is related to the output selection, but it seems not to be directly the output number engraved on the board [0-15]

Thanks
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: PCA9685 PWM Driver

Post by deshipu » Wed Sep 07, 2016 9:35 am

Sorry for the lack of documentation, I will try to improve that a bit in the coming days.

You guessed correctly, "index" is the number of the board's output. Note that it starts with 0, so it may be off-by-one compared to what is printed on your board (I don't know which board you are using, so hard to say).

This should move all servos to the central positions:

Code: Select all

from machine import I2C, Pin
import servo

servos = servo.Servos(I2C(scl=Pin(5), sda=Pin(4))
for i in range(16):
    servos.position(i, us=1500)

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: PCA9685 PWM Driver

Post by pidou46 » Thu Sep 08, 2016 8:24 pm

Thanks alot,

My mistake was not on the software side, I had reversed the polarity of the power port of the adafruit breakboard's.

Nota: when the power led is red, it means the power for the chip is ok (green would have been better thought ;) ), it not mean power for servos is ok... But the board is protected from heedless guy and it's the most important (for me)
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: PCA9685 PWM Driver

Post by pidou46 » Sat Apr 01, 2017 3:38 pm

hello,

I'm back playing with PCA9685 and your helpful library.

I see that it's also possible to drive DC motor, it's something I would want to try, but I don't understand how I should wiring it ?

What kind of motor should I be able to drive ?

I would like to recycle some two wire DC motors, does it could work ?

Thanks
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: PCA9685 PWM Driver

Post by deshipu » Sat Apr 01, 2017 7:04 pm

The motor.py library is for this shield: https://www.adafruit.com/products/2927

There is a schematic in its documentation if you want to recreate the same circuit.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: PCA9685 PWM Driver

Post by pidou46 » Tue Apr 04, 2017 7:06 pm

Thank a lot deshipu,

I understand,

I don't own a FeatherWing, but I think I can do it with a H bridge, type L298N
Attachments
L298N.png
L298N.png (50.83 KiB) Viewed 13901 times
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

Post Reply