Skip to main content

Meadow.Foundation.ICs.IOExpanders.Pcf8575

Pcf8575
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.ICs.IOExpanders.Pcx857x

Code Example

private Pcf8575 device;

public override Task Initialize()
{
device = new Pcf8575(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.P00);
var out01 = device.CreateDigitalOutputPort(device.Pins.P01);
var out02 = device.CreateDigitalOutputPort(device.Pins.P02);
var out03 = device.CreateDigitalOutputPort(device.Pins.P03);
var out04 = device.CreateDigitalOutputPort(device.Pins.P04);
var out05 = device.CreateDigitalOutputPort(device.Pins.P05);
var out06 = device.CreateDigitalOutputPort(device.Pins.P06);
var out07 = device.CreateDigitalOutputPort(device.Pins.P07);

var out10 = device.CreateDigitalOutputPort(device.Pins.P10);
var out11 = device.CreateDigitalOutputPort(device.Pins.P11);
var out12 = device.CreateDigitalOutputPort(device.Pins.P12);
var out13 = device.CreateDigitalOutputPort(device.Pins.P13);
var out14 = device.CreateDigitalOutputPort(device.Pins.P14);
var out15 = device.CreateDigitalOutputPort(device.Pins.P15);
var out16 = device.CreateDigitalOutputPort(device.Pins.P16);
var out17 = device.CreateDigitalOutputPort(device.Pins.P17);

var outputPorts = new List<IDigitalOutputPort>()
{
out00, out01, out02, out03,
out04, out05, out06, out07,
out10, out11, out12, out13,
out14, out15, out16, out17
};

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

Thread.Sleep(1000);
}

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

Class Pcf8575

Represents the Pcf8575 8-bit I/O I2C expander

Assembly: Pcx857x.dll
View Source
Declaration
public class Pcf8575 : Pcx8575, IDigitalOutputController, IDigitalInputController, IDigitalInterruptController, IPinController, II2cPeripheral, IDisposable

Inheritance: System.Object -> Meadow.Foundation.ICs.IOExpanders.Pcx857x

Implements:
Meadow.Hardware.IDigitalOutputController, Meadow.Hardware.IDigitalInputController, Meadow.Hardware.IDigitalInterruptController, Meadow.Hardware.IPinController, Meadow.Hardware.II2cPeripheral, System.IDisposable

Methods

GetAddressForPins(bool, bool, bool)

Helper method to get address from address pin configuration

View Source
Declaration
public static byte GetAddressForPins(bool pinA0, bool pinA1, bool pinA2)
Returns

System.Byte: The device address

Parameters
TypeNameDescription
System.BooleanpinA0State of A0 address pin - true if high
System.BooleanpinA1State of A1 address pin - true if high
System.BooleanpinA2State of A2 address pin - true if high

Implements

  • Meadow.Hardware.IDigitalOutputController
  • Meadow.Hardware.IDigitalInputController
  • Meadow.Hardware.IDigitalInterruptController
  • Meadow.Hardware.IPinController
  • Meadow.Hardware.II2cPeripheral
  • System.IDisposable