Shop OBEX P1 Docs P2 Docs Learn Events
Using VB with Stamps — Parallax Forums

Using VB with Stamps

ArchiverArchiver Posts: 46,084
edited 2000-06-16 13:53 in General Discussion
Hi there,
I am a fairly acomplished Visual Basic Programmer and would like to
know if anyone has managed to communicate with the stamp using VB
programs. In particular I would like to know how to do simple thinks
like control servos using VB instead of using the terminal program.
Also this allows me to manipulate data more easily cuz vb can work
with negative numbers where as the stamp can't Anyway i was just
interested. If anyone has done this can u letme know the sorts of
things u did maybe send me some source code etc. =] Any info would be
nice. Thanks very much.
-regards
Alistair

__________________________________________________________________
Get your free Australian email account at http://www.start.com.au

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-06-15 12:34
    In a message dated 6/15/00 3:18:29 AM Central Daylight Time,
    pointybeard@s... writes:

    > I am a fairly acomplished Visual Basic Programmer and would like to
    > know if anyone has managed to communicate with the stamp using VB
    > programs. In particular I would like to know how to do simple thinks
    > like control servos using VB instead of using the terminal program.
    > Also this allows me to manipulate data more easily cuz vb can work
    > with negative numbers where as the stamp can't Anyway i was just
    > interested. If anyone has done this can u letme know the sorts of
    > things u did maybe send me some source code etc. =] Any info would be
    > nice. Thanks very much.

    I use VB to talk with my Stamps. In general, I put the MSComm control in
    text mode and use SERIN modifiers. This allows me to test my Stamp code with
    a terminal program before dealing with the VB stuff. For example, a program
    I recently wrote has the Stamp waiting for a command from the PC like this:

    SERIN sioPin, baud, [noparse][[/noparse]WAIT ("?"), HEX cmd, HEX param]

    (cmd is a byte, param is a word).

    From a terminal I can enter: ? A0 FFFF<cr> and get the Stamp to respond
    (note the space between A0 and FFFF). To duplicate this in VB is pretty easy
    (VB has a Hex function), but you have to give a bit of pacing time between
    each character. I've found that 2 ms works fine at 9600 baud.

    The output from the Stamp is generally text oriented, like "temp=23.7"<cr>.
    Again, this allows me to see how everything is working with a terminal. In
    my VB apps, I trigger the OnComm receive event with each character. I build
    a buffer until a CR is received. When that happens, the buffer is processed
    and any data is parsed out.

    I too, like that VB can deal with negative numbers. Remember that you can
    send them to the PC with the SDEC modifier. I generally define my VB
    variables as Longs and use CLng to convert the text data sent from the Stamp
    into a numeric. If you send hex numbers from the Stamp, you'll need to add
    "&h" to the string before VB can use the Val function to convert it.

    -- Jon Williams
    -- Dallas, TX

    Resources:

    "Stamp Applications" - Jon Williams
    Nuts & Volts magazine
    July 2000 / August 2000 - "Stamps In The Lab"

    Serial Port Complete - Jan Axelson
    www.lvr.com

    Visual Basic Programmer's Guide to Serial Communications - Richard Grier
    www.maybry.com
    http://ourwourld.compuserve.com/homepages/richard_grier
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-15 13:39
    Alistair,

    We have several complete VB programs & tutorials for
    controlling servo motors & talking to the BASIC Stamp
    at: http://www.rentron.com

    Controlling Scott Edwards' Mini SSC II serial servo controllers.
    http://www.rentron.com/Mini-ssc.htm

    Controlling servo motors with your PC + the Stamp, or even
    a PIC. Complete BASIC Stamp & PIC16F84 code is on
    this same page. http://www.rentron.com/SerialServo.htm

    Yet another VB example to control servo motors with your PC
    and the Stamp. http://www.rentron.com/servo.htm

    If you need more information on using VB to talk to/control the
    Stamp, just let me know. I'll be happy to help you get the project
    up & going.

    Regards,

    Bruce Reynolds
    webmaster@r...


    Original Message
    From: "Alistair Kearney" <pointybeard@s...>
    To: <basicstamps@egroups.com>; <pointybeard@s...>
    Sent: Thursday, June 15, 2000 2:17 AM
    Subject: [noparse][[/noparse]basicstamps] Using VB with Stamps


    > Hi there,
    > I am a fairly acomplished Visual Basic Programmer and would like to
    > know if anyone has managed to communicate with the stamp using VB
    > programs. In particular I would like to know how to do simple thinks
    > like control servos using VB instead of using the terminal program.
    > Also this allows me to manipulate data more easily cuz vb can work
    > with negative numbers where as the stamp can't Anyway i was just
    > interested. If anyone has done this can u letme know the sorts of
    > things u did maybe send me some source code etc. =] Any info would be
    > nice. Thanks very much.
    > -regards
    > Alistair
    >
    > __________________________________________________________________
    > Get your free Australian email account at http://www.start.com.au
    >
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-15 13:44
    In addition to Jon's reply, I'd add that you can wrap all of the logic up in
    an object. My book "Microcontroller Projects with Basic Stamps" has an
    example of that where you have a class that is essentially the Basic Stamp.
    A small "server" program runs on the Stamp. Then you can control all the
    Stamp I/O with the VB program.

    So for example, your VB program can write:

    Dim io as New Stamp
    io.Start(1) ' select com port
    l1 = io.Stamp_Pulsin(0,1) ' pulse input on P0
    l2 = io.Stamp_RCTime(1,1) ' RCTime on P1

    You could customize the module to any extent you wished. My implementation
    has 31 different commands (basic I/O, pulse I/O, COUNT, shift I/O, PWM,
    RCTIME, FREQOUT, DTMFOUT, WRITE, READ, and 2 "housekeeping" commands).

    You can also find a VB example for a frequency counter in the book or on my
    site: http://www.al-williams.com/stampcom.zip


    Regards,

    Al Williams
    AWC
    * Expand your Stamp I/O with a PAK-III or PAK-IV:
    http://www.al-williams.com/awce/pak3.htm

    >
    Original Message
    > From: Alistair Kearney [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=RfP9mza1u1gVkI_2g-Vvk1J_Q6K1Y8430vAgaaHFsJfGu-naXo02bR0zOwDmVAlQqrutPojrzv1ugRThIYN0xe0]pointybeard@s...[/url
    > Sent: Thursday, June 15, 2000 3:18 AM
    > To: basicstamps@egroups.com; pointybeard@s...
    > Subject: [noparse][[/noparse]basicstamps] Using VB with Stamps
    >
    >
    > Hi there,
    > I am a fairly acomplished Visual Basic Programmer and would like to
    > know if anyone has managed to communicate with the stamp using VB
    > programs. In particular I would like to know how to do simple thinks
    > like control servos using VB instead of using the terminal program.
    > Also this allows me to manipulate data more easily cuz vb can work
    > with negative numbers where as the stamp can't Anyway i was just
    > interested. If anyone has done this can u letme know the sorts of
    > things u did maybe send me some source code etc. =] Any info would be
    > nice. Thanks very much.
    > -regards
    > Alistair
    >
    > __________________________________________________________________
    > Get your free Australian email account at http://www.start.com.au
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-15 14:59
    I too use VB 6.0 Professional to talk to Stamps using pretty much the same
    method as Jon and it works great as long as you keep in mind any limitations
    the Stamp has. The MScomm control is easy to use and extremely powerful. If
    you follow the instructions from Jon everything should work just fine.

    Randy A.
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-16 12:34
    Thanks Very much for the responces i got.
    I have another question regarding the same subject. I want to read a
    thermister and currently am using the rctime command. I use the
    following code:

    High 3
    pause 1000
    RCtime 3,1,a
    debug dec a

    How can i use VB to get the values instead of using the debug window?

    Reason i ask is i am currently making a temp sensor and i would like
    to make reading it easier by using VB. I am basing the sensor on the
    application note 7 from in the stamp manual. I want to make life
    easier by maniplating all the data away from the stamp. Anyway thanks
    for the help.
    regards
    Alistair

    __________________________________________________________________
    Get your free Australian email account at http://www.start.com.au
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-16 13:53
    In a message dated 6/16/00 6:32:18 AM Central Daylight Time,
    pointybeard@s... writes:

    > I have another question regarding the same subject. I want to read a
    > thermister and currently am using the rctime command. I use the
    > following code:
    >
    > High 3
    > pause 1000
    > RCtime 3,1,a
    > debug dec a
    >
    > How can i use VB to get the values instead of using the debug window?
    >
    > Reason i ask is i am currently making a temp sensor and i would like
    > to make reading it easier by using VB. I am basing the sensor on the
    > application note 7 from in the stamp manual. I want to make life
    > easier by maniplating all the data away from the stamp. Anyway thanks
    > for the help.

    It takes more than a few lines of code to read it in VB, but it's not very
    hard. This is how I do it.

    First, you need to setup the MSComm control like this:
    - InputLen = 1
    - InputMode = comInputModeText
    - RThreshold = 1
    - Settings = 9600,n,8,1

    In the OnComm handler, look at each character as it comes in. If it's not a
    carriage return (CR), add it to a buffer (must be defined globally). If it
    is a CR, you can convert the buffer to a number (define you variable as long)
    like this:

    myVariable = CLng(buffer).

    What you'll need to do for this to work is add a CR to the end of your DEBUG
    line. Like this:

    DEBUG DEC a, CR

    In the July and August issues of Nuts & Volts magazine, my "Stamp
    Applications" column is titled "Stamps In The Lab" and goes into details
    about grabbing DEBUG data from the Stamp using VB.

    -- Jon Williams
    -- Dallas, TX
Sign In or Register to comment.