Contributors:
MikeGrusin,
Gella TroubleshootingAs you begin to edit the example code and write your own programs, you may experience some error messages. This section highlights a few common issues and solutions as you work on your Arduino code.
At the bottom of the Arduino IDE is section with a black background. This is the Debug Window - if something unexpected or incorrect happens and Arduino can't communicate to your LilyPad USB Plus or run the code you've written, an error message will display here. The top of the section will turn orange and a "Copy Error Messages" button will display.
An example of an error displaying in the debug window
WARNING: There are known driver issues on older versions of Windows (7 and 8 specifically). We are actively working on the issue and expect to have a resolution soon.
Common Error Messages Error: "Couldn't find a Board on the selected port"This error happens when there is a missing ;
at the end of a statement. Arduino will highlight the line in red in the code window and print a line number in the code around where the error occurred to help you identify where you need to fix something. You can turn on line numbering in Arduino > Preferences.
In this example, a missing ;
after digitalWrite(A5, HIGH)
caused the error.
Scope errors can happen for a variety of reasons, here are some common things to check:
This error happened because the variable blueLED
was mistyped as BlueLED
. Arduino did not recognize BlueLED
, while it may look similar enough to you, Arduino is case sensitive.
As you copy and paste to move pieces of your code around or work with nested functions, your code will accumulate a lot of curly brackets. To keep track of nested functions in the example code, we use indented formatting. Each new nested layer of function is indented an addition time to visually organize the code. If one of the opening {
or closing }
is accidentally deleted or not added, you will get an error.
This error in Activity 4 happened because the closing bracket for the for()
loop is missing. This can be initially misleading, as Arduino highlighted a closing bracket - this one belongs to the loop. The space above it is where Arduino expected a match for the opening bracket of the for()
loop - highlighted in blue.
Arduino has a handy feature built in that highlights the matching curly bracket if you place your cursor after one. You can use this to quickly check that there are no brackets left behind.
Placing the cursor next to the closing bracket of the for ()
loop in Activity 4 highlights its matching opening bracket with a blue outline.
Depending on the Arduino IDE version that you have installed, you may also be able to view the function that was associated with the bracket if it is out of frame. In this example, we were using Arduino IDE v1.8.3.
Placing the cursor next to the closing bracket of the loop()
function highlights the function and bracket when it is out of frame.
This sounds like a pretty general question, but it's likely a semantic error. While the code is able to compile and is free from syntax errors, the code might not be written to do what you intended. Assuming the hardware connections and boards are good, it is possible that:
delay()
function is preventing a certain line from executing fast enough.The list of reasons why this may be happening can go on depending on the complexity of the project. The simplest method of debugging can be turning on an LED when we reach a certain part of the code. However, the best method of troubleshooting Arduino code is to try to step through using the serial.print() function to debug. If used correctly, the function is more flexible and can indicate that we have entered a line of code.
Maybe you want to print "I entered this function" to the Serial Monitor after pressing a button or when a sensor reaches a certain value. The serial.print()
function can also be used to inspect variables in order to know what to expect from a sensor's output range. The function can also be used to verify calculations. Other environments allow you to step through the code to simulate what may happen without the need for serial.print()
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4