Shop OBEX P1 Docs P2 Docs Learn Events
PC Control of Stamp! — Parallax Forums

PC Control of Stamp!

Bill ChennaultBill Chennault Posts: 1,198
edited 2006-11-27 18:40 in BASIC Stamp
All--

All of my robot and many of my automation ideas include a PC controlling a Stamp. Despite asking in many ways and reading many threads and doing a lot of Internet searches, I could not find out how to do this seemingly simple task.

Perhaps, it is SO simple that everyone can do it and it is not worth mentioning. If so, forgive me . . . but when I did it I was sure excited!

The Stamp (in my case, the BS2pX), simply needs to be set up to listen to PIN 16, which forces it to use Sin for serial communications to your PC (or whatever). (Usually, Sin is used by Stamp's DEBUG.)

So, I wrote a program that used SERIN to listen for one of three ASCII characters, A, B, or C. "A" turns on an LED. "B" turns it off. "C" makes it blink 10 times.

On the PC side all you need is an MSCOMM control set to 9600,n,8,1. Then, send an "A", "B", or "C".

The code is almost too dumb to post. The hard part was getting straight in my head what the Stamp was supposed to do (in this case, just listen and react appropriately) and what the PC was supposed to do (in this case, I explained it above . . . just be read to send the appropriate character).

If you use the PC to open the serial port BEFORE the stamp does, when the Stamp is powered up and the program launched, you will get a "Stamp not found" type error message. So, just power the Stamp up first and run the Stamp program before running the PC program. By the way, I did this via USB which inserted itself on COM6.

--Bill

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Comments

  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-11-25 23:37
    Easy? Who the heck said it was easy?
    The secret is setting up a handshake between the PC and the stamp. Use a time out so the programs dont hang.· The following code I modified from an MS Access program (VBA) that I wrote for servo animatronics.


    Something like this :

    On the Stamp side:
    · LEDPIN VAR Byte
    · idx VAR Byte
    · MAIN:
    · DO
    ··· Redo:
    ··· DEBUG "!",CR
    ··· SERIN 16, $4054, 5000, Redo,[noparse][[/noparse]WAIT ("?"),DEC1 idx]

    ··· LOOKUP idx, (0, 1, 2), LEDPIN
    ····High LEDPIN
    ··· LOOKUP idx, (1, 2, 0), LEDPIN
    ··· Low LEDPIN
    ··· LOOKUP idx, (2, 0, 1), LEDPIN
    ··· Low LEDPIN
    · LOOP

    On The PC Side:
    setup a global variable called "ready"and something like this on the mscomm side:

    Private Sub MSComm1_OnComm()

    Dim InBuff As String
    Select Case MSComm1.CommEvent
    ··· Case comEvReceive
    ······ InBuff = MSComm1.Input
    ······ If InStr(InBuff, "!") > 0 Then ready= True
    ······ Debug.Print InBuff;
    ··· Case Is > 8
    ······ Debug.Print "ERROR!!!!"·
    ··· End Select
    End Sub

    Sub LEDon(LED As Integer) '0 , 1 or 2 for the·LEDs
    ··· Dim tmp As String
    ··· On Error GoTo OutaHere
    ··· Do While Not ready
    ··········· DoEvents
    ··· Loop
    ··· ready=false
    ··· If MSComm1.PortOpen = False Then GoTo OutaHere
    ··· tmp = "?"
    ··· MSComm1.Output = tmp
    ··· pause 10 ' this is a subroutine I do with·the Form timer and TimerInterval property
    ··· 'try a for next loop with DoEvents in the·center instead
    ··· tmp = Format(LED, "0") & vbCr
    ··· MSComm1.Output = tmp
    OutaHere:
    ··· Exit Sub
    End Sub

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 11/27/2006 1:55:28 AM GMT
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2006-11-27 01:55
    I noticed I hadn't changed the name of the flag to "ready" it was still called "capture" I changed it. And added the reset to the flag - all this occurs in the Form Timer in the actual program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 11/28/2006 3:26:42 AM GMT
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2006-11-27 18:40
    TechnoRobbo--

    Ha! Your code is much more sophisticated than mine! I just wanted to "make it work" and it does. My code is virtually useless other than as a demonstration to myself that I can do it.

    --Bill



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.