Shop OBEX P1 Docs P2 Docs Learn Events
I cant get the led's to flash on my boe-bot — Parallax Forums

I cant get the led's to flash on my boe-bot

walice_drelwalice_drel Posts: 81
edited 2007-08-09 06:06 in BASIC Stamp
I set up my boe-bot just like it was pictured in the manual for roaming, everything works correctly but the led's wont flash. Here is the code I used.


'
[noparse][[/noparse] Title ]
' Robotics with the Boe-Bot - RoamingWithIr.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.

' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.

'
[noparse][[/noparse] Variables ]
counter VAR Nib
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseCount VAR Byte

'
[noparse][[/noparse] Initialization ]

FREQOUT 4, 2000, 3000 ' Signal program start/reset.

'
[noparse][[/noparse] Main Routine ]

DO

FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.

FREQOUT 2, 1, 38500
irDetectRight = IN0

IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both IR pairs detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both IR pairs 1, no detects
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again

LOOP

'
[noparse][[/noparse] Subroutines ]

IF (IN0 = 0) OR (IN9 = 0) THEN
FOR counter = 1 TO 5
HIGH 1
HIGH 10
FREQOUT 6, 200, 4000
LOW 1
LOW 10
PAUSE 20
NEXT
ENDIF
RETURN
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN

Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN

Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN



Can someone please tell me what I am doing wrong.

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2007-08-09 03:13
    Ah, which LEDs are you talking about? The IR LEDs only put out infra-red light which is not visible to the human eye. If everything works except you can't see the IR LEDs flash, then everything is okay.

    It's been a while since I did the BoE-bot experiments, but I seem to remember a set-up that had normal LEDs that indicated whether a high or low signal was being received from the IR detectors. If this is what you're talking about, then check that the LEDs are in the right way, if they're wired in backwards they don't light up.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • walice_drelwalice_drel Posts: 81
    edited 2007-08-09 03:17
    I'm not that new...lol The red led's . I am not sure if I wired them wrong or if this code is missing something.
  • FranklinFranklin Posts: 4,747
    edited 2007-08-09 04:38
    Try writing a simple program that just pulls the pin high waits 1 second then pulls it low and waits another second then repeats. If the leds dont flash reverse them and try again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • walice_drelwalice_drel Posts: 81
    edited 2007-08-09 05:13
    Here is the code and wiring i am using.


    '
    [noparse][[/noparse] Title ]
    ' Robotics with the Boe-Bot - RoamingWithIr.bs2
    ' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.

    ' {$STAMP BS2} ' Stamp directive.
    ' {$PBASIC 2.5} ' PBASIC directive.

    '
    [noparse][[/noparse] Variables ]
    counter VAR Nib
    irDetectLeft VAR Bit
    irDetectRight VAR Bit
    pulseCount VAR Byte

    '
    [noparse][[/noparse] Initialization ]

    DEBUG "Testing piezospeaker..."
    FREQOUT 4, 2000, 3000
    DEBUG CLS,
    "IR DETECTORS", CR,
    "Left Right", CR,
    "

    "
    '
    [noparse][[/noparse] Main Routine ]

    DO

    FREQOUT 8, 1, 38500 ' Store IR detection values in
    irDetectLeft = IN9 ' bit variables.

    FREQOUT 2, 1, 38500
    irDetectRight = IN0

    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
    GOSUB Back_Up ' Both IR pairs detect obstacle
    GOSUB Turn_Left ' Back up & U-turn (left twice)
    GOSUB Turn_Left
    ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
    GOSUB Back_Up ' Back up & turn right
    GOSUB Turn_Right
    ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
    GOSUB Back_Up ' Back up & turn left
    GOSUB Turn_Left
    ELSE ' Both IR pairs 1, no detects
    GOSUB Forward_Pulse ' Apply a forward pulse
    ENDIF ' and check again

    LOOP

    '
    [noparse][[/noparse] Subroutines ]

    IF (IN0 = 0) OR (IN9 = 0) THEN
    FOR counter = 1 TO 5
    HIGH 1
    HIGH 10
    FREQOUT 6, 200, 4000
    LOW 1
    LOW 10
    PAUSE 20
    NEXT
    ENDIF
    RETURN
    Forward_Pulse: ' Send a single forward pulse.
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    RETURN

    Turn_Left: ' Left turn, about 90-degrees.
    FOR pulseCount = 0 TO 20
    PULSOUT 13, 650
    PULSOUT 12, 650
    PAUSE 20
    NEXT
    RETURN

    Turn_Right:
    FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
    PULSOUT 13, 850
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN

    Back_Up: ' Back up.
    FOR pulseCount = 0 TO 40
    PULSOUT 13, 650
    PULSOUT 12, 850
    PAUSE 20
    NEXT
    RETURN




    and I wired it the same as the pic in the manual on page 243.
  • OSOKOSOK Posts: 35
    edited 2007-08-09 05:20
    Hehe... I found the answer. Take a look at the code right after the '
    [noparse][[/noparse] Subroutines ]
    line, see if you can figure it out on your own. If you don't, we'll tell you, but go ahead and try.
  • walice_drelwalice_drel Posts: 81
    edited 2007-08-09 05:24
    I'm new to this I just got my boe-bot in the mail today so I don't think i can figure it out on my own. The answer would be much appreciated.
  • OSOKOSOK Posts: 35
    edited 2007-08-09 05:35
    The code where you have the LEDs lighting up isnt part of a subroutine, so it never gets called. The only code that gets processed is the stuff inside the DO LOOP section, and the subroutines that are called from within it.

    Take it easy, do all the projects in the book one by one, and I guarantee by the time you get to page 243 you'll understand what you did wrong.
  • walice_drelwalice_drel Posts: 81
    edited 2007-08-09 05:41
    I'm not sure i understand can you please type a couple lines so i can see a example?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-09 05:53
    Hi walice_drel, what he is saying is that the first subroutine which begins

    IF (IN0 = 0) OR (IN9 = 0) THEN

    has a return statement but is missing a label

    Jeff T.
  • OSOKOSOK Posts: 35
    edited 2007-08-09 05:56
    Look at the following code

    ***************************
    -main program
    DO
    GOSUB SayHello
    GOSUB SayBye
    LOOP

    -subroutines definitions
    SayHello:
    Type hello on the screen
    SayBye:
    Type bye on the screen
    ShakeHands:
    Shake your hand and smack you on the butt.

    ***************************

    The the code is processed, it goes line by line. The first line is SayHello. The GOSUB command is like a GOTO that makes the compiler 'jump' to where SayHello is defined, run that code, and then it jumps back to where it left off. Next would be Saybye, so again, the program 'jumps' down to where SayBye is defined, types bye on the screen, then it jumps back up to the next line, LOOP, which repeates the whole thing.

    Now, you notice the third routine there ShakeHands ? It's never called in the DO LOOP, so it's never processed.

    So, the problem with your code: 1) you have code outside of the DO LOOP part so it's never processed, and 2) the code isn't part of a subroutine. You can either make it a subroutine and call it with GOSUB, or incorporate it in the main code as is.

    Hope that helps.


    EDIT: yes, just like unsoundcode said, it's missing a label. You know why? Because you just copied and pasted code from the book and slapped it together. That's not the way to learn, my friend, but it's the way to get frustrated very easily.

    Post Edited (OSOK) : 8/9/2007 6:01:04 AM GMT
  • walice_drelwalice_drel Posts: 81
    edited 2007-08-09 06:06
    Thank you so much I got it working
Sign In or Register to comment.