Skip to content
Brian Dorey edited this page Jul 1, 2017 · 1 revision

ExpanderPi

This class contains methods to use with the Expander Pi from https://www.abelectronics.co.uk/p/50/Expander-Pi

Methods

Connect() 

Connect to the Expander Pi
Parameters: none
Returns: null

IsConnected() 

Check if the device is connected Parameters: none
Returns: boolean

Dispose() 

Dispose of the active device
Parameters: none
Returns: null

ADC Methods

ADCReadVoltage(byte channel, byte mode) 

Read the voltage from the selected channel on the ADC.
Parameters: channel (1 to 8)
Parameters: mode (1 = Single Ended Input, 2 = Differential Input)
Returns: voltage

ADCReadRaw(byte channel, byte mode)

Read the raw value from the selected channel on the ADC.
Parameters: channel (1 to 8)
Parameters: mode (1 = Single Ended Input, 2 = Differential Input)
Returns: voltage

ADCSetRefVoltage(double voltage) 

Set the reference voltage for the analogue to digital converter.
The Expander Pi contains an onboard 4.096V voltage reference.
If you want to use an external reference between 0V and 5V, disconnect the jumper J1 and connect your reference voltage to the Vref pin.
Parameters: voltage
Returns: null

DAC Methods

DACSetVoltage(byte channel, double voltage, byte gain)

Set the voltage for the selected channel on the DAC.
Parameters: channel (1 or 2)
Parameters: voltage (Voltage will be between 0 and 2.047V when gain is 1, 0 and 4.096V when gain is 2)
Parameters: gain (1 or 2)
Returns: null

DACSetRaw(byte channel, short value, byte gain)

Set the voltage for the selected channel on the DAC.
Voltage will be between 0 and 2.047V when gain is 1, 0 and 4.096V when gain is 2
Parameters: channel (1 or 2)
Parameters: value (0 to 4095)
Parameters: gain (1 or 2)
Returns: null

IO Methods

IOSetPinDirection(byte pin, bool direction)  

Sets the IO direction for an individual pin
Parameters: pin - 1 to 16, direction - true = input, false = output
Returns: null

IOSetPortDirection(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

IOSetPinPullup(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

IOSetPortPullups(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

IOWritePin(byte pin, bool value)

Write to an individual pin 1 - 16
Parameters: pin - 1 to 16, value - true = Enabled, false = Disabled Returns: null

IOWritePort(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

IOReadPin(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

IOReadPort(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

IOInvertPort(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

IOInvertPin(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

IOMirrorInterrupts(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

IOSetInterruptPolarity(byte value)

This sets the polarity of the INT output pins
Parameters: 1 = Active - high. 0 = Active - low.
Returns: null

IOSetInterruptType(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

IOSetInterruptDefaults(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

IOSetInterruptOnPort(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

IOSetInterruptOnPin(byte pin, bool value)

Enable interrupts for the selected pin
Parameters: pin - 1 to 16, value - true = interrupt disabled, false = interrupt enabled
Returns: null

IOReadInterruptStatus(byte port)

Enable interrupts for the selected pin
Parameters: port 0 = pins 1 to 8, port 1 = pins 8 to 16
Returns: status

IOReadInterruptCapture(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

IOResetInterrupts()

Set the interrupts A and B to 0
Parameters: null
Returns: null

RTC Methods

RTCSetDate(DateTime date)

Set the date and time on the RTC
Parameters: date as DateTime Returns: null

RTCReadDate() 

Returns the date from the RTC in ISO 8601 format - YYYY-MM-DDTHH:MM:SS
Returns: date as DateTime

RTCEnableOutput() 

Enable the square-wave output on the SQW pin.
Returns: null

RTCDisableOutput()

Disable the square-wave output on the SQW pin.
Returns: null

RTCSetFrequency(byte frequency)

Set the frequency for the square-wave output on the SQW pin.
Parameters: frequency - options are: 1 = 1Hz, 2 = 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
Returns: null

Usage:

To use the Expander 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 expi = new ABElectronics_Win10IOT_Libraries.ExpanderPi();

Next we need to connect to the device and wait for the connection before setting the digital IO ports to be inputs

expi.Connect();

while (!expi.IsConnected)
{
}
expi.IOSetPortDirection(0, 0xFF);
expi.IOSetPortDirection(1, 0xFF);

You can now read the input status from pin 1 on the digital IO bus with:

bool value = bus1.IOReadPin(1);
Clone this wiki locally