Remarks

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

Code Example

private Pca8574 device;

public override Task Initialize()
{
    device = new Pca8574(Device.CreateI2cBus(1), 0x20, Device.Pins.D01);

    return base.Initialize();
}

public override Task Run()
{
    TestDigitalOutputPorts(10);

    return Task.CompletedTask;
}

private void TestDigitalOutputPorts(int loopCount)
{
    var out00 = device.CreateDigitalOutputPort(device.Pins.P0);
    var out01 = device.CreateDigitalOutputPort(device.Pins.P1);
    var out02 = device.CreateDigitalOutputPort(device.Pins.P2);
    var out03 = device.CreateDigitalOutputPort(device.Pins.P3);
    var out04 = device.CreateDigitalOutputPort(device.Pins.P4);
    var out05 = device.CreateDigitalOutputPort(device.Pins.P5);
    var out06 = device.CreateDigitalOutputPort(device.Pins.P6);
    var out07 = device.CreateDigitalOutputPort(device.Pins.P7);

    var outputPorts = new List<IDigitalOutputPort>()
    {
        out00, out01, out02, out03,
        out04, out05, out06, out07,
    };

    foreach (var outputPort in outputPorts)
    {
        outputPort.State = true;

        Thread.Sleep(100);
    }

    for (int l = 0; l < loopCount; l++)
    {
        // loop through all the outputs
        for (int i = 0; i < outputPorts.Count; i++)
        {
            // turn them all off
            device.AllOff();

            Thread.Sleep(1000);

            // turn them all on
            device.AllOn();
            Thread.Sleep(1000);

            // turn on just one
            Resolver.Log.Info($"Update pin {i} to {true}");
            outputPorts[i].State = true;
            Thread.Sleep(250);

            // turn off just one
            Resolver.Log.Info($"Update pin {i} to {false}");
            outputPorts[i].State = false;
            Thread.Sleep(250);
        }
    }

    // cleanup
    for (int i = 0; i < outputPorts.Count; i++)
    {
        outputPorts[i].Dispose();
    }
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object Pcx857x Pcx8574 > Pca8574
Implements IDigitalOutputController IDigitalInputController IDigitalInterruptController IPinController II2cPeripheral IDisposable
Inherited Members Pcx8574.Pins Pcx8574.NumberOfPins Pcx8574.IsValidPin(IPin) Pcx8574.GetPin(string) Pcx8574.SetPinDirection(bool, byte) Pcx8574.GetPinState(IPin) Pcx8574.SetPinState(IPin, bool) Pcx8574.ReadState() Pcx8574.WriteState(ushort) Pcx8574.SetState(ushort) Pcx8574.ReadState8() Pcx8574.WriteState(byte) Pcx857x.GetAddressFromPins(bool, bool, bool, bool) Pcx857x.DefaultI2cAddress Pcx857x.IsDisposed Pcx857x.createdPorts Pcx857x.i2cComms Pcx857x.CreateDigitalOutputPort(IPin, bool, OutputType) Pcx857x.CreateDigitalInputPort(IPin, ResistorMode) Pcx857x.CreateDigitalInterruptPort(IPin, InterruptMode, ResistorMode) Pcx857x.CreateDigitalInterruptPort(IPin, InterruptMode, ResistorMode, TimeSpan) Pcx857x.CreateDigitalInterruptPort(IPin, InterruptMode, ResistorMode, TimeSpan, TimeSpan) Pcx857x.AllOff() Pcx857x.AllOn() Pcx857x.Dispose(bool) Pcx857x.Dispose() object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.ICs.IOExpanders
Assembly Pcx857x.dll

Syntax

public class Pca8574 : Pcx8574, IDigitalOutputController, IDigitalInputController, IDigitalInterruptController, IPinController, II2cPeripheral, IDisposable

Constructors

Pca8574(II2cBus, byte, IDigitalInterruptPort?)

Initializes a new instance of the Pca8574 device

Declaration
public Pca8574(II2cBus i2cBus, byte address, IDigitalInterruptPort? interruptPort = null)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus the peripheral is connected to

byte address

The I2C bus address of the peripheral

IDigitalInterruptPort interruptPort

The interrupt port

Remarks

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

Code Example

private Pca8574 device;

public override Task Initialize()
{
    device = new Pca8574(Device.CreateI2cBus(1), 0x20, Device.Pins.D01);

    return base.Initialize();
}

public override Task Run()
{
    TestDigitalOutputPorts(10);

    return Task.CompletedTask;
}

private void TestDigitalOutputPorts(int loopCount)
{
    var out00 = device.CreateDigitalOutputPort(device.Pins.P0);
    var out01 = device.CreateDigitalOutputPort(device.Pins.P1);
    var out02 = device.CreateDigitalOutputPort(device.Pins.P2);
    var out03 = device.CreateDigitalOutputPort(device.Pins.P3);
    var out04 = device.CreateDigitalOutputPort(device.Pins.P4);
    var out05 = device.CreateDigitalOutputPort(device.Pins.P5);
    var out06 = device.CreateDigitalOutputPort(device.Pins.P6);
    var out07 = device.CreateDigitalOutputPort(device.Pins.P7);

    var outputPorts = new List<IDigitalOutputPort>()
    {
        out00, out01, out02, out03,
        out04, out05, out06, out07,
    };

    foreach (var outputPort in outputPorts)
    {
        outputPort.State = true;

        Thread.Sleep(100);
    }

    for (int l = 0; l < loopCount; l++)
    {
        // loop through all the outputs
        for (int i = 0; i < outputPorts.Count; i++)
        {
            // turn them all off
            device.AllOff();

            Thread.Sleep(1000);

            // turn them all on
            device.AllOn();
            Thread.Sleep(1000);

            // turn on just one
            Resolver.Log.Info($"Update pin {i} to {true}");
            outputPorts[i].State = true;
            Thread.Sleep(250);

            // turn off just one
            Resolver.Log.Info($"Update pin {i} to {false}");
            outputPorts[i].State = false;
            Thread.Sleep(250);
        }
    }

    // cleanup
    for (int i = 0; i < outputPorts.Count; i++)
    {
        outputPorts[i].Dispose();
    }
}

Sample project(s) available on GitHub

Pca8574(II2cBus, byte, IPin?)

Initializes a new instance of the Pca8574 device

Declaration
public Pca8574(II2cBus i2cBus, byte address, IPin? interruptPin)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus the peripheral is connected to

byte address

The I2C bus address of the peripheral

IPin interruptPin

The interrupt pin

Remarks

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

Code Example

private Pca8574 device;

public override Task Initialize()
{
    device = new Pca8574(Device.CreateI2cBus(1), 0x20, Device.Pins.D01);

    return base.Initialize();
}

public override Task Run()
{
    TestDigitalOutputPorts(10);

    return Task.CompletedTask;
}

private void TestDigitalOutputPorts(int loopCount)
{
    var out00 = device.CreateDigitalOutputPort(device.Pins.P0);
    var out01 = device.CreateDigitalOutputPort(device.Pins.P1);
    var out02 = device.CreateDigitalOutputPort(device.Pins.P2);
    var out03 = device.CreateDigitalOutputPort(device.Pins.P3);
    var out04 = device.CreateDigitalOutputPort(device.Pins.P4);
    var out05 = device.CreateDigitalOutputPort(device.Pins.P5);
    var out06 = device.CreateDigitalOutputPort(device.Pins.P6);
    var out07 = device.CreateDigitalOutputPort(device.Pins.P7);

    var outputPorts = new List<IDigitalOutputPort>()
    {
        out00, out01, out02, out03,
        out04, out05, out06, out07,
    };

    foreach (var outputPort in outputPorts)
    {
        outputPort.State = true;

        Thread.Sleep(100);
    }

    for (int l = 0; l < loopCount; l++)
    {
        // loop through all the outputs
        for (int i = 0; i < outputPorts.Count; i++)
        {
            // turn them all off
            device.AllOff();

            Thread.Sleep(1000);

            // turn them all on
            device.AllOn();
            Thread.Sleep(1000);

            // turn on just one
            Resolver.Log.Info($"Update pin {i} to {true}");
            outputPorts[i].State = true;
            Thread.Sleep(250);

            // turn off just one
            Resolver.Log.Info($"Update pin {i} to {false}");
            outputPorts[i].State = false;
            Thread.Sleep(250);
        }
    }

    // cleanup
    for (int i = 0; i < outputPorts.Count; i++)
    {
        outputPorts[i].Dispose();
    }
}

Sample project(s) available on GitHub