Shop OBEX P1 Docs P2 Docs Learn Events
still need some help BS1 and servo! — Parallax Forums

still need some help BS1 and servo!

studiomagic1studiomagic1 Posts: 25
edited 2009-06-14 03:29 in BASIC Stamp
I still need some help. I can read the pot on my BS1 reading (95 - 255) now I need to understand how to use this information into moving the servo to ehco the pot movement. I'm not understanding all the reading and it's·very vauge for an old man. Please some help! I was told that the forum was the place to get expert help.·I have used the BS2 to move a servo. This is my first try at using the pot and BS1.sad.gif Thanks,
«1

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-06-05 03:34
    The values you get from the pot need to be scaled to the values you need for the servo. If 95 is full left and 255 is full right (180 deg) then the pulses for the servo for 180 deg need to be devided by 160 to scale. this is just an overview and I didn't look anything up but this should get you started.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-05 03:40
    Franklin,

    I don't know how to start the code. On the BS2 they give you a example code and from that I played with it and got my old BS2 to work a servo using a push button. Why doesn't anyone from the forum like to help someone start or show me what the code should look like? I'm just puzzled!
  • FranklinFranklin Posts: 4,747
    edited 2009-06-05 03:51
    Part of your problem is your attitude. Putting the people on the forum down as unhelpful will not win you friends (or get you help)

    If you have been able to get the POT command to give you numbers when you turn the pot and have been able to get the stamp to move the servo from one side to the other of it's travel you have most of the programming done. you just need to combine the two parts. Show us what you have and maybe we can show you how to make it work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-05 04:05
    studiomagic1 said...
    Why doesn't anyone from the forum like to help someone start or show me what the code should look like? I'm just puzzled!

    Mike Green suggested you look at Basic Stamp application notes, he even provided a link. In less than one minute I found this on page 86 of this PDF


    servo: 
    
    pulsout 0,150
    pause 20
    goto servo
    
    



    Below is the reply I was working on before I refreshed the page and saw your response. It wasn't done yet, I was going to alter it a bit to better fit the BS1, using 10 uS increments. I'm stopping for now because I looked up the other thread where others were trying to lead you to the answer yet you don't seem to consider anyone from the forum helpful...

    I said...

    Hmmm, ok. First, I have never used a BS1 so I apologize if what I'm going to say is what you already know.

    You have values of 95 - 255 and you want to scale those values to something the servo can use.

    First decide the maximum amount you want the servo to move. Center for most servos is a pulse of 1.5 mS. Futaba uses 1.52 mS but you can ignore that and use 1.5 mS anyway. Travel limits can span a range of .5 mS up to 2.5 mS though you will most likely run up against one or both of the stops if you use such values. A safe bet is to go .5 mS either way from center so that means 1.0 mS to 2.0 mS. Convert to microseconds and we get 1000 uS to 2000 uS.

    In your case the center is 175 and it varies 80 each way. 500 uS / 80 = 6.25 us steps.

    So,
    95 = 1000 uS
    175 = 1500 uS
    255 = 2000 uS

    Now you need an equation.

    First I would off set the pot readings so that we are working from zero.

    Value1 = pot - 95

    Now we have this,

    0 = 1000 uS
    80 = 1500 uS
    160 = 2000 uS

    We already know that one pot unit is equal to 6.25 uS so...

    PulseWidth = pot * 6.25 + 1000

    Combine that with the pot offset,

    PulseWidth = (pot - 95) * 6.25 + 1000

    Rich H
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-05 04:23
    I'm not trying to have a attitude. I'm lost in this whole project i'm trying. I've post a few times I'm told go look at this link. I go to the link and I don't understand the whole thing I did try the pot test in the editor. I can read the pot using the simple code and I see the numbers. I have not got the servo to move using this BS1 yet. I did try the code Mike provided didn't move the servo but 1/8 inch. Icould never get it to move left or right changing numbers. I worked on a project a couple years back with the BS2 and push buttons to move the servos I can't remember having this much trouble. Most people here in this forum have either study this in high school or collage. I have done neither. Almost all my use has been BS2 High and low on pins to triger relays. Maybe I could just ask someone here to just write me what I need so I't would be less trouble and maybe help someone else that may have the same problems.

    Sincerely,
    Jim
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-05 04:59
    Even though your code is not doing what you want, you should post it so that we can see exactly what your having trouble with. Actually it's kinda dumb to say that... code not doing what you want is a primary reason for posting it!

    Rich H
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-05 05:10
    Thanks Rich for helping me. I wished Iknew this and was helping someone else but that not the case. Here's what i'm trying right now.

    This will move the servo counterclockwise all the way.
    SERVO:
    PULSOUT 1, 690
    PAUSE 20
    GOTO SERVO



    I have used the code counter in the BS2. I kind of know what to do. This was some of my old code for BS2 i use but it don't work with the BS1
    ' {$STAMP BS1}
    ' {$PBASIC 2.5}

    counter VAR Word


    FOR counter = 1 TO 20
    PULSOUT 13, 690
    PAUSE 5
    PULSOUT 12, 415
    PAUSE 5
    NEXT
    GOTO Main:

    Main:
    DO

    IF IN2 = 1 THEN
    GOTO Blink1:
    ENDIF

    IF IN4 = 1 THEN
    GOTO Blink2:
    ENDIF

    IF IN1 = 1 THEN
    GOTO Blink3:
    ENDIF


    LOOP

    ' ' '' ' '' ' 'pushbutton ' ' '' ' '' ' '' ' '

    Blink2:


    FOR counter = 1 TO 10
    PULSOUT 13, 690
    PAUSE 15
    PULSOUT 12, 415
    PAUSE 15
    NEXT


    FOR counter = 1 TO 15
    PULSOUT 13, 300
    PAUSE 14
    PULSOUT 12, 840
    PAUSE 14
    NEXT
    GOTO Main:
    can make the servo work in BS2 using this
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-05 05:42
    Again, I have never used a BS1 so my code syntax is suspect.

    Try this, you'll need to add in the code for reading the pot.

    SERVO
    GOSUB READPOT
    PULSOUT 1, POT - 25 ..... was PULSOUT 1, (POT - 95) + 70
    PAUSE 20
    GOTO Servo

    Where pot is the value you get from the potentiometer which is expected to be between 95 and 255.

    Below is the explanation based upon needing to scale the reading from the pot but it turns out that is not necessary. The explanation still stands but for the code, no need to make it more complex. (pot-95) + 70 is exactly the same as pot - 25.

    The theory is that you offset the pot readings to zero, that's why you subtract 95. Now the offsetted readings will be 0 to 160. The center being 80.

    So now if the pot is centered and you add 80 you get 150. Which for the BS1 equates to 1500 uS, or the standard "center" pulsewidth for servos.

    If the pot is full left the offsetted reading will be zero. add 70 and you get ... 70! Which for the BS1 is 700 uS.
    If the pot is full right the offsetted reading will be 160. Add 70 and you get 230, or 2300 uS in BS1 talk.

    uS meaning microseconds, millionths of a second.

    Rich H

    Post Edited (W9GFO) : 6/5/2009 5:57:45 AM GMT
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-05 06:03
    Rich,

    Didn't work. I get a error saying the it's (missing constant or variable). I don't think I would be have this much trouble if I had just got the BS2. Thanks Rich for all your help and I do mean that. I wasn't trying to knock anyone here but I was getting upset with my lack of knowledge and was just looking forsome at this point to pay the write it for me.
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-05 06:12
    studiomagic1 said...
    Rich,

    Didn't work. I get a error saying the it's (missing constant or variable).

    It is at this very point where you should post the code that you tried to run in it's entirety. What I posted certainly was not complete - more like something that you add to the code you already had working that read the potentiometer.

    In fact, post the code that worked with the pot AND post the code that you just tried and didn't work.

    Rich H
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-05 06:25
    My 9volt has drained. I think I'm going to call in a night!

    Thanks, Jim
  • FranklinFranklin Posts: 4,747
    edited 2009-06-05 15:54
    Click on Post Reply and scroll down to the Attachment Manager. point it to the file you have been trying to run and ATTACH it to your next post, please. Also a 9v battery is not a good power source when trying to work with servos, get a 6 or 7.5v wall wart.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Shawn LoweShawn Lowe Posts: 635
    edited 2009-06-05 18:35
    StudioMagic-
    Did you try EFX-TEK's documents like I posted in your last post? Jon Williams did a good PDF for getting people up to speed on the BS1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • JDJD Posts: 570
    edited 2009-06-05 18:39
    Jim,

    Here is a quick and dirty sample for the BS1 that should get you started. It's not the cleanest by far, and cuts the resolution of the POT, but again should give you something to show the relation of the POT value and the PULSE value·given to the servo.

    I hope this helps,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • JDJD Posts: 570
    edited 2009-06-05 20:40
    Jim,

    Here is one that has a bit cleaner scaling operation sample; this will help you use the entire range of the POT. Here is also the theory of how the scale operation is equated.

    1)·We’ve got an input and an output.

    2) Our input is a number from 0 to 255 (which is a delta of 255)

    3) Our output is a number from 100 to 200 (which is a delta of 100)

    4) We need to determine a scale factor to translate our input to our output.· To do that you divide your input delta by your output delta:· 255 / 100 = 2.55.

    5) Now we have two things to do, we need to apply our scale factor to our input (which will give us a number from 0 to 100), and then we need to adjust our output upward since the low (100) of its range in higher than zero (0).· So the mathematical equation becomes:· input / scale_factor + offset = output.· Our offset is 100 because we want the low point of our output to be 100 instead of 0.

    6) Now, the BASIC Stamp can do 16-bit integer math only (no fractions), so we can’t just divide a number by 2.55 (our scale factor), but, it is 16-bit math… if our input is in a low-enough range, we can scale both it and our scale factor so that both are integer values and, thus, we’re dividing by an integer.· Since our max input (255) times 100 equals 25,500, and that is less than 64K (65,535) it will fit in 16-bits.· Yea!


    I hope this helps,


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-05 23:25
    I'd like to understand why the above is necessary. He said that his input was 95 - 255. Simply subtracting 25 from that appears to me to work quite nicely, allowing full resolution available - a delta of 160.

    95 - 25 = 70 ( 700 mS )
    175 - 25 = 150 ( 1.500 mS)
    255 - 25 = 230 ( 2.300 mS )

    All very useable pulsewidths, no scaling necessary.

    What am I missing?

    Rich H
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-06 14:30
    Thanks Jouhsa and Rich for explaning this I'll try it!
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-06 15:05
    Here's what I've come up with so far. Servo 1 works great with the pot command now thanks to you guys. I tried to work in a new code for the second servo that will work from a push button. it will just move the servo clockwise then back to center. Please look at it I'm missing something.
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-06 15:32
    studiomagic1 said...
    Here's what I've come up with so far. Servo 1 works great with the pot command now thanks to you guys. I tried to work in a new code for the second servo that will work from a push button. it will just move the servo clockwise then back to center. Please look at it I'm missing something.

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    
    SYMBOL  scale     = 85
    SYMBOL  Potpin    = 0
    SYMBOL  servopin  = 1
    SYMBOL  level     = B2
    SYMBOL  pulse     = B3
    
    
    
    Main2:
    DO
    IF IN4 = 1 THEN
    GOTO SERVO2:
    ENDIF
    LOOP
    
    Main:
    
      POT Potpin, scale, level
      pulse = level MIN 100 MAX 250
      GOTO Servo:
    
    Servo:
      PULSOUT servopin, pulse
      PAUSE 10
      GOTO Main
    
    SERVO2:
    FOR counter = 1 TO 10
    PULSOUT 4, 690
     PAUSE 15
     NEXT
    FOR counter = 1 TO 15
     PULSOUT 4, 300
     PAUSE 14
    NEXT
    GOTO Main2
    
    



    According to what I read the BS1 PULSOUT command works with 10 uS increments. A value of 690 would then be equal to 6900 uS. That is more than double what a high value should be. Even the 300 is high - that would be 3000 uS. Normal range for a servo is more like 1000 uS to 2000 uS. A little more each way if you want maximum travel - maybe 500 uS to 2500 uS.

    Also, be sure to allow the 'FOR counter = 1 to 10" loop enough times through for the servo to reach it's destination. Ten times through, taking about 20 mS each time is only 200 mS - 1/5 th of a second.

    Lastly, someone commented that the BS1 does not support "DO...LOOP". Might want to check that.

    RIch H
  • Shawn LoweShawn Lowe Posts: 635
    edited 2009-06-06 16:18
    Yes, sorry when I posted that Do..Loop probably doesn't work with a BS1. I was at work and couldn't confirm. I have now confirmed in the HELP file, DO..Loop DOES NOT work with the BS1. In fact your program won't compile StudioMagic. It says missing Label after DO, because it isn't supported.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-06 23:21
    I'm missing or have part of code wrong!
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-07 01:51
    studiomagic1 said...
    I'm missing or have part of code wrong!

    I made some changes that made sense to me, I have no way to test...

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    
    SYMBOL  scale     = 85
    SYMBOL  Potpin    = 0
    SYMBOL  servopin  = 1
    SYMBOL  level     = B2
    SYMBOL  pulse     = B3
    SYMBOL  counter   = B1
    
    
    Main:
    
      IF IN4 = 1 THEN
      GOTO Servo2
      ENDIF
    
      POT Potpin, scale, level
      pulse = level MIN 75 MAX 230
    
      GOTO Servo:
    
    Servo:
    
      PULSOUT servopin, pulse
      PAUSE 18
    
      GOTO Main
    
    Servo2:
    
      FOR counter = 1 TO 15
      PULSOUT 4, 100
      PAUSE 20
      NEXT
    
      FOR counter = 1 TO 30
      PULSOUT 4, 200
      PAUSE 20
      NEXT
    
      FOR counter = 1 TO 15
      PULSOUT 4, 150                    ' leave servo centered
      PAUSE 20
      NEXT
    
      GOTO Main
    



    Rich H

    Post Edited (W9GFO) : 6/7/2009 9:29:26 PM GMT
  • JDJD Posts: 570
    edited 2009-06-08 15:41
    Rich,

    The BS1 doesn't support DO...LOOP; that is a PBASIC 2.5 command and the BS1·supports PBASIC 1.0; which is why you see the GOTO command instead of DO...LOOP. You are correct for pulses; the BS1 PULSOUT command should be in the neighborhood of 100 to 200 which would give the 1 to 2 ms pulse.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • Shawn LoweShawn Lowe Posts: 635
    edited 2009-06-08 15:57
    I think you could simplify the program to this:

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    
    SYMBOL  scale     = 85
    SYMBOL  Potpin    = 0
    SYMBOL  servopin  = 1
    SYMBOL  level     = B2
    SYMBOL  pulse     = B3
    SYMBOL  counter   = B1
    
    
    Main:
    
      IF IN4 = 1 THEN
      GOTO Servo2
      ENDIF
    
      POT Potpin, scale, level
      pulse = level MIN 75 MAX 230
      PULSOUT servopin, pulse
      PAUSE 18
    
      GOTO Main
    
    Servo2:
    
      FOR counter = 1 TO 15
      PULSOUT 4, 100
      PAUSE 20
      NEXT
    
      FOR counter = 1 TO 30
      PULSOUT 4, 200
      PAUSE 20
      NEXT
    
      FOR counter = 1 TO 15
      PULSOUT 4, 150                    ' leave servo centered
      PAUSE 20
      NEXT
    
      GOTO Main
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-08 17:11
    This code is giving me a error saying I have a Undefined Sysmbol? Joshua can you confim this code and tell me why servo2 is not working?

    Shawn thanks for helping me!

    - Jim


    ' {$STAMP BS1}
    ' {$PBASIC 1.0}


    SYMBOL· scale···· = 85
    SYMBOL· Potpin··· = 0
    SYMBOL· servopin· = 1
    SYMBOL· level···· = B2
    SYMBOL· pulse···· = B3
    SYMBOL· counter·· = B1

    Main:
    · IF IN4 = 1 THEN····error here says (Undefined symbol)
    · GOTO Servo2
    · ENDIF
    · POT Potpin, scale, level
    · pulse = level MIN 75 MAX 230
    · PULSOUT servopin, pulse
    · PAUSE 18
    · GOTO Main
    Servo2:
    · FOR counter = 1 TO 15
    · PULSOUT 4, 100
    · PAUSE 20
    · NEXT
    · FOR counter = 1 TO 30
    · PULSOUT 4, 200
    · PAUSE 20
    · NEXT
    · FOR counter = 1 TO 15
    · PULSOUT 4, 150··················· ' leave servo centered
    · PAUSE 20
    · NEXT
    · GOTO Main
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-08 17:25
    Try this:
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    
    SYMBOL  scale     = 85
    SYMBOL  Potpin    = 0
    SYMBOL  servopin  = 1
    SYMBOL  level     = B2
    SYMBOL  pulse     = B3
    SYMBOL  counter   = B4
    SYMBOL  main2pin  = 1
    
    
    
    
    
    
    Main:
    
      IF PIN3 = 1 THEN Servo2
      
      POT Potpin, scale, level
      pulse = level MIN 50 MAX 250
      GOTO Servo:
    
    Servo:
      PULSOUT servopin, pulse
      PAUSE 10
      GOTO Main
    
    
    Servo2:
      FOR counter = 1 TO 15
      PULSOUT 4, 100
      PAUSE 20
      NEXT
      FOR counter = 1 TO 30
      PULSOUT 4, 200
      PAUSE 20
      NEXT
      FOR counter = 1 TO 15
      PULSOUT 4, 150                    ' leave servo centered
      PAUSE 20
      NEXT
      GOTO Main
    


    Rich H

    Post Edited (W9GFO) : 6/8/2009 6:00:10 PM GMT
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-08 17:35
    I'm using Pin3 on the push button for servo2 which is connected to pin4. I just corrected that but still getting the error. I beleive I'm missing something at the top of the code where the SYNBOL stuff is?
  • studiomagic1studiomagic1 Posts: 25
    edited 2009-06-08 17:47
    Here what I've got uptill now. The servo using the pot connamd works great. I tried a couple thing with no luck. Here's what I've got!
  • JDJD Posts: 570
    edited 2009-06-08 17:56
    Jim,

    Instead of IN3 for watching an INPUT, you would want to use PIN3.

    For Example:

    IF PIN3 = 1 THEN Servo2

    However, in the program its going to Servo2 regardless if the button is pressed or not because after your IF...THEN statement, there is a GOTO Servo2; did you mean for that? Also, did you get the scaling program to work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-08 17:58
    I've updated my post above, try that.

    Rich H
Sign In or Register to comment.