still need some help BS1 and servo!
studiomagic1
Posts: 25
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. Thanks,
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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!
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
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
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...
Rich H
Sincerely,
Jim
Rich H
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
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
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.
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
Thanks, Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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!
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
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
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
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 Lowe
When all else fails.....procrastinate!
I made some changes that made sense to me, I have no way to test...
Rich H
Post Edited (W9GFO) : 6/7/2009 9:29:26 PM GMT
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 Lowe
When all else fails.....procrastinate!
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
Rich H
Post Edited (W9GFO) : 6/8/2009 6:00:10 PM GMT
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
Rich H