.Net Core Library to use with the IO Pi Plus, IO Pi, and IO Pi Zero Raspberry Pi development boards.
Downloading and Installing the .Net Core Libraries
Download the zip archive containing the code demos and libaries from GitHub.
Note: Microchip recommends that pin 8 (GPA7) and pin 16 (GPB7) are used as outputs only. This change was made for revision D MCP23017 chips manufactured after June 2020. See the MCP23017 datasheet for more information.
IO Pi Methods
Connect()
Connect to the I2C device
Parameters: none
Returns: null
IsConnected()
Check if the device is connected
Parameters: none
Returns: boolean
Dispose()
Dispose of the active I2C device
Parameters: none
Returns: null
SetPinDirection(byte pin, bool direction)
Sets the IO direction for an individual pin
Parameters: pin - 1 to 16, direction - true = input, false = output
Returns: null
SetPortDirection(byte port, byte direction)
Sets the IO direction for the specified IO port
Parameters: port - 0 = pins 1 to 8, port 1 = pins 9 to 16, direction - true = input, false = output
Returns: null
SetPinPullup(byte pin, bool value)
Set the internal 100K pull-up resistors for the selected IO pin
Parameters: pin - 1 to 16, value: true = Enabled, false = Disabled
Returns: null
SetPortPullups(byte port, byte value)
Set the internal 100K pull-up resistors for the selected IO port
Parameters: 0 = pins 1 to 8, 1 = pins 9 to 16, value: true = Enabled, false = Disabled
Returns: null
WritePin(byte pin, bool value)
Write to an individual pin 1 - 16
Parameters: pin - 1 to 16, value - true = Enabled, false = Disabled
Returns: null
WritePort(byte port, byte value)
Write to all pins on the selected port
Parameters: port - 0 = pins 1 to 8, port 1 = pins 9 to 16, value - number between 0 and 255 or 0x00 and 0xFF
Returns: null
ReadPin(byte pin)
Read the value of an individual pin 1 - 16
Parameters: pin: 1 to 16
Returns: false = logic level low, true = logic level high
ReadPort(byte port)
Read all pins on the selected port
Parameters: port - 0 = pins 1 to 8, port 1 = pins 9 to 16
Returns: number between 0 and 255 or 0x00 and 0xFF
InvertPort(byte port, byte polarity)
Invert the polarity of the pins on a selected port
Parameters: port - 0 = pins 1 to 8, port 1 = pins 9 to 16, polarity - 0 = same logic state of the input pin, 1 = inverted logic state of the input pin
Returns: null
InvertPin(byte pin, bool polarity)
Invert the polarity of the selected pin
Parameters: pin - 1 to 16, polarity - false = same logic state of the input pin, true = inverted logic state of the input pin Returns: null
MirrorInterrupts(byte value)
Mirror Interrupts
Parameters: value - 1 = The INT pins are internally connected, 0 = The INT pins are not connected. INTA is associated with PortA and INTB is associated with PortB
Returns: null
SetInterruptPolarity(byte value)
This sets the polarity of the INT output pins
Parameters: 1 = Active - high. 0 = Active - low.
Returns: null
SetInterruptType(byte port, byte value)
Sets the type of interrupt for each pin on the selected port
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 to 16, value: number between 0 and 255 or 0x00 and 0xFF. 1 = interrupt is fired when the pin matches the default value, 0 = the interrupt is fired on state change
Returns: null
SetInterruptDefaults(byte port, byte value)
These bits set the compare value for pins configured for interrupt-on-change on the selected port.
If the associated pin level is the opposite of the register bit, an interrupt occurs.
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 to 16, value: compare value
Returns: null
SetInterruptOnPort(byte port, byte value)
Enable interrupts for the pins on the selected port
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 to 16, value: number between 0 and 255 or 0x00 and 0xFF
Returns: null
SetInterruptOnPin(byte pin, bool value)
Enable interrupts for the selected pin
Parameters: pin - 1 to 16, value - true = interrupt enabled, false = interrupt disabled
Returns: null
ReadInterruptStatus(byte port)
Enable interrupts for the selected pin
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 to 16
Returns: status
ReadInterruptCapture(byte port)
Read the value from the selected port at the time of the last interrupt trigger
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 to 16
Returns: status
ResetInterrupts()
Set the interrupts A and B to 0
Parameters: null
Returns: null
IO Pi Usage
To use the IO Pi library in your code you must first import the library DLL:
using ABElectronicsUK;
Next, you must initialise the io class:
ABElectronicsUK.IOPi bus1 = new ABElectronicsUK.IOPi(0x20);
The argument is the I2C addresses of the IO chip. The value shown is the default addresses of the IO board which are 0x20 and 0x21.
Next, we need to connect to the device and wait for the connection before setting ports to be inputs
bus1.Connect();
while (!bus1.IsConnected){}
bus1.SetPortDirection(0, 0xFF);
bus1.SetPortDirection(1, 0xFF);
You can now read the input status from channel 1 with:
bool value = bus1.ReadPin(1);
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.