Rotating a servo motor using VB code.
manishroy
Posts: 16
hi all,
I am working on a micro robotics project.I have to rotate servo motor using VB interface on my pc using Basic stamp 2.I searched net nothing comes with the complete solution to it.please help me and if possible send me some links or codes from where i can get fair amount of idea about how to do it.
Thanks in advance!!
I am working on a micro robotics project.I have to rotate servo motor using VB interface on my pc using Basic stamp 2.I searched net nothing comes with the complete solution to it.please help me and if possible send me some links or codes from where i can get fair amount of idea about how to do it.
Thanks in advance!!
Comments
- To send data from VB to Stamp you use the SerialPort control. It's very well documented. Google it.
- To receive data in the Stamp you use the SERIN command.
If you don't have a RS232 - TTL converter, you can use port 16 on the Stamp, and use the programming cable (no need for extra hardware). If you do this, you cannot use the DEBUG command, because it also uses port 16.
You write SERIN 16, baudrate, etc...
Turning the servo is documented in abundance in Parallax documents.
hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
But let me tell u that my problem is not only rotating servo but i have to control a whole Bot through VB script and BS2.I am not much conversant with VB so i just thought if i could get a sample code about how to rotate a servo motor using VB and Basic Stamp2 then i could read that and understand how the other things could be done.So if anyone could help me with that plzz..
·
What flavor of VB are you using? For instance I have a personal copy of VB4 and the code I have for that works very well to control a Servo through serial commands, but it breaks on any other version of VB.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I could send you the code, but you wouldn't understand it, and I think it's a much better way to learn things to divide your projects into smaller ones, and get the small ones working, one by one. So:
- Get the serial communication between VB and Stamp working.
- Start simple. Send "1" to the Stamp to turn on a Led, and "0" to turn it off.
- Get the servo working.
When you do this, you will have specific questions to post on the forum, instead of a vague question about some project with a servo.
In VB.Net:
1) Drop a SerialPort control to your Form1
2) Form1_Load:
SerialPort1.PortName = "COM1"
SerialPort2.BaudRate = 9600
3) SendButton1_Click:
SerialPort1.Write("!1")
4) SendButton2_Click:
SerialPort1.Write("!2")
On the Stamp, you use the SERIN command with WAIT("!"). Look in the documentation for the command.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
Post Edited (dev/null) : 9/30/2009 8:32:45 AM GMT
· I am using VB in Visual Studio 2008.You can actually send me the code i have the setup of VB4 i will use that to read it.
· Thanks in advance!
2) Form1_Load:
SerialPort1.PortName = "COM1"
SerialPort2.BaudRate = 9600
SerialPort2.Connect()
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
For the VB4 code, follow this link about a third of the way down...
http://forums.parallax.com/showthread.php?p=549166
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
What may be the problem.I have checked my connection they are fine.
- Check that your battery or power source is above 6V.
- Check your COM ports in the Device Manager in Windows. My Computer --> Properties --> Advanced --> Device manager
- Check that you have the latest version of the Stamp IDE (in the resources tab on parallax.com)
Also, to help you, please state the type of board you have (Board of Education?) and which Windows version you are running.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
If yes, will the code be different for that?
If no,then tell me how to connect the motors to the pin 0 and pin 1 of kit.
I am attaching the discovery kit picture that i am using.
Now my communication is fine.So please help me to get my servos working.I just posted the problem i am facing.Please help.
Which documentation you are talking about?
Where can i find them?
If possible please send me the link.
Thanks in advance!
What's happening is it really responding to the code or its something else???
plzz help..!!
The code i have attached was previously download from one of the threads in this forum.
You told me to post the copy of my code in the forum,i did that but since then there has been no response from your side.My guide is getting blue-black with anger.Please tell me how to get my servos moving...??
reply soon..!!
A servo won't respond to a pulse less than 0.5-1ms in width and the x and y values are initialized to zero. It may be that your PC program isn't sending anything or isn't sending valid information and the receive routine on the Stamp is timing out and using the initial values (of zero). That could make the servo twitch if you've changed the pin numbers in the code to correspond to how you've got the servos connected.
Make sure your VB code is correct. I can't help you with that since I don't really know VB and I don't have any reference manuals.
Make sure that your power source can supply 1A at least. Servos can draw quite a bit of peak current.
Post Edited (Mike Green) : 10/24/2009 8:30:01 PM GMT
Thanks for all you do,
Jim
http://forums.parallax.com/showthread.php?p=467912
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
Now coming to HOVER1!!
I was demanding in my last post because Mike's last replies were quite prompt and i naturally expected a prompt reply this time also.I have seen people in the forum who promise to help throughout the process and then disappear.I myself dont know VB much but as this project has been assigned to me i have to do it...because there is nothing that's impossible.And i am telling u i will do it...its just a matter of time.
I publicly ask if any of you guys out there have even a little bit of experience about interfacing servos through VB code using Stamp please help me.I have posted the code in this forum and tried to describe the fallacy with the best of my knowledge.
Post Edited (manishroy) : 10/25/2009 5:11:22 AM GMT