Skip to main content

Class Mcp23xxx

Provide an interface to connect to a MCP23xxx port expander

Assembly: Mcp23xxx.dll
View Source
Declaration
public abstract class Mcp23xxx : IDigitalInputOutputController, IDigitalInputController, IDigitalOutputController, ISpiPeripheral, II2cPeripheral, IDigitalInterruptController, IPinController

Derived:
Meadow.Foundation.ICs.IOExpanders.Mcp23x0x

Implements:
Meadow.Hardware.IDigitalInputOutputController, Meadow.Hardware.IDigitalInputController, Meadow.Hardware.IDigitalOutputController, Meadow.Hardware.ISpiPeripheral, Meadow.Hardware.II2cPeripheral, Meadow.Hardware.IDigitalInterruptController, Meadow.Hardware.IPinController

Properties

NumberOfPins

The number of IO pins available on the device

View Source
Declaration
public abstract int NumberOfPins { get; }

DefaultSpiBusSpeed

The default SPI bus speed for the device

View Source
Declaration
public Frequency DefaultSpiBusSpeed { get; }

SpiBusSpeed

The SPI bus speed for the device

View Source
Declaration
public Frequency SpiBusSpeed { get; set; }

DefaultSpiBusMode

The default SPI bus mode for the device

View Source
Declaration
public SpiClockConfiguration.Mode DefaultSpiBusMode { get; }

SpiBusMode

The SPI bus mode for the device

View Source
Declaration
public SpiClockConfiguration.Mode SpiBusMode { get; set; }

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

Fields

_lock

object for using lock() to do thread sync

View Source
Declaration
protected object _lock

Methods

GetAddressFromPins(bool, bool, bool)

Help method to get address from address pin configuration

