Wednesday, October 26, 2011

Controlling a Basic Stamp II With Visual Basic


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.
' I will respond to any comments and try to answer any questions.

Wednesday, October 19, 2011

8 Step Sequencer with 555 Timer and 4017 Decade Counter


I set this one down some time ago but it was my goal was to build an 8 step sequencer with a 555 Timer and a 4017 Decade Counter.
I know this shit is old school but you gotta learn somehow.


supplies:
4017 decade counter
555 timer
capacitors
resisters
perf. board or bread board

Some knowledge of the 555 Timer is helpful.

 I picked up a few 4017s from Jameco Electronics  for like .40 cents each.
The rest of the stuff I got from a local Radio Shack.
The 555 timer produces an oscillating square wave, which triggers the 4017 decade counter IC, 8 of which its outputs are connected to LEDs. I have the counter set to reset after 8 steps, by simply connecting the next output pin to the reset pin. The green wires are the outputs of the 4017.
For an example check my video.
                                                      http://www.youtube.com/watch?v=rR9tFKMrAFs

Suggestions and/or inspiration would be greatly appreciated. I may pick this project up again.
  • Should each output of the 4017 Decade Counter be connected to a separate tone generator?
  • Should I connect all of the outputs to the same tone generator and vary the frequency of the tone via a potentiometer connected in between each out output of the 4017 and the tone generator? ...and if so some direction as to the implementation would be greatly appreciated.