Shop OBEX P1 Docs P2 Docs Learn Events
Rotating a servo motor using VB code. — Parallax Forums

Rotating a servo motor using VB code.

manishroymanishroy Posts: 16
edited 2009-10-25 05:33 in BASIC Stamp
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!!

Comments

  • dev/nulldev/null Posts: 381
    edited 2009-09-29 14:46
    Some starters for you:
    - 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
  • manishroymanishroy Posts: 16
    edited 2009-09-30 04:21
    dev/null said...
    Some starters for you:
    - 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.

    Thanks null!
    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..
    ·
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-09-30 04:39
    manishroy,

    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.
  • dev/nulldev/null Posts: 381
    edited 2009-09-30 08:27
    I recently did a project with VB.Net which controlled 3 Stamps, 16 servos, and about 6 sensors. The Stamps used RS232 between each other, and a master Stamp communicated with VB via a serial port.

    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
  • manishroymanishroy Posts: 16
    edited 2009-09-30 09:44
    · hi Schwabe!
    · 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!
  • manishroymanishroy Posts: 16
    edited 2009-09-30 09:50
    Thanks dev/null for your help.
  • dev/nulldev/null Posts: 381
    edited 2009-09-30 11:16
    I forgot Connect. I will check later today my project and send you some more code.

    2) Form1_Load:
    SerialPort1.PortName = "COM1"
    SerialPort2.BaudRate = 9600
    SerialPort2.Connect()



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-10-03 06:16
    manishroy,

    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.
  • manishroymanishroy Posts: 16
    edited 2009-10-03 19:03
    I am getting a basic problem when i am connecting Basic stamp with my PC using one of my USB port.The error that i am getting when i try to run a simple Hello World program in basic stamp is : "NO Basic Stamp Found"
    What may be the problem.I have checked my connection they are fine.
  • dev/nulldev/null Posts: 381
    edited 2009-10-03 20:21
    There is a thread where Mike has some comments about this. It's a common problem.
    - 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
  • manishroymanishroy Posts: 16
    edited 2009-10-08 16:38
    Now my basic stamp's communication with the pc is fine ...its working.I am able to exchange data between basic stamp and VB code.As next step i tried to rotate the servo using the code given in a thread in this forum of "twin motors".But motors are not working.It says that i need to connect the motors to the pin 0 and pin 1 of basic stamp,i did that but nothing happend.I am using a basic stamp discovery kit for all this communication.As it must be known that a basic stamp discovery kit has 4 ports. Can i connect the motors using those ports with the basic stamp?
    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.
    500 x 357 - 78K
  • manishroymanishroy Posts: 16
    edited 2009-10-08 16:40
    hi dev/null
    Now my communication is fine.So please help me to get my servos working.I just posted the problem i am facing.Please help.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-08 17:24
    If you read the documentation for the Board of Education (used in the Stamp Discovery Kit), you'll see that the servo "ports" are connected to Stamp I/O pins 12-15. You could change the program you're using so it uses these I/O pins or you can connect to pins 0 and 1 using socket X2. The socket holes marked P0-P15 are connected to the Stamp I/O pins 0-15.
  • manishroymanishroy Posts: 16
    edited 2009-10-08 18:50
    Hi mike!
    Which documentation you are talking about?
    Where can i find them?
    If possible please send me the link.
    Thanks in advance!
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-08 19:13
    As with all Parallax products, go to the Parallax webstore page for the product you're curious about, in this case, the Discovery Kit. You'll see a list of the Kit contents and all of the items on that list are weblinks. Click on the one for the Board of Education USB and you'll go to the product page for it. On that page, there's a link to the manual for the board and a schematic (the manual also has the schematic in it).
  • manishroymanishroy Posts: 16
    edited 2009-10-12 13:30
    I read the documentation.Still i have a query.When someone tells me to connect servo 1 to pin 0 and servo 2 to pin1...in that case what should i do....which socket or which pin position will serve my purpose?
  • manishroymanishroy Posts: 16
    edited 2009-10-13 15:16
    My motor is responding to the VB code,but not properly.When i am connecting the motor to the ports on BOE the servo shakes a little then stops.When i again try to adjust the connection of servo with the ports again it shakes a little and stops.The most funny thing is that even if i disconnect the BOE from the PC and the power supply is on,in that case also if i adjust the servo connection the servo shakes a little and stops.
    What's happening is it really responding to the code or its something else???
    plzz help..!!
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-13 15:46
    In most cases, the I/O pins are all interchangible. You could use any I/O pin for controlling a servo as long as the program was changed to use the correct pin number. The PIN declaration is intended to make this easier by allowing you to name an I/O pin so you can specify the actual pin number in only one place in your program where it's easily changed. Really the only exceptions to this are in some of the I/O statements in the BS2p/pe/px models that use multiple I/O pins like the LCD and I2C I/O statements.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-13 15:49
    Please post a copy of your program and some kind of schematic drawing showing how you have things connected. The "shakes a little and stops" could be due to all sorts of things from a power supply problem to a coding error.
  • manishroymanishroy Posts: 16
    edited 2009-10-14 06:07
    i have attached the copy of my code...about the circuit...its a very simple circuit with a power supply from a adapter,connection to PC using serial to USB cable and servo is connected to port x15.
    The code i have attached was previously download from one of the threads in this forum.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-16 02:16
    Did you do the projects prior to the one you posted? If memory serves me correctly there is one or two steps prior to this one that you need to complete in order for it to work. I was able to get the same thing going woth VB 8 also. I actually modified mine so that everything is on one form. If you would like a copy send me a PM and I will send it to you.
  • manishroymanishroy Posts: 16
    edited 2009-10-24 19:27
    hi mike,
    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..!!
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-24 20:24
    The code that you posted uses I/O pins 0 and 1 for the two servos. It sends "RDY" to the PC and expects back "!xxxxyyyy" where xxxx is a value from 0 to 9999 and represents the width of the servo pulse for the servo attached to I/O pin 0 in units of 2us (for the BS2). yyyy is a value from 0 to 9999 and represents the same thing for the servo attached to I/O pin 1. If nothing is received by the Stamp within 15ms, either from the "RDY" or the last character of the !xxxxyyyy received, the input operation aborts and the most recently received values are used.

    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
  • hover1hover1 Posts: 1,929
    edited 2009-10-24 22:00
    Mike, you have the patience of a Saint. Mr Manishroy was a little demanding in his last post. Maybe he doesn't understand that no one here gets payed to give up their free time to respond to questions.

    Thanks for all you do,

    Jim
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-10-25 01:39
    That type of response will not be tolerated. Manishroy you should read the forum guidelines before posting again.

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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • manishroymanishroy Posts: 16
    edited 2009-10-25 05:06
    First of all i would like to thanks mike for his help.
    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
  • manishroymanishroy Posts: 16
    edited 2009-10-25 05:13
    I apologize if i have violated any of the guidelines. I was just trying to get a prompt help...Because we have something called DEADLINE for our project.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-25 05:25
    As others have mentioned, most of the "experts" here are volunteers that have real jobs other than the help they provide here and these jobs tend to demand a lot of time in a sometimes unpredictable fashion. There are a handful of Parallax employees, but they too have jobs at Parallax that primarily have little to do with these forums (fora?). You've been given quite a lot of help, particularly with the Stamp side of things. This is not a VB support forum, yet you've also been provided with some examples of VB code. Whatever VB code exists here is not organized the way Stamp / SX / Propeller code is organized. You'll have to tediously browse through the forum trying to find other examples and there are no guarantees you'll find what you want. Sorry, but that's the way it is. If you're lucky, someone may just happen to visit the forum that has an example you might find useful, but I wouldn't count on it. That's the nature of a forum like this when you're asking about something outside the subject area of the forum.
  • manishroymanishroy Posts: 16
    edited 2009-10-25 05:33
    Thanks Mike i will take care of that in future..!!
Sign In or Register to comment.