-
Notifications
You must be signed in to change notification settings - Fork 5
Class: IOPi
This class contains methods for use with the IO Pi, IO Pi Plus and IO Pi Zero from
https://www.abelectronics.co.uk/p/54/IO-Pi-Plus
https://www.abelectronics.co.uk/p/71/IO-Pi-Zero
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 8 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 8 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 8 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 8 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 8 to 16, value: 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 from the register bit, an interrupt occurs.
Parameters: port 0 = pins 1 to 8, port 1 = pins 8 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 8 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 disabled, false = interrupt enabled
Returns: null
ReadInterruptStatus(byte port)
Enable interrupts for the selected pin
Parameters: port 0 = pins 1 to 8, port 1 = pins 8 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 8 to 16
Returns: status
ResetInterrupts()
Set the interrupts A and B to 0
Parameters: null
Returns: null
To use the IO Pi library in your code you must first import the library dll:
using ABElectronics_Win10IOT_Libraries;
Next you must initialise the io class:
ABElectronics_Win10IOT_Libraries.IOPi bus1 = new ABElectronics_Win10IOT_Libraries.IOPi(0x20);
The argument is the I2C addresses of the IO chip. The value shown are 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);