I need help with Basic stamp 2!!
Cheon
Posts: 8
I connected the ultrasonic sensor to the carrier board, and I programmed it, and it worked right...
But when I tried to plug all 4 sensors to the carrier board, then it didn't work..
So I went back and tried to connect just one sensor, then it doesn't work anymore...
By the way, I used PBASIC 2.5, Basic stamp 2, Basic, Stamp Editor...
I need help for how to make them work like they used to, and connect all 4 of them...
Thank you!
But when I tried to plug all 4 sensors to the carrier board, then it didn't work..
So I went back and tried to connect just one sensor, then it doesn't work anymore...
By the way, I used PBASIC 2.5, Basic stamp 2, Basic, Stamp Editor...
I need help for how to make them work like they used to, and connect all 4 of them...
Thank you!
Comments
The code I used was
' Smart Sensors and Applications - Ch2_Project2.bs2
' Make a sound when someone passes through the doorway.
Before, I actually connected the another sensor, it worked perfectly fine, but when I put one more sensor to it, the other sensor just didn't work, and when I tried to make the code and program to work again, and it messed up the original sensor that worked fine....
or http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/3rdPrintSmartSensors-v1.0.pdf
page 64.
Where do you have the PING power, ground and signal wires connected? If you've plugged the PINGs into the "servo" connectors on the Board of Education, how do you have the power jumper on the Board of Education connected? The jumper can provide power to the "servo" connectors from Vin (your 7.5V supply) or Vdd (the 5V regulator). You can damage or destroy the PINGs if the jumper is set to Vin.
Ultrasonic Sensors (#28015),
You will have to do the actual programming and the wiring. We can supply help ... help you understand how they work and how you might have more than one. Along those lines, do you understand how a single PING works with a Stamp? Have you read the documentation?
First of all, I have connected each sensors to P15, P14, P12, P1, and I wired them, and made them control different... I know how to work one sensor right, but when i try to make all four sensors work, I can't do it.... So far, I figured out how to power all four of them, but not know how to make them work..
I try to make the work on this way. And, when I do it this way, I can only make one sensor that makes the sound right, and others don't make the sound, but the power is on. Is there any way to make all four of them make the sound whichever it detects any object... I want all sensors to detect each object, and not just one which makes the sound...
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ I/O Definitions ]
Ping1 PIN 15 ' Parallax Ping))) sensor
Ping2 PIN 14 ' Parallax Ping))) sensor
Ping3 PIN 12 ' Parallax Ping))) sensor
Ping4 PIN 1 ' Parallax Ping))) sensor
Speaker PIN 0 ' Optional speaker
'
[ Constants ]
InConstant CON 890
Car CON 12 ' Car width is 12 inches
'
[ Variables ]
inDistance VAR Word
time VAR Word ' Round trip echo time
counter VAR Nib
'
[ Main Routine ]
DO
GOSUB Read_Ping1
GOSUB Calc_Distance
GOSUB Read_Ping2
GOSUB Calc_Distance
GOSUB Read_Ping3
GOSUB Calc_Distance
GOSUB Read_Ping4
GOSUB Calc_Distance
IF (inDistance < Doorjamb) THEN
GOSUB Sound_Alarm
ENDIF
LOOP
'
[ Subroutines ]
Read_Ping1:
PULSOUT 15, 5 ' Start Ping)))
PULSIN 15, 1, time ' Read echo time
RETURN
Read_Ping2:
PULSOUT 14, 5 ' Start Ping)))
PULSIN 14, 1, time ' Read echo time
RETURN
Read_Ping3:
PULSOUT 12, 5 ' Start Ping)))
PULSIN 12, 1, time ' Read echo time
RETURN
Read_Ping4:
PULSOUT 1, 5 ' Start Ping)))
PULSIN 1, 1, time ' Read echo time
RETURN
Sound_Alarm:
FREQOUT Speaker, 300, 3300 ' Bing
PAUSE 50
FREQOUT Speaker, 450, 2200 ' Bong
RETURN
Calc_Distance:
inDistance = inConstant ** time ' These are the whole measurements
RETURN
What I mean by making other sound is that, only one sensor gives off the sound whenever there are objects, and others don't even though there is pauses between, and I think it is because of bad programming which I have really hard time doing it...
Can you give me any answer toward my project???
The way you have it, when you call Calc_Distance, it calculates inDistance all over again for the last sensor, throwing away the previous inDistance value.
You could use a different inDistance variable for each PING. Call the first inDistance1, then inDistance2, inDistance3, etc.
Put a PAUSE 100 after Read_Ping1, Read_Ping2, etc. to allow the echoes from each PING to die down. After all four calls, you could do IF inDistance1 < doorJamb or inDistance2 < doorJamb or ... etc. for all 4 of them.
' {$PBASIC 2.5}
'
[ I/O Definitions ]
Ping1 PIN 15 ' Parallax Ping))) sensor
Ping2 PIN 14 ' Parallax Ping))) sensor
Ping3 PIN 12 ' Parallax Ping))) sensor
Ping4 PIN 1 ' Parallax Ping))) sensor
Speaker PIN 0 ' Optional speaker
'
[ Constants ]
InConstant CON 890
Doorjamb CON 12 ' Car width is 12 inches
'
[ Variables ]
inDistance1 VAR Word
inDistance2 VAR Word
inDistance3 VAR Word
inDistance4 VAR Word
time VAR Word ' Round trip echo time
counter VAR Nib
'
[ Main Routine ]
DO
GOSUB Read_Ping1
GOSUB Calc_Distance
'IF' (inDistance1 < Doorjamb) THEN
GOSUB Sound_Alarm
PAUSE 100
GOSUB Read_Ping2
GOSUB Calc_Distance
'IF' (inDistance2 < Doorjamb) THEN
GOSUB Sound_Alarm
PAUSE 100
GOSUB Read_Ping3
GOSUB Calc_Distance
'IF' (inDistance3 < Doorjamb) THEN
GOSUB Sound_Alarm
PAUSE 100
GOSUB Read_Ping4
GOSUB Calc_Distance
'IF' (inDistance4 < Doorjamb) THEN
GOSUB Sound_Alarm
PAUSE 100
'ENDIF'
LOOP
'
[ Subroutines ]
Read_Ping1:
PULSOUT 15, 5 ' Start Ping)))
PULSIN 15, 1, time ' Read echo time
RETURN
PAUSE 100
Read_Ping2:
PULSOUT 14, 5 ' Start Ping)))
PULSIN 14, 1, time ' Read echo time
PAUSE 100
RETURN
Read_Ping3:
PULSOUT 12, 5 ' Start Ping)))
PULSIN 12, 1, time ' Read echo time
PAUSE 100
RETURN
Read_Ping4:
PULSOUT 1, 5 ' Start Ping)))
PULSIN 1, 1, time ' Read echo time
PAUSE 100
RETURN
Sound_Alarm:
FREQOUT Speaker, 300, 3300 ' Bing
PAUSE 100
FREQOUT Speaker, 450, 2200 ' Bong
PAUSE 100
RETURN
Calc_Distance:
inDistance1 = inConstant ** time ' These are the whole measurements
PAUSE 100
RETURN
Is this what you meant by doing this???
Well I did it, and the ultrasonic sensors just make sounds going by each sensors even though there is not any object near it.... Each sensors just take turns and make the sounds... and I want them to make the sound when the object came toward them....
Please read the relevant chapter in the Stamp Manual on the IF statement and go through the "What's a Microcontroller?" tutorial. These can be downloaded from Parallax and I believe they're also included in the help files of the Stamp Editor. You need to learn how to properly use the IF statement.
You will be surprized that your code does not follow what you inteded.
But make first "sonar" to work first by itself.
Most of all, don’t be concerned that it does not work. Even the simplest code may not work at first. The key is – divide and step thru until you find the problem code.