Interface Kit
Home Up Programming Conventions Interface Kit Sensors Activities


Phidget IFKit888

bullet8 digital inputs
bullet8 digital outputs @ 5 volts and 17 milliamperes maximum current output
bullet8 analog inputs, 12 bit, 0 - 5 volt input range, sample rate (not known)

Visual Basic and the IFKit

The Phidget Library

Visual Basic communicates with all the various Phidgets using an add in Phidget Library (2.0). The current Phidget library must be installed and referenced in each VB6.0 application. If an older library is present, it should be removed before a more recent copy is installed.

Phidget Library 2.0

Reference the Phidget Library: Open the Project menu and select References.  Scroll down and select Phidget Library 2.0.1 (or whatever is the current version) by clicking the check box.

Creating an Instance

Each Phidget device is represented in code as a class. For example, the IFKit888 class is named PhidgetInterfaceKit. This class refers to a number of Phidget interface kits. To access the IFKit in Visual Basic you can create an "instance" of this class. The instance name is then used to reference the various commands / events supported by the library. The instance can be created in the General..Declarations section of the code window. For Example:

Dim  WithEvents IFKit1 As PhidgetInterfaceKit

IFKit1 is the name given the instance. You could use any non reserved word.

Two additional code lines complete the setup for the particular Phidget. These lines should be executed before any other code referencing  the Phidget commands / events. If the code lines are placed in the Form_Load event, they are executed as soon as the application is run. An example follows:

Set IFKit1 = New PhidgetInterfaceKit

Call IFKit1.Open(True, xxxx)

Coding the IFKit

Visual Basic, using the Phidget library, can communicate with the IFKit by reading the Digital and Analog input lines and enabling the digital output lines. There are three basic commands used to do this:

Analog Input:


This command returns the raw ADC value from input N. Theoretically, the value can be between 0 and 4095 for a 12 bit ADC. The value of N can be between 0 and 7 which corresponds with the inputs 1 to 8.

Example: Note that RawValue is a variable.

RawValue = IFKit1.SensorRawValue(3)

The Variable RawValue is set to the value returned by analog input #4.

The following command returns a value from the ADC that is scaled between 0 and 1000.


Digital Output:

IFKit1.OutputState(N) = Boolean Expression

This command turns on the digital output referenced by the index N. Examples:

IFKit1.OutputState(2) = True

IFKit1.OutputState(5) = False

The first line turns on digital output line #3. The second turns off digital output line #6. Note: that the digital lines can output 5v DC at 17 ma.

Digital Input:

IFKit1.InputState(N) = Boolean Expression

This command is used to query the digital input port. If a digital input line is connected to ground, eg. through a switch, it will return a TRUE. An ungrounded line will return a FALSE. An example:

If IFKit1.InputState(7) = True Then
   Text1 = "The Switch is closed"
ElseIF IFKit1.InputState(7) = False Then
   Text1 = "The Switch is open"
End If

This code checks for a switch closing on digital input line #8.

There are several more commands that include detecting if the IFKit888 is connected, setting max and min values for the scaled analog input, and checking for the number of inputs.

IFKit888 Events

Analog Input Event

In the exercises that follow, the state of the IFKit is determined using a timer and the commands discussed above. An alternate method is to use a built in event.

Private Sub IFKit1_OnSensorChange(ByVal Index As Long, ByVal SensorValue As Long)

End Sub

This event "fires" and returns a value whenever the the sensor voltage changes. Index and SensorValue are variables "built in" to the event. For example:

Private Sub IFKit_OnSensorChange(ByVal Index As Long, ByVal SensorValue As Long)

Text1 = Index
Text2 = SensorValue

End Sub

Text1 will display the number of the Analog input line (1 to 8) and Text2 will display the value of the sensor as it changes.

Digital Input Event

Private Sub IFKit_OnInputChange(ByVal Index As Long, ByVal NewState As Boolean)

End Sub

This event will return a True if the digital line changes state and is grounded (eg. a switch closed) and will return a False if the ground is removed. For example:

Private Sub IFKit_OnInputChange(ByVal Index As Long, ByVal NewState As Boolean)

Text1 = Index
Text2 = NewState

End Sub

As in the previous example, Text1 will display the digital input line number, and Text2 displays True or False depending on whether the line is grounded or not.