VB Express to Stamp Template
Unsoundcode
Posts: 1,532
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.
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.
Comments
Thanks again!
http://www.theabramgroup.com/basicstamp/
"My Hat is off" Jeff,
JMLStamp2p
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
Maybe I should have waited to do that......
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.
Jeff T.
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.
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
·
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.
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
_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
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
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.
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!!!
··
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.
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..
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.
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!
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?
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.
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
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.
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?
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
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.
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
·
If anyone could explain on how to do this that would be great!
Thanks!
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.