NEED help in writing some code for a ping sensor that use the POLLIN comand
sam_sam_sam
Posts: 2,286
"···········THESE GUYS HAVE GONE MAD "·······························
···················"·THEY NEED HELP BAD"
······I would like to use 4 ping sensors on bs2p.
···· I would like do same thing with this program dose.
But·I want·to·use 4·ping sensors and have the output come·ON·by any one of the sensors
·How would·I use the POLLIN command or can·I· use the POLLIN command
CAN ANY ONE HELP ME·with this·
I have not used a·bs2p before.
I have used a bs2.
I am reading the reference manual 2.1
pollin
pollmode
pollout
pollrun
pollwait
····
· Thanks for any help that you give me···.
······················ samsam
Post Edited (sam_sam_sam) : 6/16/2005 11:38:47 PM GMT
···················"·THEY NEED HELP BAD"
······I would like to use 4 ping sensors on bs2p.
···· I would like do same thing with this program dose.
But·I want·to·use 4·ping sensors and have the output come·ON·by any one of the sensors
·How would·I use the POLLIN command or can·I· use the POLLIN command
CAN ANY ONE HELP ME·with this·
I have not used a·bs2p before.
I have used a bs2.
I am reading the reference manual 2.1
pollin
pollmode
pollout
pollrun
pollwait
····
· Thanks for any help that you give me···.
······················ samsam
Post Edited (sam_sam_sam) : 6/16/2005 11:38:47 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
············ ·THESE··THESE GUY HAVE GONE MAD················
························· THEY NEED HELP
·Jon·(or any one else)·will this work the way i have it here
I am going to buy a bs2p very soon i do not have one yet···········
I thank·you for your help in this matter
samsam
' {$STAMP BS2p}
' {$PBASIC 2.5}
#SELECT $STAMP
#CASE BS2SX, BS2P
Trigger···············CON············· 13
Scale················ CON··········· $0CD················ ' raw x 0.80 = uS
#ENDSELECT
RawToIn············· CON·········· $0379·············· ' 1 / 73.746
'
[noparse][[/noparse] Variables ]
time_1···· VAR····· ·Word···································
time_2···· VAR····· ·Word···································'
time_3···· VAR····· ·Word
time_4··· ·VAR··· ·· Word········ 'I am not sure where to put this in code
ping········VAR····· ·Word·········' or if this right·
rawDist···· ·VAR··· ·Word······························ ' raw measurement
inches······ ·VAR··· ·Word
Reset:
DEBUG CLS,··············································· ' setup report screen
"Parallax Ping Sonar", CR,
"
", CR,
CR,
"Time (uS)..... ", CR,
"Inches........ ", CR,
pulsout 15, 5
pulsin 15, 1, time_1············ 'I am not sure where to this put in code
pasue 1000
······································ ·' or if this right
pulsout 14, 5
pulsin 14, 1, time_2
pasue 1000
pulsout 13, 5
pulsin 13, 1, time_3
pasue 1000
pulsout 12, 5
pulsin 12, 1, time_4
pasue 1000
Main:
··············································
DO
POLLIN time_1, 4
POLLIN time_2, 4
POLLIN time_3, 4·······················'I am not sure where to this put in code
POLLIN time_4, 4·······················' or if this right
POLLOUT ping, 3
GOSUB Get_Sonar··································· ' get sensor value
inches = rawDist ** RawToIn···················· ' convert to inches
DEBUG CRSRXY, 15, 3,·······························' update report screen
DEC rawDist, CLREOL
DEBUG CRSRXY, 15, 4,
DEC inches, CLREOL
'Light LED OUTPUT
IF inches > 10 THEN LOW 2
IF inches < 12 THEN HIGH 2
PAUSE 100
LOOP
END
END
'
[noparse][[/noparse] Subroutines ]
Get_Sonar:
Ping = 0········································ ·· ' make trigger 0-1-0
PULSOUT Ping, Trigger······················· ·' activate sensor
PULSIN Ping, 1, rawDist······················ ·' measure echo pulse
rawDist = rawDist */ Scale·················· ' convert to uS
rawDist = rawDist / 2···························' remove return trip
RETURN
···································
Post Edited (sam_sam_sam) : 6/17/2005 4:35:01 AM GMT
Get_Sonar:
· pingPin·= 0·······················' make trigger 0-1-0
· PULSOUT pingPin, Trigger··········' activate sensor
· PULSIN pingPin, 1, rawDist········' measure echo pulse
· rawDist = rawDist */ Scale········' convert to uS
· rawDist = rawDist / 2·············' remove return trip
· RETURN
From your code, you could loop through an array of sensors like this:
Main:
· FOR idx = 0 TO 3
··· pingPin = idx + 12··············'·Pings on P12..P15
··· GOSUB Get_Sonar
··· distance(idx) = rawDist
· NEXT
POLLIN will not serve you here; you can forget about it completely for this application.· And please ... no more jumping icons (those things give me a headache!).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I want to have an output be ON If one or more PING))) Sensor has an object in front of it
and be able to measure it that is why i was using pollin command but if what you said will
work ok but i want to use something like this.......
IF inches >10 THENLOW2
IF inches >12 THENLOW2
for any Ping))) sensor.
I also want to know which sensor is triggered and display it on a LCD DISPLAY.
DO I need more than one subroutine if any one sensor is triggered.
Is the code for each sensor
ping_1 pin 12
ping_2 pin 13
and so on
Do I need write same code for each sensor
Main:
FOR idx = 0 TO 3
"pingPin = idx + 12 " ' Pings on P12..P15 ????
"What dose this do i was looking for this in the
online help but i heve not found it yet" >
GOSUB Get_Sonar
distance(idx) = rawDist
NEXT
I want to THANK YOU for your help in this matter.
I will try not to give you a headache with this but
I am tring to learn how to write my own but it is hard to teach an old dog new trick
thanks samsam
Post Edited (sam_sam_sam) : 6/18/2005 2:41:10 AM GMT
A couple things...
1) You don't want to trigger multiple sensors at the same time; echoes bouncing around from one sensor could foul the readings of another.· Read them one at a time as I showed you.
2) If your outputs are all in a row, then you can modify the main code like this to control them as you wish:
Main:
· FOR idx = 0 TO 3
··· pingPin = idx + 12··············'·Ping sensor attached to P12..P15
··· GOSUB Get_Sonar
··· distance(idx) = rawDist */ RawToIn
··· IF (distance(idx)·< 12) THEN
····· LOW (idx + 8)················ ' LEDs on P8..P11
··· ELSE
····· HIGH (idx + 8)
··· ENDIF
· NEXT
Now the code converts the distance to inches (and saves it in an array), then compares that to 12.· The way the loop works if the Ping connected to P12 measures a distance less than 12, it sets P8 low.· The control works like this:
Ping on P12 controls LED on P8
Ping on P13 controls LED on P9
Ping on P14 controls LED on P10
Ping on P15 controls LED on P11
3) You didn't say what kind of LCD you're using (that detail matters).· Again, learn how to use the LCD you have separately, then incorporate it into your Ping))) program.
4) Finally, you might consider working through our "What's A Microcontroller?" text -- it's a great foundation to BASIC Stamp programming.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
' {$STAMP BS2}
' {$PBASIC 2.5}
ping······ PIN····· 12
#SELECT $stamp
· #CASE BS2
· trigger·· CON·· 5
· scale···· CON·· $200
#ENDSELECT
rawtoin··· CON··· 889
rawdist··· VAR··· Word
idx······· VAR··· Word
distance·· VAR··· Word
pingpin·· VAR··· Byte
Get_Sonar:
· pingPin = 0······································ ' make trigger 0-1-0
· PULSOUT pingPin, Trigger················· · ' activate sensor
· PULSIN pingPin, 1, rawDist················· ·' measure echo pulse
· rawDist = rawDist */ Scale················ ·' convert to uS
· rawDist = rawDist / 2······················ · ' remove return trip
· RETURN
Main:·················································' Ping sensor attached to P12
· FOR idx = 0 TO 3····························· ·' Ping sensor attached to P13
··· pingPin = idx + 12·························· ·' Ping sensor attached to P14
··· GOSUB Get_Sonar·························· ·' Ping sensor attached to P15
··· distance(idx) = rawDist */ RawToIn
··· IF (distance(idx) < 12) THEN
····· LOW (idx + 8)
··· ELSE····························· ·'Ping on P12 controls LED on P8
···· HIGH (idx + 8)················· 'Ping on P13 controls LED on P9
········································· 'Ping on P14 controls LED on P10
········································ ·'Ping on P15 controls LED on P11
··· ENDIF
· NEXT
I want to THANK YOU for your help in this matter.
samsam
I want to do is turn on·the backlight· when there is something in
front of the ping sensor so·I can see·lcd display·it in the dark··but when there is·nothing there the backlight is off
·" Finally, you might consider working through our "What's A Microcontroller?" text -- it's a great foundation to BASIC Stamp programming."
I· have· done·the "What's A Microcontroller text·and it's a great foundation·.
How to write code for·more than one PING )))sensor·and to use·"·IDX·+12 "to write code for·more··than one sensor
it is not cover iin the text·I am glad that you are willing to help the one like me·who are having a hard time understanding thing like this I DO WANT TO THANK YOU FOR THIS·.I also like reading "NUT & VOLTS I ENJOY IT!!!!!
····················································································································································································································································································································································································You
THANK YOU FOR ALL YOUR HELP IN THIS MATTER
······· samsam
·
You are dropping through a RETURN statement that was never set by a GOSUB.
This occurs right in the beginning of your program:
Get_Sonar:
pingPin = 0 ' make trigger 0-1-0
PULSOUT pingPin, Trigger ' activate sensor
PULSIN pingPin, 1, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN <<== ** ERROR **
Regards,
Bruce Bates
·· Your subroutine needs to come after the Main routine, and the Main routine will need an END statement to keen the main routine from falling back through into it again after it's finished.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
' {$STAMP BS2}
' {$PBASIC 2.5}
ping······ PIN····· 12
ping_1···· PIN····· 13
#SELECT $stamp
· #CASE BS2
· trigger·· CON·· 5
· scale···· CON·· $200
#ENDSELECT
rawtoin···· CON··· 889
IsHIGH······ CON· 1
IsLow······· CON· 0
rawdist··· VAR··· Word
distance·· VAR··· Word
idx······· VAR··· Nib
pingpin··· VAR··· Word
· ' Ping ON P13 controls LED ON P15
Main:
· DO
· FOR idx = 0 TO 1······················ ' Ping sensor attached to P12
··· pingpin = idx + 12·················· ' Ping sensor attached to P13
··· GOSUB Get_Sonar
··· distance(idx) = rawDist */ RawToIn
····· DEBUG CRSRXY, 15, 3,
········· DEC rawDist, CLREOL,··········'
········· CRSRXY, 15, 4,
········· DEC· distance, CLREOL
··· IF (distance(idx) < 5000) THEN ledlight
··' Ping ON P12 controls LED ON P14
·' Ping ON P13 controls LED ON P15
··· NEXT
· IF (distance(idx) > 1000) THEN time
······ LOOP
· Get_Sonar:
· ping = 0······························ ' make trigger 0-1-0
· PULSOUT pingpin, Trigger·············· ' activate sensor
· PULSIN pingpin, 1, rawDist············ ' measure echo pulse
· rawDist = rawDist */ Scale············ ' convert to uS
· rawDist = rawDist / 2················· ' remove return trip
·RETURN
···· ledlight:
· HIGH·(idx + 14)
· GOTO time
···· ledoff:
· LOW·(idx + 14)
·GOTO main
·time:
PAUSE 2000
GOTO· ledoff
Can you tell me why this code will not work the way it writen
' {$STAMP BS2}
' {$PBASIC 2.5}
ping······ PIN····· 12
#SELECT $stamp
· #CASE BS2
· trigger·· CON·· 5
· scale···· CON·· $200
#ENDSELECT
rawtoin··· CON··· 889
IsHigh···· CON···· 1······················ ' for PULSOUT
IsLow····· CON···· 0
rawdist··· VAR··· Word
idx······· VAR····· nib
distance·· VAR··· Word
pingpin··· VAR··· word
·Main:········································ ' Ping sensor attached to P12
· FOR idx = 0 TO 1···························· ' Ping sensor attached to P13
··· pingPin = idx + 12
··· GOSUB Get_Sonar
··· distance(idx) = rawDist */ RawToIn
··· IF (distance(idx) < 5000) THEN
····· LOW (idx + 14)
··· ELSE
···· HIGH (idx + 14)
···································· 'Ping on P12 controls LED on P14
···································· 'Ping on P13 controls LED on P15
··· ENDIF
· NEXT
· Get_Sonar:
· pingPin = 0································ ' make trigger 0-1-0
· PULSOUT pingPin, Trigger··················· ' activate sensor
· PULSIN pingPin, 1, rawDist················· ' measure echo pulse
· rawDist = rawDist */ Scale················· ' convert to uS
· rawDist = rawDist / 2······················ ' remove return trip
· RETURN
I would like to THANK EVERYONE who has help me in this matter· THANK YOU ........
samsam
Post Edited (sam_sam_sam) : 7/17/2005 1:14:01 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I would like to make an out put go on and off
using this
IF (distance(idx) < 5000) to turn on·
and use the··COUNT command·(" event-based program deay·") used in Stamp Works ver.1.2
pages 105 to 107 exeperiment #16 counting events
IF (distance(idx) > 1000) to turn·· off
Would this work and how would·I write it
Thank You for any help in this matter
samsam
·