USB to serial interface
epicjr77
Posts: 29
Hello I have a USB to serial interface, and for some reason my robot on runs the program correctly if the serial is connected into the board of education. If I unplug it it freaks out for some reason. I Blew my first basic stamp 2, so I bought a new 1 off ebay and it is a rev G, any ideas whats going on?
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program is running"
'
( Variables)
pulseCount VAR Byte 'For Next loop counter.
'
(initialization)
FREQOUT 4, 2000, 3000 ' signal program start/ reset.
'
(main ROutine)
DO
IF ( IN5 = 1) AND ( IN7 = 1) THEN
GOSUB Back_up 'Back up and U turn (left twice)
GOSUB Turn_left
GOSUB Turn_left
ELSEIF (IN5 =1) THEN 'left switch hits
GOSUB Back_up
GOSUB Turn_right
ELSEIF (IN7 = 1) THEN ' right switch hits
GOSUB Back_up
GOSUB Turn_left
ELSE
GOSUB Forward_pulse ' No hits send foward and check again
ENDIF
LOOP
'
(Subroutines)
Forward_pulse:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN
Turn_left: ' 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
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_up:
FOR pulsecount= 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
There's something odd about your switch setup. In the BoeBot, the switches are wired to connect to ground when closed (logic zero) and there's a 10K pullup resistor to Vdd that provides a logic one when the switch is open. In your case, you're testing for a logic one for when the switch is closed. If you've got things reversed, make sure you have a pulldown resistor. Look in the "Robotics for the BoeBot" tutorial from Parallax's Stamps in Class downloads page for the schematics.
"Backs up and turns around" is what the 'bot does when both switches are open, in your current code. Is that what you intend?
So, are you sure the 'other end' of the switch goes to a good "Vss"? You could measure this with a voltmeter.