View Source
Declaration
public static byte GetAddressFromPins(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

ResetMcp()

Reset the MCPxxxx expander Requires using a reset port

View Source
Declaration
public void ResetMcp()

IsValidPin(IPin)

Checks if a pin exists on the Mcp23xxx

View Source
Declaration
protected abstract bool IsValidPin(IPin pin)
Returns

System.Boolean

Parameters
TypeName
Meadow.Hardware.IPinpin

CreateDigitalOutputPort(IPin, bool, OutputType)

Creates a new DigitalOutputPort using the specified pin and initial state

View Source
Declaration
public virtual IDigitalOutputPort CreateDigitalOutputPort(IPin pin, bool initialState = false, OutputType outputType = OutputType.OpenDrain)
Returns

Meadow.Hardware.IDigitalOutputPort: IDigitalOutputPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin representing the port
System.BooleaninitialStateWhether the pin is initially high or low
Meadow.Hardware.OutputTypeoutputTypeThe output type

CreateDigitalInputPort(IPin, ResistorMode)

Creates a new DigitalInputPort using the specified pin

View Source
Declaration
public IDigitalInputPort CreateDigitalInputPort(IPin pin, ResistorMode resistorMode = ResistorMode.Disabled)
Returns

Meadow.Hardware.IDigitalInputPort: IDigitalInputPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin representing the port
Meadow.Hardware.ResistorModeresistorModeThe port resistor mode

CreateDigitalInterruptPort(IPin, InterruptMode, ResistorMode)

Creates a new DigitalInputPort using the specified pin

View Source
Declaration
public IDigitalInterruptPort CreateDigitalInterruptPort(IPin pin, InterruptMode interruptMode = InterruptMode.None, ResistorMode resistorMode = ResistorMode.Disabled)
Returns

Meadow.Hardware.IDigitalInterruptPort: IDigitalInterruptPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin representing the port
Meadow.Hardware.InterruptModeinterruptModeThe port interrupt mode
Meadow.Hardware.ResistorModeresistorModeThe port resistor mode

CreateDigitalInterruptPort(IPin, InterruptMode, ResistorMode, TimeSpan)

Creates a new DigitalInputPort using the specified pin

View Source
Declaration
public IDigitalInterruptPort CreateDigitalInterruptPort(IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, TimeSpan debounceDuration)
Returns

Meadow.Hardware.IDigitalInterruptPort: IDigitalInterruptPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin representing the port
Meadow.Hardware.InterruptModeinterruptModeThe port interrupt mode
Meadow.Hardware.ResistorModeresistorModeThe port resistor mode
System.TimeSpandebounceDurationThe debounce duration

CreateDigitalInterruptPort(IPin, InterruptMode, ResistorMode, TimeSpan, TimeSpan)

Creates a new DigitalInputPort using the specified pin

View Source
Declaration
public IDigitalInterruptPort CreateDigitalInterruptPort(IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, TimeSpan debounceDuration, TimeSpan glitchDuration)
Returns

Meadow.Hardware.IDigitalInterruptPort: IDigitalInterruptPort

Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin representing the port
Meadow.Hardware.InterruptModeinterruptModeThe port interrupt mode
Meadow.Hardware.ResistorModeresistorModeThe port resistor mode
System.TimeSpandebounceDurationThe debounce duration
System.TimeSpanglitchDurationThe glitch duration - not configurable on Mcp23xxx

SetPortDirection(IPin, PortDirectionType)

Sets the direction of a port

View Source
Declaration
public void SetPortDirection(IPin pin, PortDirectionType direction)
Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin representing the port
Meadow.Hardware.PortDirectionTypedirectionThe port direction (input or output)

WriteToPort(IPin, bool)

Sets a particular pin's value. If that pin is not in output mode, this method will first set its mode to output.

View Source
Declaration
public void WriteToPort(IPin pin, bool value)
Parameters
TypeNameDescription
Meadow.Hardware.IPinpinThe pin to write to.
System.BooleanvalueThe value to write. True for high, false for low.

ReadPort(IPin)

Gets the value of a particular port. If the port is currently configured as an output, this will change the configuration.

View Source
Declaration
public bool ReadPort(IPin pin)
Returns

System.Boolean

Parameters
TypeName
Meadow.Hardware.IPinpin

WriteToPorts(byte)

Outputs a byte value across all of the pins by writing directly to the output latch (OLAT) register

View Source
Declaration
public void WriteToPorts(byte mask)
Parameters
TypeName
System.Bytemask

ReadFromPorts(PortBank)

Reads a byte value from all of the pins. little-endian; the least significant bit is the value of GP0. So a byte value of 0x60, or 0110 0000, means that pins GP5 and GP6 are high.

View Source
Declaration
public byte ReadFromPorts(Mcp23xxx.PortBank bank = PortBank.A)
Returns

System.Byte: A little-endian byte mask of the pin values.

Parameters
TypeName
Meadow.Foundation.ICs.IOExpanders.Mcp23xxx.PortBankbank

ResetPin(IPin)

Sets the pin back to an input

View Source
Declaration
protected void ResetPin(IPin pin)
Parameters
TypeName
Meadow.Hardware.IPinpin

GetPin(string)

Get Pin by name

View Source
Declaration
public abstract IPin GetPin(string pinName)
Returns

Meadow.Hardware.IPin: IPin object if found

Parameters
TypeNameDescription
System.StringpinNameThe pin name

Events

InputChanged

Raised when the value of any pin configured for input interrupts changes This provides raw port state data from the MCP23xxx It's highly recommended to prefer using the events exposed on the digital input ports instead.

View Source
Declaration
public event EventHandler<IOExpanderInputChangedEventArgs> InputChanged
Event Type

System.EventHandler<Meadow.Foundation.ICs.IOExpanders.IOExpanderInputChangedEventArgs>

Implements

  • Meadow.Hardware.IDigitalInputOutputController
  • Meadow.Hardware.IDigitalInputController
  • Meadow.Hardware.IDigitalOutputController
  • Meadow.Hardware.ISpiPeripheral
  • Meadow.Hardware.II2cPeripheral
  • Meadow.Hardware.IDigitalInterruptController
  • Meadow.Hardware.IPinController