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);

    var 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)

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

Parameters

Type Name Description
II2cBus i2cBus
Frequency frequency
System.Byte address

Pca9685(II2cBus, Byte)

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

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

Fields

allCall

Declaration
protected const byte allCall = null

Field Value

Type Description
System.Byte

AllLedOffH

Declaration
protected const byte AllLedOffH = null

Field Value

Type Description
System.Byte

AllLedOffL

Declaration
protected const byte AllLedOffL = null

Field Value

Type Description
System.Byte

AllLedOnH

Declaration
protected const byte AllLedOnH = null

Field Value

Type Description
System.Byte

AllLedOnL

Declaration
protected const byte AllLedOnL = null

Field Value

Type Description
System.Byte

invert

Declaration
protected const byte invert = null

Field Value

Type Description
System.Byte

Led0OffH

Declaration
protected const byte Led0OffH = null

Field Value

Type Description
System.Byte

Led0OffL

Declaration
protected const byte Led0OffL = null

Field Value

Type Description
System.Byte

Led0OnH

Declaration
protected const byte Led0OnH = null

Field Value

Type Description
System.Byte

Led0OnL

Declaration
protected const byte Led0OnL = null

Field Value

Type Description
System.Byte

Mode1

Declaration
protected const byte Mode1 = null

Field Value

Type Description
System.Byte

mode1AI

Declaration
protected const byte mode1AI = null

Field Value

Type Description
System.Byte

Mode2

Declaration
protected const byte Mode2 = null

Field Value

Type Description
System.Byte

outDrv

Declaration
protected const byte outDrv = null

Field Value

Type Description
System.Byte

PreScale

Declaration
protected const byte PreScale = null

Field Value

Type Description
System.Byte

restart

Declaration
protected const byte restart = null

Field Value

Type Description
System.Byte

sleep

Declaration
protected const byte sleep = null

Field Value

Type Description
System.Byte

SubAdr1

Declaration
protected const byte SubAdr1 = null

Field Value

Type Description
System.Byte

SubAdr2

Declaration
protected const byte SubAdr2 = null

Field Value

Type Description
System.Byte

SubAdr3

Declaration
protected const byte SubAdr3 = null

Field Value

Type Description
System.Byte

Properties

i2CBus

The I2C bus connected to the pca9685

Declaration
public II2cBus i2CBus { get; protected 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()

SetFrequency(Frequency)

Declaration
protected virtual void SetFrequency(Frequency frequency)

Parameters

Type Name Description
Frequency frequency

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)

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

Parameters

Type Name Description
System.Byte pin
System.Int32 on
System.Int32 off

Write(Byte, Byte)

Declaration
protected virtual void Write(byte register, byte value)

Parameters

Type Name Description
System.Byte register
System.Byte value

Write(Byte, Byte, Byte, Byte, Byte)

Declaration
protected virtual void Write(byte register, byte ledXOnL, byte ledXOnH, byte ledXOffL, byte ledXOffH)

Parameters

Type Name Description
System.Byte register
System.Byte ledXOnL
System.Byte ledXOnH
System.Byte ledXOffL
System.Byte ledXOffH