Shop OBEX P1 Docs P2 Docs Learn Events
VB Express to Stamp Template — Parallax Forums

VB Express to Stamp Template

UnsoundcodeUnsoundcode Posts: 1,532
edited 2011-12-19 14:00 in BASIC Stamp
Occasionally I see interest from people wanting to use PC applications to interface to a Stamp module. The most common problem they face is usually figuring out how to communicate through the serial port. I have written a short description of how to set up a template that provides a serial interface that can be used and reused in many applicaions. The notes contain all the neccessary code and a short example of sending a byte to a Stamp. The only requirements are a PC with VB Express installed a Basic Stamp microprocessor and a·reasonable understanding of the VB and Pbasic IDE.
I am not a technical writer and I have only been messing with VB for about a year so there may be parts of the document that could be explained in a better way.· Any questions comments or suggested improvements are welcome.
If there is any interest then down the line I may add further, things like servo control and sensor input.

regards
Jeff T.
«134

Comments

  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-09-05 19:42
    This is great stuff! Many of us are quite confused by this very topic so I am glad that folks are taking the initiative to document these rather "simple" processes. As more PC programs (simulators, vision processing, MSRS, etc.) become popular, and as hobbyists move to more complex projects that require a microcontroller AND and PC, these sorts of educational gems will be unsed and needed quite often!

    Thanks again!
  • LittleTykeLittleTyke Posts: 34
    edited 2007-09-06 08:25
    I agree. I think Parallax could do more to publicise interfacing VB (traditional, and new-fangled yukky .Net version) to Basic Stamps. But also Delphi, Linux, etc. Publish an official pamphlet, for example. Maybe there are links, but Google is so imprecise one has to traipse through thousands of inappropriate hits.
  • D. AbramD. Abram Posts: 20
    edited 2007-09-06 13:12
    I've got some documentation of the same topic with pictures for the VB code.· This may help the novice VB user get up to speed.· I always look at the pictures first, then if the project doesn't work, go back and read the text [noparse]:)[/noparse]

    http://www.theabramgroup.com/basicstamp/
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-09-06 14:37
    I would like to say thanks to the author as I have Greatly benifited from this topic. I am brand new to VB and have a need in most all my projects to incorperate serial data protocall from a PC to Parallax's products. Thanks to this documentation "and the authors support" I have a VB program up and running that communicates to a BS2 through (2) Spread Spectrum Trancievers.

    "My Hat is off" Jeff,

    JMLStamp2p
  • Shawn LoweShawn Lowe Posts: 635
    edited 2007-09-06 16:14
    I think its cool that VB express is free! Right on!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    Maybe I should have waited to do that......
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-09-06 16:28
    Hi guys, I am really glad you all think this is useful and I hope everything is easy to follow and understand. Within the next few days I will probably add another piece.

    Little Tyke, I have seen you have already built some succesful VB to Stamp interfaces. What we have to remember though is that there are many such similar programs to VB and that the people who want to use Visual Basic with the Stamp are a relatively small group. It would be unreasonable to expect Parallax to try and support all these third party programs. The beauty of a discussion forum is that you and others with similar interests can exchange ideas and reduce the need to scour the internet for information. You do good work keep sharing.

    I have to post this link because this guy does a first class job

    http://forums.parallax.com/showthread.php?p=640960

    regards

    Jeff T.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-09-07 17:25
    Here is a small add in to the template. The app controls two servos with sliders (trackbars). The most valuable thing about it though is the way the Stamp controls when data is sent from the PC and the use of strings to synchronize tx/rx.

    Jeff T.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-09-16 21:01
    Hi to all, I see a good amount of interest in the original template. Not a tremendous amount of feedback··nono.gif·· but I'm sure most have found it easy to follow.
    The template and the servo control had simple examples of sending data to a Stamp to help the user get started.
    I have here a simple upgrade to the template that adds a little more complexity. The changes are not huge and if you found the first app relatively easy this will be no harder. The benefit of the upgrade to code is the ability of the PC to read data as it is sent and as fast as it is sent. The example included is a functional Debug application that can be used in a similar way to using Hyper Terminal.

    It would take very little effort to turn the application into a data logging program or RFID reader database·by·writing to a text file instead of a textbox.

    Jeff T.
    409 x 521 - 90K
  • BeanBean Posts: 8,129
    edited 2007-10-22 16:32
    Jeff,
    Thanks for posting this. It has greatly helped me get "up to speed" with Visual Basic 2005.

    Do you know if Visual Studio 2008 is going to handle serial ports the same way ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-10-22 18:45
    Bean, I'm really glad you found it useful. The template is a simple project but a great starting point for any Visual Basic windows application that uses serial communication. This makes it particularly useful for Stamp based projects.

    Since posting the template docs I have added VB Delegates to the code which allow for cleaner access to VB Controls (text boxes etc)·when using the Data_Received event.

    I advise the use of delegates and if you or anyone else that may be interested would like to learn more about the use of delegates then PM me and I can provide a link or two that explain the subject better than I could.

    thanks for the feedback

    Jeff T.
  • TomOTomO Posts: 3
    edited 2008-01-04 14:51
    Cheers Jeff, awesome stuff. The template for the servo control is excellent, ive been looking for an example like this for ages.
    The board im using is a parallax USB servo control board, will this code work with it given that it uses a virtual serial port or will it need editing slightly as this is for a basic stamp (not sure if the parallax board is a stamp or not)

    Thanks again

    Tom
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-04 16:07
    Hi Tom, the application will work just bear in mind that any command you send will be echoed back and must be discarded from the buffer before sending the next command. The servo position command would look something like this for a PSC

    _port.WriteLine("!SC" &·0 & 0 & high_byte & low_byte)

    to derive high and low byte you might do this

    low_byte=command_value AND &HFF

    high_byte=command_value >> 8· AND &HFF

    feel free to ask if you run into problems

    Jeff T.

    EDIT : It's worth mentioning that some motor controllers accept RS232 (+/- 12v) some accept RS232 at TTL level (+5v to 0v) and some·have the option of both. The PC com port should not be connected directly to a TTL level serial input. The PSC USB connector converts the RS232 +/- 12v to TTL level and thats fine. Other controllers might need a level shifter so it pays to check before making any connections.

    Post Edited (Unsoundcode) : 1/4/2008 7:02:43 PM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-26 23:37
    Over the past month I have seen an interest from those wanting to code their own Parallax servo controller. This has been done before in several formats and although this version leaves a lot of scope for improvement I feel it is different enough to post here.

    This is not stand alone it is intended to be integrated into the Template from the original post of this thread.

    The main problem I have is that I don't own a PSC blush.gif

    I think the serial string is close enough to work if not it would not take much to bring in line. What I would like is for someone to test it and give me feedback. If it needs modification I can then edit this attachment to suit.

    Jeff T.
    342 x 368 - 24K
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-02-17 04:52
    JEFF T, THANK YOU so much for·posting this!

    Both Apps (Template and the Slider servo controller) worked the first time!· NOTHING ever works the first time!·
    · I'm new to·both the stamp and VB (VERY NEW to VB) , and this gives me a toe hold on developing something interesting.
    My current project is posted below on youtube.·


    http://www.youtube.com/watch?v=jI79Xsm_Kyk
    Because I write such bad code the currrent routine runs pretty slow and jerky on the BS2.· I'd someday like to get this configured so that the robot controls itself (servos) and monitors the sensors but the PC makes the logic decisions on what to do in various situations.· I'd imagine one could do nearly infinite data logging and maze solving, route planning, etc. if the data is passed up to a PC type procesor.·If I get camera data through a USB port, can I processs that in VB code to make the bot SUPER smart?· Lots of possibilites here....

    Any suggestions on how to make the connection wireless?· eb500, or is there a better approach?

    More VB code comments would help me to better understand what is going on in the VB code.

    I've been slowly plowing my way through a VB manual I bought at Borders (Visual Basic 2005·How to Program, Deitel) but it is intense and tedious learing.· Any suggestions on other VB training resources·that would be useful for robotic applications?·

    Based on my very positive experience with the Parallax manuals, I'd be the first in line to buy a "VB and the Basic Stamp" training manual!!!! Are you guys listening!!!

    THANKS Again!!!
    ··
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-17 06:08
    That was a great video Steve.

    Sorry for the lack of comments in the Visual Basic, I tried to highlight the main points.

    A lot of this is relatively new to me so I like things explained as simply as possible, and that is what I try to do when I attempt to explain something.

    If you want what in my opinion is a good starter book for Visual Basic take a look at Visual Basic 2005 Cookbook·from·O'Reilly ( www.oreilly.com )

    Jeff T.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-18 16:13
    This short sub routine will reset a Stamp from within a VB application. This is a really nice feature you might use immediately after opening the serial port ensuring that both programs initialize at the same time or you may assign it to a button for debugging purposes.

    Jeff T.
  • sylvie369sylvie369 Posts: 1,622
    edited 2008-02-19 00:47
    Great thread - thanks to those of you who posted code and information. I set up the serial communications VB project from the first post, and it worked right away. Fascinating.
  • bennettdanbennettdan Posts: 614
    edited 2008-02-19 03:36
    Jeff T.
    ·· I like the thread and I have a few VB.net programs I could share if you want them.
    SteveWoodrough
    ·· I have used the bluetooth moduals but they are not very long range..I like these units and they are very nicly priced..
    http://www.sparkfun.com/commerce/product_info.php?products_id=7816
    or even faster but more expensive...
    http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=XB24-DKS-ND

    I have added a small program that allows you to bring webcams into your forms and control a Pan/Tilt camera with servos and
    then control your bot with the buttons. I have not attached the BS2 program but all that is needed is read the serial port then use an
    IF THEN statement like this.

    Main:
    · SERIN 16, 16468, [noparse][[/noparse]STR command\1]··· ' Get 1-byte string

    CheckCommand:
    · IF command = "1" THEN
    ···· GOTO·CENTER
    · IF command = "2" THEN
    ···· GOTO·LEFT
    · ENDIF
    · IF command = "3" THEN
    ···· GOTO·RIGHT
    · ENDIF
    · GOTO Main

    CENTER:
    PULSOUT 15, 750···· 'Centers a servo....
    GOTO Main
    If you have any questions please post them here and we can share....
    I also have some PC Joystick control and Hot key control programs to I will have to dig them up..
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-19 17:04
    Hi Dan, the Tracbot Control worked really well I am sure there are people who want video·for their Bots, the pan and tilt is a great feature.

    The Windows API calls are complex and it is something I have steered away from because I have problems understanding it all. That does not exclude it from being used if we treat it as a piece of "black box" code that we can slot into our projects.

    My original idea was a natural progression using the Template in the OP, is it possible for you to post a version that uses this VB Template so that the port and baud are selectable and perhaps add some controls that give the user the option to select a capture device·and also·start and stop the capture.

    Jeff T.
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-03-01 20:57
    I guess I'm just stuck at the rank of "tenderfoot"

    I can't get tracbot to work.· He's what I've done.·

    copied simple program to my bot (previously confirmed that HIGH 8 lights an LED) see attached bs2 program

    Loaded tracbot into Visual Basic 2005 Express.· changed COM port to 4 (same com I use to program the bot) kept the baud rate to 9600

    executed tracbot through VB debugger

    When I click the buttons on the tracbot form, the tiny LED on my serial connection blinks, so I'm pretty sure data is going out, but my LED connected to Pin 8 never lights.

    I'm misssing something simple.

    THANKS!
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-03-01 21:39
    I'd like more information on the RF modules. What plugs in on the PC side?

    Also, the twin servo program above works great at 4800 baud but works strangely (or not at all) when I go from 4800 baud (16572) to 9600 baud (16468) Why?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-01 22:48
    Hi Steve, the BS2 can have problems communicating at bauds above 2400. The problem in the case of the Twin Servo is the WAIT instruction, I have been able to overcome the limitation of the WAIT by placing a short pause between the header and the data transmitted string but usually the difference between 4800 and 9600 is of no consequence. If you need the extra speed the [url=mailto:BS@px]BS2px[/url] will do it.

    RE Tracbot, do you have video. I didn't try the serial side of it but if I get time this weekend I will take a look at it, I don't think it's a major issue.

    Jeff T.
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-03-02 00:57
    Thanks Jeff,
    I'm OK with 2400 as long as there is a reason why the BS was acting goofy.

    On the trackbot side, No I do not have video yet. I was working with the trying to get the bot to respond to mouse clicks I'm still feeling my way around in the dark with VB. I feel like I'm trying to untangle a ball of thread in the dark with gloves on. As we speak, I'm trying to modify your template so that I can read and write data to the BS2. Expect a post by midnight! I bought both the VB Cookbook and the Programming VB books by O'reilly. I'm not sure they really help me too much. I may try to modify your template to do the same. Look forward to hearing from you...Thanks Steve
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-02 02:28
    Hi Steve, the document "How to Create a Communications Template" in the original post describes how to send a byte to a BS2. The way I tell it is not the only way but it does work.

    VB..........._port.WriteLine(1)

    Stamp....SERIN 16,baud, [noparse][[/noparse]DEC X]

    The VB Cookbook really is good for a beginner, I think you will agree with me a little further down the road.

    The original template is everything you need to begin designing a program to interface to a Stamp or Prop and adding in a video interface is no exception. Because this forum is dedicated to the Stamp I don't want to get·distracted and lean towards VB too far. Having said that if you have any issues with the VB application you are building feel free to drop me a PM.

    Jeff T.
  • varmavarunvarmavarun Posts: 6
    edited 2008-03-04 08:35
    Hey, I posted this on another thread, but just thought that it would be relevant here.

    I'm currently working on a Visual Basic Application GUI for my Boebots. For now, what I basically want it to do is this:

    1. Send a byte to the basic stamp connected to my computer via serial port. (I can do this).

    2. Make this basic stamp perform an operation eg,·pulsout on a·servo motor (this is also alright)

    3. Have this basic stamp send a byte to another basic stamp via RF (using serout); and have the receiving boe bot do something, and then send a byte back (lets say x)

    4. Have this new byte x displayed in the GUI.

    I'm having trouble with steps 3 and 4. The code should be rather simple, but for some reason I can't get it to work. I know its possible because it actually worked once before.. but it isnt anymore (i lost my code).

    Parts of code: (for BS2 connected to my comp-- transmitter):


    · PULSOUT 11, 1200 'Sync pulse for the receiver·( I can verify that this happens, the bot·moves)
    · SEROUT 11, 16468, [noparse][[/noparse]"!" ]
    · PULSOUT 12, 850

    For the other BS2, relevant part

    PULSOUT 13, 850
    LOW 0
    SERIN 6, 16468, [noparse][[/noparse]WAIT("!")]
    HIGH 0
    PULSOUT 12, 850

    What could the issue be? Is it just a little snag in something like baudrates? And lastly, once this gets sorted out, is it possible to remote control a robot over RF via this BS2 plugged into my computer?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-04 10:30
    varmavarun -

    If these program snippets are supposed to send and receive the "X" byte you are looking to send back and forth, that is completely missing from BOTH programs. The variable "X" needs to be defined in EACH program, and the respective SEROUT and SERIN commands need to have it specified as well.

    My suggestion is to look at the PBASIC Help file, and check out SEROUT and SERIN for the details of how those commands operate. That should get you going again, if that's the problem.

    However, I have a sneaking suspicion that if you remove the wire from Pin Port 11 on the Stamp from the first program, that you will STILL get the "sync pulse" that you seem to believe is coming from that first program. My guess is that you may have the wrong Pin Port specified in the first program, but again, that's just a guess. You will have to confirm whether that's a problem or not. The reason I say that, is that you are performing the PULSOUT AND the SEROUT to the same Pin Port, and that just doesn't seem correct - but I'll again leave it to you to confirm whether that is a problem or not.

    As far as the RF business, I'd suggest you get the PBASIC Programming down just a bit better, before you get involved with more sophisticated projects. Yes, it can be done, but it may not be as simple as you may think it is.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming can't be all that difficult, it's nothing but 1's and 0's
  • varmavarunvarmavarun Posts: 6
    edited 2008-03-14 11:59
    hey Bruce,
    Thanks for your reply.

    I managed to get the rf thing working over visual basic. i basically just changed the baud rate. now i can control a boe bot via rf via a basic stamp. so its basically VB GUI
    > basic stamp
    > (RF)
    > second basic stamp on boe bot. i might put up a video in a bit.
  • stamptrolstamptrol Posts: 1,731
    edited 2008-03-14 12:30
    Hello all,

    I just finished teaching an industrial Stamp course yesterday. To demonstrate serial communication, I used Micro Quicktrol which was written by Jeff T.

    The system worked perfectly and the students (all industrial technicians) were amazed at how simple it was to get a really professional front-end for a Stamp Project.

    It available from the "Downloads" page of my web-site www.siskconsult.com for anyone who wants to see another example of Jeff's excellent work.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • ElementElement Posts: 9
    edited 2008-03-15 15:55
    Is there a way to get button 1 to open and then close immediately after? I would be using the button to turn on an LED, but what I want is it just to flash once. Then button 2 would be used the same way except for a different LED.

    If anyone could explain on how to do this that would be great!

    Thanks!
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-03-16 16:23
    Hi Element, I have had a couple of requests on how to interface to a Boe Bot controlling two motors using the original template. The code actually latches the output depending on which direction is pressed. This can easily be modified to "one shot" an LED. I am attaching the complete template.

    In the Vb code in the write_to_stamp sub I have commented out a line that will give the "one shot",·insert the comment into the code if you require a "one shot"

    Because it is a fairly simple program it runs at 9600 quite well.

    This is the code for the BS2, just modify it to your needs

    main:
    · SEROUT 16,16468,[noparse][[/noparse]"#"]
    · SERIN 16,16468,25,timeout,[noparse][[/noparse]DEC1 x]
    ··· timeout:
    ON x GOSUB Halt,Forward,Back,Right,Left
    GOTO main

    The attached zip file is a template, don't unzip it, copy it to your MyDocuments/VisualStudio/Templates/ProjectTemplates folder. Any problems let me know.

    Jeff T.
Sign In or Register to comment.