The Arduino Microcontroller

arduinounotop.jpg

The Arduino Uno is a microcontroller made and designed in Italy. Have a quick look at Adafruit's decription of this and related devices (there are many). A microcontroller is not the same as a //microprocessor//. The Raspberry Pi is a microprocessor. You can run an operating system on the Pi. The Arduino is far simpler; think of it as a programmable chip. You write the program on a computer, compile it (translate it into machine code), upload it onto the Arduino, and the Arduino will attempt to follow your instructions. Because of its simplicity it is not as powerful as something like a Raspberry Pi, but it is far more robust, easy to use, is better able to control and accept input from devices, and is cheaper!

You will not need to set up any software as this has already been done. But for an introduction of the system and software have a look at the Getting Started page on the Adafruit website.

Why use an Arduino Board? Watch the Arduino Movie on Vimeo. (But not while you are in the lab!!!) The Wikipedia page on the Arduino is also quite cool and contains a load of information.

Basics

What's on the board?

We will be using the Arduino Uno. This is the most commonly used board for hobby projects. For a full description of the board, chips, memory, I/O pins, voltages, etc., see the Arduino Uno page.

Getting Started & Troubleshooting

Need help setting up an Arduino board, or something has gone wrong? Have a look at the Getting Started with Arduino page for information.

Foundations

The best way to learn about an Arduino board is to use it. So first try the examples given below. At least the simple ones. Once you've got your hands wet, you may want to know more about it: What is a //sketch//? What are the pins on an Arduino board for? This sort of information can be found on the Foundations page. The most useful bits are:

Example Sketches

Here are some example projects that introduce you to various aspects of the Arduino. If you are doing an SCM laboratory experiment, you may need to do only a few of these. Make sure you know which ones are necessary!

  1. Blink: (PDF) This is a very simple example. There is nothing to construct here as the Arduino already contains all the components.

  2. Blink 2: (PDF) This example is similar to the previous one, but includes more exercises and more information. Try out the exercises to make sure you understand how the C-language works.

  3. Control a single LED: (PDF) In this example we learn how to control a single LED (light emitting diode). This time we will create our first circuit. You will also use a breadboard here. If you have not seen one before, this is a good place to start.

  4. More on LEDs: (PDF) Use this tutorial to learn more about LEDs and why we need to connect them to resistors. There are some cool projects here, but try them only if you have the components at hand. Also use this tutorial if you are unsure of how to read resistor codes and use breadboards.

  5. Digital Inputs: (PDF) Here we learn how to use button input to control an LED.

  6. A (pseudo-)Theremin: (PDF) This is a device that can be played by waving your hand in front of it. This small project involved sensing light and using this reading to control the pitch of a piezo speaker.

  7. Programming the Arduino and using the Serial Interface: (PDF) These issues are described here in some detail, together with exercises. If you want to be really sure of what you are doing try this exercise. Another version of the Serial Monitor tutorial from Adafruit is here (PDF).

  8. Working with Inputs: (PDF) Learn how to program the Arduino to use inputs from switches. You will have used switches in the Digital Inputs tutorial above, but this one contains much more detailed information and more challenging projects. You could regard this as a more advanced version of the earlier project.

You will find more examples at the Examples page on the arduino.cc site.

Debugging your sketchs

There is no simple recipe for debugging sketches. But a few conventions will help:

  if (abs(speedLeft) < abs(speedRight))
  {
    digitalWrite(pinRled, HIGH);
    digitalWrite(pinLled, LOW);
  } 
  else if (abs(speedLeft) > abs(speedRight))
  {
    digitalWrite(pinRled, LOW);
    digitalWrite(pinLled, HIGH);
  }
  else
  {
    digitalWrite(pinRled, LOW);
    digitalWrite(pinLled, LOW);
  }

Or this one, without indents?

  if (abs(speedLeft) < abs(speedRight)){
  digitalWrite(pinRled, HIGH);
  digitalWrite(pinLled, LOW);
  }else if (abs(speedLeft) > abs(speedRight)){
  digitalWrite(pinRled, LOW);
  digitalWrite(pinLled, HIGH);
  }else{
  digitalWrite(pinRled, LOW);
  digitalWrite(pinLled, LOW);
  }

Reference Material

The most comprehensive reference for the Arduino is the arduino.cc website. Everything you need is likely here. But here are some specific pages that you will probably need to reference more often:

Have a look at the language reference as this is the first place to go when you get stuck and need to either debug a program (they call them //sketches//) or add a new language feature to your sketch.

AJMPublic/teaching/arduino-pi/projects/arduino/getting-started (last edited 2021-04-14 13:17:17 by apw109)