Setting the Basic Stamp II's Input/Output or I/O pins low or high (on and off) with Visual Basic Button_Click events.
...The BASIC Stamp II is a microcontroller with a small, specialized BASIC interpreter(PBASIC) built into its ROM. It is manufactured by Parallax, Inc.
In my example I use the Basic Stamp II Homework Board.
Heads up..
...Controlling a Basic Stamp II with Visual Basic is pretty easy.
...It is required to write a small program to the Basic Stamp itself and then to write a small program with Visual Basic.
...I assume you have some experience with the Basic Stamp Editor and with Visual Basic.
...I am not a programmer but I do consider myself pretty resourceful so through a little research I was able to determine how to do this.
I connected my Basic Stamp to my laptop with a USB to serial connector.
I picked one up from Radio Shack for about 30 dollars.
Later noticed they do have a Basic Stamp prototyping model available that is ready for USB...
Story of my life.
I am pretty sure that there were some necessary drivers to be installed..I dont remember exactly.
In the PBASIC Editor enter the following code.
______________________________________________________________________________
' {$STAMP BS2}
' {$PBASIC 2.5}
' Hook up a two LEDs to Pins 3 and 4 to test this.
' Then VB code is set up for Com1 incase you have to change this to the Com
' port of your computer.
Main:
SERIN 16, 16468, [STR command\1] ' Get 1-byte string
CheckCommand:
IF command = "1" THEN
GOTO Task1
ENDIF
IF command = "2" THEN
GOTO Task2
ENDIF
IF command = "3" THEN
GOTO Task3
ENDIF
IF command = "4" THEN
GOTO Task4
ENDIF
GOTO Main
Task1:
HIGH 3
GOTO Main
Task2:
LOW 3
GOTO Main
Task3:
HIGH 4
GOTO Main
Task4:
LOW 4
GOTO Main
______________________________________________________________________________
I downloaded a evaluation version of Visual Basic 2010 Express
I hope that you have some experience with it.
Create the necessary controls and label them properly.
Then enter the following code.
Public Class Form1
Private WithEvents serialPort As New IO.Ports.SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
IF serialPort.IsOpen THEN
serialPort.Close()
END IF
Try
With serialPort
.PortName = "COM10"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
END With
serialPort.Open()
Catch ex As Exception
MsgBox(ex.ToString)
END Try
END Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
serialPort.WRITE("1")
TextBox1.Text = "LED 1 ON"
END Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
serialPort.WRITE("2")
TextBox1.Text = "LED 1 OFF"
END Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
serialPort.WRITE("3")
TextBox2.Text = "LED 2 ON"
END Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
serialPort.WRITE("4")
TextBox2.Text = "LED 2 OFF"
END Sub
Private Sub Form1_close()
serialPort.Close()
END Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
END Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
END Sub
End Class
' I hope that the information is useful.
' Forgive my brevity... Watching TV...and I'm hungry.