Shop OBEX P1 Docs P2 Docs Learn Events
Controling a servo from VB — Parallax Forums

Controling a servo from VB

ArchiverArchiver Posts: 46,084
edited 2002-11-26 02:00 in General Discussion
Hello

Can someone help a newbie?

I am trying to control a servo from Visual Basic. I dont seem to
understand how i shall receive the data from vb. The servo doesnt
behave any good( just jerks). Here is a sample of my code that i
have in the BS2.

'{$STAMP BS2}
output 1
tal var word
x var word


Main:
serin 16,16468,[noparse][[/noparse]wait (255),tal]

low 4
for x = 1 to 100
pulsout 1,tal
pause 10
next
high 4
serout 16,16780,[noparse][[/noparse]X]

goto main

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-24 14:21
    I made a project that has a servo controlling a light switch. I guess this
    might be called a poor mans high voltage controller or wanna-be x-10.

    I stuck the servo arm into the switch box and fashioned a connector rod out
    of a thick coat hanger, then drilled a hole in the arm on the switch to put
    the connector rod thru. Result: Servo goes forward, lights/120vAc goes
    out. Servo goes backward, lights/120v Ac goes on.

    While this is no breakthru in electronics or power control - the cool thing
    is I was able to fashion my own comm cable out of a long phone cord and a
    male and female db9 connectors then hook the thing back to my PC and control
    the switch from fairly far away using a simple VB app - all it has is an Up
    button and a Down button on the GUI as well as an image of a light switch
    that toggles up and down with the actual real light switch.

    Again, I am totally new to this stuff and just doing a lot of guessing and
    expirementing so don't take my code or project for any textbook examples.

    I also realize I could make this project more dynamic by sending more data
    from VB such as servo
    position and having the stamp report back its position to verify it recd.
    the command but there is so much to learn and the weekends are so short so i
    just moved on from this project.

    '***VB Code to send data to stamp
    Private Sub cmdUp_Click()
    comStamp.Output = "U"
    imgLightSwitch.Picture = imgSwitchUp.Picture

    End Sub

    Private Sub cmdDown_Click()
    comStamp.Output = "D"
    imgLightSwitch.Picture = imgSwitchDown.Picture

    End Sub

    Private Sub Form_Load()
    comStamp.CommPort = 1
    comStamp.Settings = "2400,N,8,1"
    comStamp.InputLen = 0
    comStamp.PortOpen = True

    End Sub

    '***Stamp code to accept data from VB and control servo
    '{$STAMP BS2}

    '******************************************************
    'Description
    '******************************************************
    'Program Controls Servo

    '******************************************************
    'I/O defs
    '******************************************************
    Servo con 0 'Servo Pin

    '******************************************************
    'Varibales
    '******************************************************
    Times VAR Byte
    SerData VAR Byte

    '******************************************************
    'Begin Program
    '******************************************************
    Main:
    serin 16,16780,[noparse][[/noparse]SerData]
    if SerData = "U" then servo_up
    if SerData = "D" then servo_down
    GOTO Main

    END

    servo_up:
    for Times = 0 to 100
    PULSOUT Servo,(500) ' move the servo to up position
    pause 5
    next
    return

    servo_down:
    for Times = 0 to 100
    PULSOUT Servo,(350) ' move the servo to up position
    pause 5
    next
    return



    Original Message
    From: "gertlind" <gert.lindstrom@b...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, November 24, 2002 4:10 AM
    Subject: [noparse][[/noparse]basicstamps] Controling a servo from VB


    > Hello
    >
    > Can someone help a newbie?
    >
    > I am trying to control a servo from Visual Basic. I dont seem to
    > understand how i shall receive the data from vb. The servo doesnt
    > behave any good( just jerks). Here is a sample of my code that i
    > have in the BS2.
    >
    > '{$STAMP BS2}
    > output 1
    > tal var word
    > x var word
    >
    >
    > Main:
    > serin 16,16468,[noparse][[/noparse]wait (255),tal]
    >
    > low 4
    > for x = 1 to 100
    > pulsout 1,tal
    > pause 10
    > next
    > high 4
    > serout 16,16780,[noparse][[/noparse]X]
    >
    > goto main
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-24 21:03
    Wow thats using overkill! [noparse]:)[/noparse] But hey it DOES work...

    --- In basicstamps@y..., Matt Lorenz <mklorenz@c...> wrote:
    > I made a project that has a servo controlling a light switch. I
    guess this
    > might be called a poor mans high voltage controller or wanna-be x-
    10.
    >
    > I stuck the servo arm into the switch box and fashioned a connector
    rod out
    > of a thick coat hanger, then drilled a hole in the arm on the
    switch to put
    > the connector rod thru. Result: Servo goes forward, lights/120vAc
    goes
    > out. Servo goes backward, lights/120v Ac goes on.
    >
    > While this is no breakthru in electronics or power control - the
    cool thing
    > is I was able to fashion my own comm cable out of a long phone cord
    and a
    > male and female db9 connectors then hook the thing back to my PC
    and control
    > the switch from fairly far away using a simple VB app - all it has
    is an Up
    > button and a Down button on the GUI as well as an image of a light
    switch
    > that toggles up and down with the actual real light switch.
    >
    > Again, I am totally new to this stuff and just doing a lot of
    guessing and
    > expirementing so don't take my code or project for any textbook
    examples.
    >
    > I also realize I could make this project more dynamic by sending
    more data
    > from VB such as servo
    > position and having the stamp report back its position to verify it
    recd.
    > the command but there is so much to learn and the weekends are so
    short so i
    > just moved on from this project.
    >
    > '***VB Code to send data to stamp
    > Private Sub cmdUp_Click()
    > comStamp.Output = "U"
    > imgLightSwitch.Picture = imgSwitchUp.Picture
    >
    > End Sub
    >
    > Private Sub cmdDown_Click()
    > comStamp.Output = "D"
    > imgLightSwitch.Picture = imgSwitchDown.Picture
    >
    > End Sub
    >
    > Private Sub Form_Load()
    > comStamp.CommPort = 1
    > comStamp.Settings = "2400,N,8,1"
    > comStamp.InputLen = 0
    > comStamp.PortOpen = True
    >
    > End Sub
    >
    > '***Stamp code to accept data from VB and control servo
    > '{$STAMP BS2}
    >
    > '******************************************************
    > 'Description
    > '******************************************************
    > 'Program Controls Servo
    >
    > '******************************************************
    > 'I/O defs
    > '******************************************************
    > Servo con 0 'Servo Pin
    >
    > '******************************************************
    > 'Varibales
    > '******************************************************
    > Times VAR Byte
    > SerData VAR Byte
    >
    > '******************************************************
    > 'Begin Program
    > '******************************************************
    > Main:
    > serin 16,16780,[noparse][[/noparse]SerData]
    > if SerData = "U" then servo_up
    > if SerData = "D" then servo_down
    > GOTO Main
    >
    > END
    >
    > servo_up:
    > for Times = 0 to 100
    > PULSOUT Servo,(500) ' move the servo to up position
    > pause 5
    > next
    > return
    >
    > servo_down:
    > for Times = 0 to 100
    > PULSOUT Servo,(350) ' move the servo to up position
    > pause 5
    > next
    > return
    >
    >
    >
    >
    Original Message
    > From: "gertlind" <gert.lindstrom@b...>
    > To: <basicstamps@y...>
    > Sent: Sunday, November 24, 2002 4:10 AM
    > Subject: [noparse][[/noparse]basicstamps] Controling a servo from VB
    >
    >
    > > Hello
    > >
    > > Can someone help a newbie?
    > >
    > > I am trying to control a servo from Visual Basic. I dont seem to
    > > understand how i shall receive the data from vb. The servo doesnt
    > > behave any good( just jerks). Here is a sample of my code that i
    > > have in the BS2.
    > >
    > > '{$STAMP BS2}
    > > output 1
    > > tal var word
    > > x var word
    > >
    > >
    > > Main:
    > > serin 16,16468,[noparse][[/noparse]wait (255),tal]
    > >
    > > low 4
    > > for x = 1 to 100
    > > pulsout 1,tal
    > > pause 10
    > > next
    > > high 4
    > > serout 16,16780,[noparse][[/noparse]X]
    > >
    > > goto main
    > >
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@y...
    > > from the same email address that you subscribed. Text in the
    Subject and
    > Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    > >
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-25 23:55
    This guy has a good tutorial on how to do that... although you have
    to experiment with some settings in VB. Also, I think he fails to
    mention that you need to setup a timer in VB to read values from your
    PC's serial input.

    www.picobay.com

    hope it helps


    --- In basicstamps@y..., "gertlind" <gert.lindstrom@b...> wrote:
    > Hello
    >
    > Can someone help a newbie?
    >
    > I am trying to control a servo from Visual Basic. I dont seem to
    > understand how i shall receive the data from vb. The servo doesnt
    > behave any good( just jerks). Here is a sample of my code that i
    > have in the BS2.
    >
    > '{$STAMP BS2}
    > output 1
    > tal var word
    > x var word
    >
    >
    > Main:
    > serin 16,16468,[noparse][[/noparse]wait (255),tal]
    >
    > low 4
    > for x = 1 to 100
    > pulsout 1,tal
    > pause 10
    > next
    > high 4
    > serout 16,16780,[noparse][[/noparse]X]
    >
    > goto main
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-26 02:00
    You have:
    > serin 16,16468,[noparse][[/noparse]wait (255),tal]

    You might try:
    serin 16,16468,[noparse][[/noparse]wait (255), Dec tal]

    You need this decimal formatter to tell it it is a number rather than ascii
    text.
    I tested it on a servo and without the Dec it indeed "twitches" but with the
    Dec formatter the servo rolls to whatever number you send in from the VB
    app.


    Original Message
    From: "djhermlewis" <djhermlewis@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, November 25, 2002 5:55 PM
    Subject: [noparse][[/noparse]basicstamps] Re: Controling a servo from VB


    > This guy has a good tutorial on how to do that... although you have
    > to experiment with some settings in VB. Also, I think he fails to
    > mention that you need to setup a timer in VB to read values from your
    > PC's serial input.
    >
    > www.picobay.com
    >
    > hope it helps
    >
    >
    > --- In basicstamps@y..., "gertlind" <gert.lindstrom@b...> wrote:
    > > Hello
    > >
    > > Can someone help a newbie?
    > >
    > > I am trying to control a servo from Visual Basic. I dont seem to
    > > understand how i shall receive the data from vb. The servo doesnt
    > > behave any good( just jerks). Here is a sample of my code that i
    > > have in the BS2.
    > >
    > > '{$STAMP BS2}
    > > output 1
    > > tal var word
    > > x var word
    > >
    > >
    > > Main:
    > > serin 16,16468,[noparse][[/noparse]wait (255),tal]
    > >
    > > low 4
    > > for x = 1 to 100
    > > pulsout 1,tal
    > > pause 10
    > > next
    > > high 4
    > > serout 16,16780,[noparse][[/noparse]X]
    > >
    > > goto main
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
Sign In or Register to comment.