Shop OBEX P1 Docs P2 Docs Learn Events
Looking for a little help. — Parallax Forums

Looking for a little help.

Fusion360Fusion360 Posts: 5
edited 2005-09-08 15:41 in BASIC Stamp
Hello, new to this whole BASIC thang...

I am sure that somewhere in the great information superhighway this exhixts:

I am looking for a code that accomplishes this:

I am looking to control a servo (I have a Basic Stamp Home Work Board and servo assembled as specified) I would like to assign the keys on my keyboard to have a value (percentage) of servo movement (i.e., pressing the "G" key would move the servo let's say 7% and "H" would move it 8% etc., etc.) I am sure that a someone had created a BASIC code that acheives this I just am ignorant as to where to look.

Any help in finding (or writing) this would be most helpful!

Thanks in advance!

Scott

jumpin.gif·I just like this little guy!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-04 19:41
    Hello,

    ·· Are you trying to do this from a keyboard, or from the PC itself?· If from the PC you would need some software on the PC side as well to handle key presses and send them to the BASIC Stamp, unless you used the DEBUG window.· In any event it's basically a matter of inputting the keystrokes via SERIN and having a small lookup for the key value that correlates to a PULSOUT value.· You could also achieve your servo delay using the timeout on the SERIN.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Fusion360Fusion360 Posts: 5
    edited 2005-09-05 03:09
    Hi, and thanks or the reply. I am trying to run this from the PC. Currently I am trying to run it off of BASIC Stamp Editor V 2.1 I am a total newbie when it comes to this. I am trying to figure out how to program the SERIN to = the PULSOUT value. As mentioned I find it hard to beleive that there isn't a code out there somewhere already written that I could maybe just cut and paste, yes I know that this is the easy route however I am under a huge time crunch to get this done. Any other help of suggestions on where to find this info would be most welcome!
    Thanks again, I really appreciate it!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-05 03:25
    ·· I highly doubt there is going to be any copy-and-paste code for your situation.· You could check out the example code in the Help files for the editor.··Almost every·command has the complete information for the command, as well as some example code on how to use it.· That should get you going.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Fusion360Fusion360 Posts: 5
    edited 2005-09-05 03:30
    I will check it out. If by chance you stuble accross any other info...

    I appreciate the help, thanks agian!
  • Philip GamblinPhilip Gamblin Posts: 202
    edited 2005-09-07 04:20
    If you can flow chart it you can probably program it. Don't forget you have +/- 90 from center. I googled servo timing and found ( correctly or not )
    a servo needs a pulse every 20 ms. That pulse needs to be between 1 and 2 ms in width. 1 ms pulse is full counter clockwise and 2 ms pulse is full clockwise. Look at the timing for PULSOUT for the stamp that you have. IT is IMPORTANT that you realize the timing varies from one stamp to the next. Use DEBUGIN to read your letters from the keyboard, when the letter = X ( insert your letter here) Pulsout to the servo the appropriate pulse width in microseconds to the servo. Use the help function in the PBasic editor to study FOR... NEXT, PULSOUT, DEBUG and DEBUGIN . This should help you get started. You can do this.
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-09-07 14:26
    It's not the desired output that changes from stamp to stamp for servo control, it is the units that the pulsout uses that changes.

    Servos do in fact need to be refreshed if they have not yet arrived at the desired position, and to maintain position (actively) if the position has already been reached.

    There are newer servos that have different timing/resolution needs, be aware of that.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke

    Parallax Tech Support
    rclarke@parallax.com
  • Fusion360Fusion360 Posts: 5
    edited 2005-09-07 19:09
    Fortunalty, the exact stopping/placement of the servo is not critical within 1/4 of an inch either way is within acceptable limits, but thank you. As for muddeling my way through this as mentioned above I am sure I could do this with the right amount of time but of course the project was due (like) yesterday, I was looking for the easy cut and paste method. But... we'll just keep pluggin' away. Thank you so much for your help at least it is pointing me in the right direction.
  • SN96SN96 Posts: 318
    edited 2005-09-07 23:11
    Fusion360, I wrote this code for you and tested it out and it worked fine on my end. Try this code:

    'Homework Board and Parallax Standard Servo. This program moves a servo via a computer
    'keyboard using the DEBUGIN command. Developed by RoboRookie 9-7-05
    '{$STAMP BS2}
    '{$PBASIC 2.5}
    
    counter VAR Word
    KeyIN VAR Byte            'Define KeyIN as a variable
    
    FOR counter = 0 TO 30     'Center servo to position 750
      PULSOUT 15, 750
      PAUSE 20
    NEXT
    DO
     DEBUGIN  KeyIN           'Prompt for user key input.
     SELECT  KeyIN            'Match the contents of KeyIN to match one of the CASE conditions.
      CASE = "x"              'If KeyIN = "x" then execute FOR NEXT loop
        FOR counter = 1 TO 30 'Change vale 30 to a higher number to allow servo enough time
          PULSOUT 15, 1200    'to pulse to proper position. The higher the number, the slower
          PAUSE 20            'the response to user key input. 30 seems to work best with
        NEXT                  'the Parallax Standard servo with the Homework Board.
      CASE = "y"              'If KeyIN = "y" then execute FOR NEXT loop
        FOR counter = 1 TO 30
          PULSOUT 15, 280     '15 = I/O Pin #15, 300 = servo position.
          PAUSE 20
        NEXT
      CASE = "s"              'Center servo
        FOR counter = 1 TO 30
          PULSOUT 15, 750
          PAUSE 20
        NEXT
      CASE = "q"              '"Quit" - Exit DO LOOP and END program
        END
      ENDSELECT
    LOOP
    

    Post Edited (RoboROOKIE) : 9/7/2005 11:29:52 PM GMT
  • Fusion360Fusion360 Posts: 5
    edited 2005-09-08 15:41
    Dude you ROCK!
    Thank you so much for your help! I'll go check it out right now!
Sign In or Register to comment.