A Basic Stamp (or other microcontroller) is just the ticket for many control applications. However, sometimes you really want to control the real world from a PC. Our latest kit, the GP3, can provide practically any PC with 8 digital I/O pins, 5 10-bit A/D converters, a hardware PWM output, and a hardware counter. It connects directly to the PC's serial port and -- this is the interesting part -- we provide ActiveX libraries so you can use the GP3 with Visual Basic, C++, Delphi, Active Server Pages, or any language that supports ActiveX.

If you don't want to program, you need to check out GP3EZ which is our "point and click" software that lets you create applications with the GP3 with no programming. In many cases you can even download your application to the GP3 and run it without a PC.

If you want the ultimate control, however, you'll want to use one of the libraries and the langauge of your choice.

This table shows a summary of your options for using the board:
GP3EZ Use a simple point and click interface to create "scripts". You can run the scripts from the PC, or download them to the GP3 so it will run standalone. Very easy to use. Integrated debugging. Only way to compile to the GP3. Not as flexible as conventional programming. Requires Windows or Mono under Linux (Linux version available May 2010, although V1.5 works under Mono with only a few cosmetic problems)
GP3DAQ Use an example program to plot analog inputs and save them to your PC as files No programming required Windows only. Only plots analog values. Although you can scale data using a polynomial, generally not as flexible as writing custom software or scripts
Microsoft (ActiveX) languages (C++, C#, VB, VBA, ASP, etc.) The provided ActiveX control provides an easy way to control the GP3 from most Microsoft languages and many other Windows-based languages. Simple integration with common Windows languages. Very simple to use. ActiveX not portable. Must have correct MS dependencies.
Windows DLL or Library Standard library can produce a standard library, a DLL, or you can just include the source code in your C or C++ program. Portable (same code usable on Linux, Windows, Cygwin, Windows CE). DLL usable with Java via JNI or JNA calls. Integrating DLLs slightly more difficult in some languages).
Linux Library Standard library can produce a standard library, a shared object, or you can just include the source code in your C or C++ program. Portable (same code usable on Linux, Windows, Cygwin, Windows CE). The .so is usable with Java via JNI or JNA calls. None
Pure Java Object Standard Java Object wraps GP3 functionality No native code required. Example includes embeddable Javascripting language. Requires finicky Java Serial libraries (javax.comm or RXTX)
Java via Library Using the portable DLL or .so file from Linux is simple No need for finicky serial libraries Not "pure" Java
LabView LabView (by National Instruments) is a very popular program for managing data acquisition and simple control. LabView can easily drive the GP-3 hardware via a serial or USB port. Popular environment. Interfaces with many other tools. Not inexpensive for all versions. Experienced programs often prefer working in traditional languages.
Gambas (Linux) Gambas is a VB-like RAD tool for Linux that supports the GP3 Easy visual development Linux only
GNUPlot (Linux) This article shows a simple way to stream data from a GP-3 to GNUPlot No real programming; flexible and easy Linux only; not the fastest solution

More about the ActiveX control

The ActiveX control (or DLL) supplied makes it simple to control the GP-3. Here's a summary of the functions available:

high/low - Set output pin high/low

a2d - Read A/D channel

inp - Read one input pin

pins - Set output pin state

tris - Set direction of I/O pins

eeprom - Read/write EEPROM

portopen - Connect or disconnect

pwm - Output PWM

toggle - Toggle output pin

count - Count pulses on input pin

led - Set state of indicator LED

pulsein - Read pulse

freq - Output a frequency

pulseout - Output a single pulse

rctime - Measure an RC discharge time

setcounter - Configure timer/counter

counter - Read hardware timer/counter

ok - Check for connection

errflag - Check for errors

comport - Set com port

ready - Check status

How easy is using the GP-3? Easy! Here's a simple Visual Basic event handler that reads an analog input:


If you want to convert the raw counts to a voltage and format the data, that's easy to do in Basic:

Volt0.Caption = Format(GP3IO1.a2d(0) / 1023 * 5#, "0.##")

Want to turn on an LED from an ASP Web page? That's easy too:

set io = Server.CreateObject("AWCGP3DLL.GP3DLL")
io.led=Request("LED") ' set LED based on user request

You can do the same sort of thing from an Excel spreadsheet (using VBA).

If you want to use the GP3 from a different platform our portable C library will work with nearly any standard C compiler and includes porting examples for Linux, Cygwin, and Windows. You can browse the online documentation for the library, or download a local copy for yourself.

You can also use the board from Java. We have an example of interfacing the Java library to JavaScript (using the Rhino JavaScript library). This is great for interactive debugging. Here's an example of a JavaScript that exercises the board:

// Test script for GP3
// To run: java GP3Script gp3test.js
io.openPort("COM7"); // change to match your COM port!
function readvolt(n)
return io.a2d(n)/1023.0*5.0;
for (i=0;i<1000;i++)
print(readvolt(0)); // print voltage on analog in 0

A Temperature Example

Suppose you want to monitor a temperature with your PC. If the temperature exceeds a certain range, you want to turn on a light, beep an alarm, and turn on a fan. What's more, you want the fan to spin faster as the temperature rises higher above the limit.

Of course, while you are monitoring the temperature, you could store the data in a database, a spreadsheet file, or serve it over the Internet. But for now, let's just focus on the basic task at hand. Speaking of basic, Visual Basic is a good language for this sort of program. The GP3 works well with Visual Basic and it can easily read an LM34 (this is a three-terminal sensor that reads 10mV/degree F). So the basic connections are simple:

An LM34 on analog channel 0 (the LM34 also requires 5V and ground).
A 5V LED on digital output 0.
A piezo speaker on digital output 1.
A IRL510 FET on the PWM output. The gate connects to the GP3 output. The source goes to ground. The drain connects to one side of the fan motor (the other side of the fan motor connects to 12V).

For testing purposes, you can connect an LED to the PWM output and observe the brightness change instead of the actual fan speed. Here's what the final program will look like:

Using the GP3 ActiveX control is very simple. First, you use the Project | Components command in Visual Basic. From the list, pick AWCGP3 as the control to add to your project. If you don't see it, you probably haven't installed the control. Once you are through, you'll see an icon in your tool box that has a large number "3". This is the control. Place it on your form in the usual way. This control is like the timer control -- it is only visible during design time. You can't see it while the program is running.

To use the control you have to set the COM port that the GP3 uses. You can do this during design time, but I wanted to make the program allow you to set it. Once you set the COM port (the commport parameter) you have to set portopen to TRUE to make the control connect. From there it is easy to manipulate the GP3's ports. For example, to read analog channel 0 (assuming you've named the GP3 control IO):


