.Net Core Library to use with the Expander Pi Raspberry Pi development boards.
Downloading and Installing the .Net Core Libraries
Download the zip archive containing the code demos and libaries from GitHub.
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
Expander Pi ADC Methods
The ADC supports single-ended or differential modes.
In single-ended mode, each channel acts as an individual single-ended input.
In differential mode, the inputs are split into four differential pairs.
Setting channel to 1 will make IN1 = IN+ and IN2 = IN-
Setting channel to 2 will make IN1 = IN- and IN2 = IN+
Setting channel to 3 will make IN3 = IN+ and IN4 = IN-
Setting channel to 4 will make IN3 = IN- and IN4 = IN+
Setting channel to 5 will make IN5 = IN+ and IN6 = IN-
Setting channel to 6 will make IN5 = IN- and IN6 = IN+
Setting channel to 7 will make IN7 = IN+ and IN8 = IN-
Setting channel to 8 will make IN7 = IN- and IN8 = IN+
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: (double) 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
Expander Pi ADC Parameters
double ADCReferenceVoltage { get; set; }
Gets or sets 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.
Expander Pi 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 the gain is 1, 0 and 4.096V when the 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.
The voltage will be between 0 and 2.047V when the gain is 1, 0 and 4.096V when the gain is 2
Parameters: channel (1 or 2)
Parameters: value (0 to 4095)
Parameters: gain (1 or 2)
Returns: null
Expander Pi IO Methods
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.
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 9 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 9 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 9 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 9 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 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
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 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
IOSetInterruptOnPort(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
IOSetInterruptOnPin(byte pin, bool value)
Enable interrupts for the selected pin
Parameters: pin - 1 to 16, value - true = interrupt enabled, false = interrupt disabled
Returns: null
IOReadInterruptStatus(byte port)
Enable interrupts for the selected pin
Parameters: port 0 = pins 1 to 8, port 1 = pins 9 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 9 to 16
Returns: status
IOResetInterrupts()
Set the interrupts A and B to 0
Parameters: null
Returns: null
Expander Pi RTC Methods
RTCReadMemory(byte address, byte length)
Write to the SRAM memory on the DS1307. Memory range is 0x08 to 0x3F.
Parameters: address - First memory address where the values with be written.
length - Number of bytes to read from memory.
Returns: byte[] - Byte array containing read memory values.
RTCWriteMemory(byte address, byte[] values)
Write to the SRAM memory on the DS1307. Memory range is 0x08 to 0x3F.
Parameters: address - First memory address where the values with be written. values - Byte array containing values to be written to memory. Array length can not exceed the memory space available. Returns: null
Expander Pi RTC Parameters
DateTime RTCDate { get; set; }
Set or get the date and time from the RTC.
Takes a DateTime variable.
Returns: DateTime
byte RTCFrequency { get; set; }
Get or set the frequency of the output pin square wave.
Options are: 1 = 1Hz, 2 = 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
bool RTCOutput { get; set; }
Enable or disable the square wave output on the SQW pin.
Set output as true or false. Gets output state as true or false.
Expander Pi Usage
To use the Expander Pi library in your code you must first import the library DLL:
using ABElectronicsUK;
Next, you must initialise the ExpanderPi class:
ABElectronicsUK.ExpanderPi expi = new ABElectronicsUK.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 = expi.IOReadPin(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.