4.1.2. Exercise: Coding, Compiling, Deploying

4.1.2.1. Objective

Running a program on an Arduino.

The best references for getting started with the Arduino are supplied with the IDE: the Help menu includes a section for Getting Started which covers operation and Reference which covers the language.

In addition, the main Arduino site has similar introduction pages:

  1. Arduino: Getting Started
  2. Arduino: Reference

The Arduino Tutorial Foundations page addresses many basic ideas and syntax. If you have no programming experience at all, please be sure to look at First Sketch, Variables, and Functions. For more beginner help, please remember that the Arduino language is a subset of C++, so many elementary C or C++ tutorials online can cover the basics of variables, functions, control flow, and program logic, e.g., anything which relates purely to the internal logic of a computation rather than the physical interface.

4.1.2.2. Steps and observations

  1. Connect an Arduino Uno to the host computer with the IDE.
  2. Configure the IDE for the Uno as per the Getting Started guide.
  3. Load the Examples/01.Basics/Blink sketch. The Examples are found on the File menu, as is the Sketchbook in which you can put your own programs.
  4. This program uses just the LED onboard the Uno, so no additional external circuit is required.
  5. Verify/Compile the program to check that the program text is valid.
  6. Upload to the Uno and check that the LED blinks when the program runs.
  7. Change the numbers in the delay statements; the units are milliseconds.
  8. Re-upload and observe the change in LED behavior.
  9. Upload the ReadAnalogVoltage sketch.
  10. Find and open the Serial Monitor. Set it to 9600 baud to match the sketch.
  11. Observe the measurements of analog noise printed to the monitor. Attach a wire to A0 and touch it with your finger to change the noise input.
  12. The serial monitor is your primary means for seeing the debugging output from your programs; you should become familiar with the Serial library and printing out text and numbers.

4.1.2.3. Comments

It can be quite difficult to debug complex programs when the serial port is the only source of information, and especially when it is also being used for transmitting data back to the hosts. It can be helpful to use digital output pins for indicating single bits of program state and viewing the voltages on the oscilloscope.