Hardware 32
Hardware
Diagnosing If your microcontroller is not plugged in, your computer will not be able to communicate with
it. This may show up as tools->serial port being grayed out, or the message “transfer incomplete” will show
up in your console after pressing “upload”. If you see these try:
• Unplugging and replugging in your microcontroller
• Resetting your microcontroller
• Rebooting your microcontroller
You may have to wait a minute or two after any of these xes to see if they work.
Dealing with Syntax Errors
Prevention Syntax errors are easy to make, typos and missed semicolons are very common. Verifying
your code often will help you to know if you made any syntax errors. If you write all your code at once, it will
be harder to gure out where the error is, and it is more likely there are more than one. Experience will help,
as you get used to ending with a semicolon and matching parentheses.
Diagnosing Usually syntax errors will be caught by the compiler. When you press “verify”, an error will
appear in the bottom console.
11:1:error:expected‘;’before‘}’token
There is a missing semicolon, which the compiler noticed at line 11, character 1. The line number
of your cursor is displayed in the bottom-left of the IDE. The actual error was on line 9, but the
compiler doesn’t notice until a bracket occurs.
9:24:error:expected‘)’before‘;’token
There is a missing closing parenthesis, noticed at line 9, character 24. Usually this error will have
the right line number, and the IDE highlights matching parentheses, which is helpful.
9:20:error:‘HIG’wasnotdeclaredinthis
scope
The compiler does not know what ‘HIG’ is, at line 9, character 20. This is usually a typo. If ‘HIG’
was a variable you created, make sure it is declared properly at the beginning of your function or
program. Maybe it’s missing a eld type (int, char, double, long, void).
If you’re not sure where the error is coming from, try commenting out a line, and see if the error goes away.
If it did, you know which line is wrong. You comment out a line by adding two forward slashes ‘//’ to the
beginning of the line.
Dealing with Logical Errors
Prevention Logical errors are usually caused by programmer mistakes, or if you don’t exactly know how
your program should work. Good programming practice helps prevent these errors.
• Make code readable This means using empty lines to separate code, indenting blocks of
code. Name variables, functions, and anything with understandable names, not ‘a’, ‘b’, but something
like, ‘myspeed’, ‘forwardspeed’. It is important to keep your style consistent. You can use tools-