Some of my projects in the past have had issues due to a bad digital pin. If this has ever happened to you, then you know how frustrating it can be. Most people's first reaction is that there is something wrong with the code. You can save hours of wasted debugging time if you take a few minutes to test your microcontroller before your next big project.
Step 1: Pick Your Logic Analyzer
My Logic Analyzer of choice is the Analog Discovery by Digilent. It includes a 2-Channel Oscilloscope, 2-Channel Waveform Generator, 16-Channel Logic Analyzer, 16-Channel Digital Pattern Generator, ±5VDC Power Supplies, Spectrum Analyzer, Network Analyzer, Voltmeter, Digital I/O, and it is supported by MATLAB. You read that right, it has all those features packed into one little device! The Oscilloscope isn't the best but I purchased this product mainly for the Logic Analyzer. Overall it is a great tool for learning and definitely has it's purpose in my lab. I have also heard good things about Saleae Logic Analyzers, but I still prefer my Analog Discovery.
Step 2: Pick Your Favorite Development Board
For this instructable I will be testing an Arduino Uno, but the procedure is the same regardless of your choice of microcontroller.
Step 3: Upload the Code
Just upload the code to your microcontroller. If you're using an Arduino based microcontroller, then just use this code. If you have another microcontroller you want to test, then have each of the pins trigger high for a second and then switch to low. After cycling through all of the pins individually, simultaneously trigger all the pins high for a second and then low.
Step 4: Connect Your Logic Analyzer
Connect each digital pin of your microcontroller to a channel of your logic analyzer. Turn on your microcontroller with the uploaded code. Check to see that each pin is functioning as intended. If something is wrong, you will see it immediately. Whether the pin is not triggering at all or the timing is wrong, you can easily find the problem using a logic analyzer.
I will usually test a few at a time and mark them with a green paint marker if they pass the test. Next time I'm in a rush to build a project, I can confidently grab a tested unit and know that it is fully functional. I will also mark bad pins with a red paint marker. If I know I will not need all of the pins for a project, I will try to choose a board with a few damaged pins first.
Step 5: Other Uses for a Logic Analyzer
This is just one great use of a Logic Analyzer. If you have a Logic Analyzer that can output signals as well as receive them, then you can test IC chips. Use them to debug projects that have failed after being in use for sometime. Use them to check the timing of your I/Os. If you don't already have one, do yourself a favor and get a Logic Analyzer. You will start finding many uses for it.