Remarks

Pca9685
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.ICs.IOExpanders.Pca9685

Code Example

Pca9685 pca9685;

public override Task Initialize()
{
    Console.WriteLine("Initialize...");
    var i2CBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);

    pca9685 = new Pca9685(i2CBus, new Meadow.Units.Frequency(50, Meadow.Units.Frequency.UnitType.Hertz), (byte)Pca9685.Addresses.Default);
    pca9685.Initialize();

    return base.Initialize();
}

public override Task Run()
{
    var port0 = pca9685.CreatePwmPort(0, 0.05f);
    var port7 = pca9685.CreatePwmPort(7);

    port0.Start();
    port7.Start();

    return base.Run();
}

Sample project(s) available on GitHub

Wiring Example

To wire a PCA9685 to your Meadow board, connect the following:

Characteristic Locus
Inheritance System.Object > Pca9685
Namespace Meadow.Foundation.ICs.IOExpanders
Assembly Pca9685.dll

Syntax

public class Pca9685 : object

Constructors

Pca9685(II2cBus, Frequency, Byte)

Create a new Pca9685 object

Declaration
public Pca9685(II2cBus i2cBus, Frequency frequency, byte address = null)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus connected to the peripheral

Frequency frequency

The frequency

System.Byte address

The I2C address

Pca9685(II2cBus, Byte)

Create a new Pca9685 object

Declaration
public Pca9685(II2cBus i2cBus, byte address = null)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus connected to the peripheral

System.Byte address

The I2C address

Properties

i2CBus

The I2C bus connected to the pca9685

Declaration
protected II2cBus i2CBus { get; set; }

Property Value

Type Description
II2cBus

Methods

CreatePwmPort(Byte, Single)

Create a IPwmPort on the specified pin

Declaration
public virtual IPwmPort CreatePwmPort(byte portNumber, float dutyCycle = 0.5F)

Parameters

Type Name Description
System.Byte portNumber

The port number (0-15)

System.Single dutyCycle

The duty cycle for that port

Returns

Type Description
IPwmPort

IPwmPort

Initialize()

Initializes the PCA9685 IC

Declaration
public virtual void Initialize()

SetPin(Byte, Boolean)

Turns the specified pin On or Off

Declaration
public virtual void SetPin(byte pin, bool on)

Parameters

Type Name Description
System.Byte pin

The pin to set

System.Boolean on

true is on, false if off

SetPwm(Byte, Int32, Int32)

Set the values for specified output pin.

Declaration
public virtual void SetPwm(byte pin, int on, int off)

Parameters

Type Name Description
System.Byte pin

The pwm Pin

System.Int32 on

LED{X}_ON_L and LED{X}_ON_H registier value

System.Int32 off

LED{X}_OFF_L and LED{X}_OFF_H registier value

Remarks

On parameter is an inverted pwm signal