You download your beautifully crafted program....and nothing. Or, your watchdog LED doesn't flash. Or, your bidirectional motor doesn't bidirection. Here's what to do.
The key to effective debugging is to isolate the problem system and then tackle it a piece at a time.
First, write and download this one-line program (after saving your main program)
which will clear out your main program.
Then follow the steps listed below depending on what part of your system doesn't work.
Assuming your LED is in Pin 0, try this program
high 0 pause 1000 low 0
The LED should light for one second. If not run the program while measuring the voltage between Pin 0 and ground with your voltmeter. The voltage should jump to +5 and then back to 0. If not, disconnect the LED from the pin and try again. If not, disconnect the wiring from all the pins and from Vdd and Vss and try again.
If the voltage is good, then you either have a wiring error or a bad LED. Disconnect the wire from Pin 0 and connect to Vdd. The LED should light. If not check the LED orientation.
If the LED lights, but does not flash, you have a programming error. Write a program that just has the flashing LED part and debug.
Assuming your switch is connected to Pin 1, download this program
check: debug dec in1 pause 250 goto check
You will see a stream of 1's on the screen. When the switch is pressed the 1's change to 0's. If not, measure the voltage between Pin 1 and ground while operating the switch. You should get +5V when the switch is open and 0V when the switch is closed. If not, you either have a wiring error or a bad switch. To check for the latter, disconnect the switch from the circuit and measure continuity across the terminals with the continuity checker (the beeper function) of your voltmeter. The switch should be open when not pressed and shorted when pressed.
If the debug program works fine, but the switch is not being recognized in your main program, you have a programming error. Download just that section of code and debug.
Assume you have a motor/solenoid/electromagnet being controlled by Pin 2 via a TIP120 transistor. Download this program
high 2 pause 1000 low 2
The motor should turn on for one second. If not run the program while measuring the voltage between Pin 2and ground with your voltmeter. The voltage should jump to +5 and then back to 0. If not, disconnect the lead to the TIP120 base resistor try again. If not, disconnect the wiring from all the pins and from Vdd and Vss and try again.
If the pin voltage is good, then their is either a wiring error or the TIP120 is bad or the battery is dead.
Confirm that the battery minus is connected both to the emitter of the TIP120 and Vss (gnd) of the Stamp board.
Measure the voltage between the collector of the TIP120 (the tab is also the collector) and gnd. It should read the battery voltage. If not, measure your battery voltage. If the battery is good, then you have a wiring error.
Try touching the collector of the TIP120 to ground. The motor should turn on. A simple way of doing this is to short the collector and emitter leads of the TIP with a wire, clip lead, or paper clip. If the motor does not turn on, then you have a wiring error. If the motor does turn on, but you still do not have control by the computer, you either have a wiring error on the base side, or your TIP120 is bad. Find a spare TIP120, swap in to test.
Assume you have the standard DPDT relay setup for running a motor in two directions and that the on/off control is in Pin 4 and the direction control is in Pin 5.
Download this program
high 4 pause 500 low 4
The motor should run for 1/2 second. If not, follow the same debug procedures listed above for debugging a motor.
Now download this program
high 5 pause 500 low 5
You should hear the relay give two solid clicks as it turns on then off. If not, check your wiring, check that the relay coil is being driven by 12V, and then do the same debug procedures listed above for debugging a motor.
If these two checks work, download this program
high 4 pause 1000 low 4 pause 1000 high 5 pause 20 high 4 pause 1000 low 4 pause 20 low 5
This should turn the motor for one second in one direction, then wait one second, then turn it for one second in the other direction. The "pause 20" statements are to minimize the effects of voltage spikes that occur when turning relays or motors on and off.
If all this works, but your main program does not, you have a programming error. Download just that section of the code and debug.
If none of this works, ask the staff for help. When coming for help, bring (1) schematic, (2) voltmeter, (3) programming cable, (4) laptop (if you have one).
The staff will first go through the above debugging procedures, so save yourself some time by running them yourself first.