O'Reilly logo

Arduino Cookbook, 2nd Edition by Michael Margolis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix D. Tips on Troubleshooting Software Problems

As you write and modify code, you will get code that doesn’t work for some reason (this reason is 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 (checkbox) button 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)    // <- BUG: 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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required