That's it! Of course, the real program averages 5 readings and converts it to a temperature:

' average 5 samples
adv = 0
For i = 1 To 5
adv = adv + IO.a2d(0)
adv = adv / 5
t = adv / 1023# * 5 * 100
Temp.Caption = Temp.Tag & Format(t, "#0.0") & " F"

The program above uses a timer to periodically scan the temperature and compares it to the limit field. Then it determines if the temperature is over limit:

If t > l Then    ' t is temperature, l is limit
  deltat = t - l
' Turn the fan on harder as deltat increases
  Select Case deltat
  Case Is < 2
    dc = 10   ' 10/255 (4%)
  Case Is < 10
    dc = 64   ' 64/255  (25%)
  Case Else
    dc = 255  ' 255/255 (100%)
  End Select
  Temp.ForeColor = vbRed
  IO.high 0 ' turn on alarm light
  IO.pwm -1, dc, 5000   ' hardware PWM at 5kHz
  IO.freq 1, 1000, 250  ' make a 250mS beep on the speaker 
' Everything is OK so stop everything
  Temp.ForeColor = vbGreen
  IO.low 0
  IO.pwm -1, 0, 5000
End If

You can download the entire project in one zip file. You'll also need the library files for the GP3. It would be nice to add some hysteresis, and you can probably think of many other enhancements.

A Scope

The serial protocol between the PC and the GP3 is efficient and fast (57600 baud). However, sometimes you want things to go as fast as possible. Here is a simple "oscilloscope" (actually more like a strip chart recorder) that I wrote.

Each screen refresh needs to draw the A/D samples as fast as possible. The GP3 has a repeat mode for several commands (including a2d) so you can have the output repeat some number of times. Here's the code for a screen refresh:

    IO.repeat xmax + 1
    n = IO.a2d(0)
    For xpos = 0 To xmax
    If quit Then
       busy = False
       Exit Sub
    End If
    ' n between 0 and 1023
    Dim y As Single
    Dim volt As Single
    Dim yint As Integer
    y = ymax
    y = y * n / 1024
    If xpos Mod 64 = 0 Then
      volt = (n / 1024#) * 5
      OScope.Caption = "Last = " & Format(volt, "0.00") & "V"
    End If
    yint = ymax - Int(y)
    If xlast <> -1 Then OScreen.Line (xlast, ylast)-(xpos, yint)
    xlast = xpos
    ylast = yint
    If xpos <> xmax Then n = IO.readword

The xmax variable contains the maximum x coordinate of the screen. The repeat command tells the GP3 to repeat the next command (in this case, a2d). After the program reads the first sample, it uses readword to get the subsequent readings. This saves overhead of having to ask for the sample hundreds of times.

You can download the complete scope project in a single zip file.

On the Web

Microsoft's Web server (IIS) supports ASP (Active Server Pages). ASP scripts can access ActiveX DLLs so... Yep, you can use the GP3 with ASP! Look at this:

This Web page was created with the following ASP script:

set io = Server.CreateObject("AWCGP3DLL.GP3DLL")
<H1>GP3 DEMO</H1>
<P>Current temperature=<%= t %>F
<A HREF=io.asp?LED=1>LED ON</A> <A HREF=io.asp?LED=0>LED OFF</A>

Notice the META tag causes the page to refresh every 10 seconds. The Server.CreateObject call creates a copy of the GP3 library. I've hard coded the COM port (yes, I have 8 ports on my PC). In addition to the temperature display, the page also has links to turn the LED on the board on and off. Of course, you would have to worry about multiple users fighting for control of the GP3, but that's just the Web for you.

Using the Windows Scripting Host, you could even control the GP3 from a JavaScript (or VBScript) "batch file" (for more about Windows Scripting Host, read this from Microsoft). Here's a sample script:


This "batch file" outputs a 1 Hz sine wave for 10 seconds (you can see this very nicely with an LED connected to pin 0).

You can even use the ActiveX DLL from Excel.

More Ideas

You can use the GP3 anywhere you need to sense or control the real world with a PC. In fact, the device is serial so it will work with any computer or operating system if you control it properly. Need to run a machine tool? Monitor analog sensors? Control a test fixture? The GP3 makes it a snap to interface the world to your PC. Although the examples here use Visual Basic and VBScript, you can use the GP3 with C++, C#, Delphi or practically any language (We have a simple C++ example available). Today, the ActiveX libraries provide many options and we will release other libraries for other development tools as demand warrants. For example, if you prefer to use a standard DLL, you can download the non-ActiveX DLL. You can also use the board from Java and we even include an example that lets you program it with JavaScript. You can download the Java files in this zip file.

Site contents © 1997-2018 by AWC, Houston TX    (281) 334-4341