Appendix D. Tips on Troubleshooting Software Problems

As you write and modify code, you will get code that doesn’t work (usually referred to as a bug). There are two broad areas of software problems: code that won’t compile and code that compiles and uploads to the board but doesn’t behave as you want.

D.1. Code That Won’t Compile

Your code might fail to compile when you click on the “verify” triangle or the “upload” button (see Chapter 1). This is indicated by red error messages in the black console area at the bottom of the Arduino software window and a yellow highlight in the code if there is a specific point where the compilation failed. Often the problem in the code is in the line immediately before the highlighted line. The error messages in the console window are generated by the command-line programs used to compile and link the code (see Recipe 17.1 for details on the build process). This message may be difficult to understand when you first start.

One of the most common errors made by people new to Arduino programming is omission of the semicolon at the end of a line. This can produce various different error messages, depending on the next line. For example, this code fragment:

void loop()
{
  digitalWrite(ledPin, HIGH)    // <- ERROR: missing semicolon
  delay(1000);
}

produces the following error message:

  In function 'void loop()':
  error: expected `;' before 'delay

A less obvious error message is:

  expected unqualified-id before numeric constant

Although the cause is similar, a missing ...

Get Arduino Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.