E2 Laboratory 01

Getting Connected


Overview of this week's lab.

The purpose of this lab is simply to get the Arduino package up and running and to establish communications between the Arduino and your computer. The directions below are tailored for a PC, but you should feel free to download the Arduino Development environment to your Mac if you prefer to use it.

  1. Download the Development Environment
  2. Starting the software and running your first program
  3. Communicate between Arduino and your computer

 

Task 1: Download the Arduino Development Environment

You can skip this section if you are using the PC's in Hicks 212. Otherwise follow the directions to download and install the Arduino software.

 

Task 2: Starting the software and running your first program

Connect the Arduino to your compuer with a USB cable. You may have to wait until drivers are loaded if this is the first time you have used an Arduino on your computer. Next, start the Arduino program. After a short time, you should get a screen like the one below that shows the interface to the Arduino Development Environment. The

Click on File→Examples→Blink. This will load program code into the development environment.

The working part of the code is shown below; we'll go over exactly what it is doing soon.:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT); 
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

Right now the program is just a text file that resides on your computer. We need to translater (or compile) the program into a set of instructions that the Arduino processor can understand and then sen those instructions to the the Arduino's processor. To compile the program you can go to Sketch→Verify/Compile or hit the "Verify" button, , or "Ctrl-R", After doing this, the program has still not been sent to the Arduino.

First we must make sure your computer is connected to the Arduino. Go to Tools→Port and choose your Arduino. In my case it was connect to COM5. On a Mac choose the one beginning with "/dev/cu.usbmodem...". If you have trouble click here for link to help page.

To send the code to the Arduino, go to Sketch→Upload, hit the "Upload" button, , or "Ctrl-U." This compiles the program, sends it to the Arduino, and starts it. It will take up to a minute to complete. An LED on the Arduino board should now be blinking (on for one second, and off for one second).

Task 3: Communicating between Arduino and Computer

Change your code to look like the one below. The code is unchanged except for three lines that have been added, all marked by beginning with Serial and ending with ***NEW***.

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
  Serial.begin(9600); // 9600 bps  ***NEW***
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);       // turn the LED on (HIGH is the voltage level)
  Serial.println("LED is on");  // ***NEW***
  delay(1000);                  // wait for a second
  digitalWrite(13, LOW);        // turn the LED off by making the voltage LOW
  Serial.println("LED is off"); // ***NEW***
  delay(1000);                  // wait for a second
}

Compile and download the code as before. Now open a "Serial Monitor" window on your computer to see communication from your Arduinto by going to Tools→Serial Monitor. A new window should open that displays the status of the LED (i.e., whether it is on or off).

 

That's it!

That's it for this week. When you are finished, go back to the moodle page and turn in a pdf file that has:

Make sure it is a pdf file and not some other format.

Next week we'll learn about some electronics and actually build a circuit to connect to the Arduino that will allow you to begin physically interacting with the processor directly. Feel free to search the internet for more information on Arduino's and try out some new things.