Shop OBEX P1 Docs P2 Docs Learn Events
I need help with Basic stamp 2!! — Parallax Forums

I need help with Basic stamp 2!!

CheonCheon Posts: 8
edited 2011-02-01 16:48 in BASIC Stamp
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!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-31 08:27
    You need to provide more information. What carrier board? Which sensors? How did you connect everything? How are you powering it all? What happens? Schematics are helpful. Program source code is helpful (Use the Reply button and the paperclip attachment icon).
  • CheonCheon Posts: 8
    edited 2011-01-31 08:54
    I used Educational USB kit (#28803) and I used the ultrasonic sensors (#28015), and I am powering it by 7.5 VDC 1 amp Power Supply (#750-00009),and I connected the ultrasonic sensors, how they do in the manuals, and then I tried to connect another one just like the original one, and it didn't work....
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-31 09:06
    Like I said, you need to provide details. How did you actually connect the sensor? Sure, the manual explains it, but how did you do it? How did you connect a second PING? How did you connect the 3rd and 4th PING? It's not helpful to just provide a link to Parallax's documentation. We know those diagrams and explanations work. What did you actually do?

    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.
  • CheonCheon Posts: 8
    edited 2011-01-31 15:27
    I am trying to connect 4 ultrasonic sensors to the Educational board, and I don't know how to program it for 4 sensors. I am using 2.5 Basic Stamp Editor, and using PBASIC language. I only know how to program one sensors, and I have no clue to connect four sensors, and have them work at same time.
    Ultrasonic Sensors (#28015),
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-31 15:56
    First define what you want ... How do you want the sensors to behave? Why do you need four? Physically how do you have them mounted or where do you plan to mount them? Remember that you can only trigger them one at a time with short pauses in between or the sound pulses will interfere with each other. How do you plan to connect them? Each sensor needs power and a separate control line.

    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?
  • CheonCheon Posts: 8
    edited 2011-01-31 16:16
    Ok, so I have mounted the 4 ultrasonic sensors to detect the object for parking...
    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
  • RavenkallenRavenkallen Posts: 1,057
    edited 2011-01-31 16:47
    What do you mean by "make the sound"? Do you really need four sensors for your application? Did you physically move the PING)))'s to a different location? As Mike said, you will only be able to fire off one sensor at a time because the signals will interfere with each other. Try inserting a pause command right before the triggering of the next sensor..Like before every subroutine call.
  • CheonCheon Posts: 8
    edited 2011-01-31 17:19
    Yeah I put the pauses between but it doesn't work...
    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???
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-31 17:33
    Each call to Calc_Distance has to be followed by its own IF inDistance < doorJamb.

    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.
  • CheonCheon Posts: 8
    edited 2011-01-31 18:14
    ' {$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
    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....
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-31 18:29
    I don't understand why you put the single quotes around the IF and ENDIF statements.

    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.
  • CheonCheon Posts: 8
    edited 2011-01-31 18:37
    Because it wouldn't let me run the program it... they said I have to put ':' or something, and said IF cannot work without ENDIF...
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-31 19:10
    Like I said, you need to understand how the IF / THEN / ELSE / ENDIF statement works. Read the appropriate parts of the Manual and the What's a Microcontroller tutorial. If there's something in that that you don't understand after reading, do ask.
  • RavenkallenRavenkallen Posts: 1,057
    edited 2011-02-01 11:22
    You did make sure that every sensor works by itself first, right? I think you are getting to far ahead of yourself. Do you have a picture of your setup?
  • vaclav_salvaclav_sal Posts: 451
    edited 2011-02-01 16:48
    After you get better understanding of IF / THEN... command study subroutine. Your code will became more efficient and easier to modify if you add another level(s) of subrutines. For example if you had your code in subroutines you may see that your are using only one inDistance1 variable and testing for all four of them! Also learn how to use DEBUG to trace progress of you code.
    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.
Sign In or Register to comment.