ME102 Lab 1: Getting Started

This lab will teach you how to setup the IDE (Integrated Development Environment) for the Arduino. These instruction have been tested for the computers available in lab. However, it is just as easy to setup the IDE on your own laptop. You may wish to do this for future lab assignments.
  1. Introduction to the Arduino
    • Kit contents check
    • Arduino IDE and some terminology
    • Hello Worlds
    • Anatomy of a sketch
  2. Setting up your hardware buffers
    • Digital input buffering with the 74LS4
    • Digital output buffering with the 7417
    • ADC setup with the 4342
  3. Clean up and check off
    • Blinking LED with the buffered setup
  4. References

1| Introduction to the Arduino

Kit contents check

Before we continue any further, please make sure that you have at least the following in your lab kit.

  • 1 Arduino Duemilanove
  • 1 USB A-B cord
  • 1 breadboard
  • 5 LED’s of assorted colors
  • 2 tactile switches
  • 1 DC motor
  • 1 tiny RC servo
  • 1 potentiometer
  • 1 optical encoder (datasheet)
  • 1 pair of wire cutters
  • 1 74LS14 (datasheet)
  • 1 SN7417 (datasheet)
  • 1 OPA4342(datasheet) or TLV2364I (datasheet)

If you have any problems identifying your parts, please notify a GSI
If you are missing any parts, please find Tom Clark

The Arduino and some terminology

Your Arduino board will look something like this

Arduino Duemilanove layout

The largest benefit of the Arduino is the fact that you are not limited to programming in the lab. Instructions on how to install a copy of the Arduino IDE on your own machine can be found here (Mac, Windows and Linux).

Start the Arduino IDE by clicking the Arduino icon on the desktop.

For those of you who are familiar with microprocessor programming, the first thing you will notice is the Arduino’s minimalist approach.

There are 7 shortcut commands that you can use with the Arduino IDE:

  • Serial Monitor opens the only debugging tool you have with the Arduino. The Serial Monitor displays information passed from the Duemilanove to the computer.
  • Upload compiles your program (“sketch” in the parlance of the creators of the Arduino, and sends it to the board if there are no compile-time errors.
  • Save your sketch
  • Open an existing sketch
  • New creates a new sketch
  • Stop interrupts compilation of your code.
  • Compile your sketch in order to check for compile-time errors. As your sketch grows in size, it’ll save time to verify that your code compiles before trying to upload it.

There are only a few things you need to configure and to learn before you begin. First, you need to make sure that the IDE has the correct target chosen. Select the Arduino Duemilanove from Tools>Board.

Secondly, the board communicates with the computer via a USB interface, but with a serial protocol. All this means is that you must select the correct serial port number. First, plug the provided USB cord into the computer. Please note that the Dell computers have some problems with the USB port located in the front. You can try both the USB port on the side of the monitor, or behind the machine. Once it is complete, open up the Device Manager (shortcut located on the Desktop) and check for the COM port that says USB serial port.

Make sure that the same COM port number is checked in the Arduino IDE.

Hello Worlds

Upload the provided sketch “HelloWorld” to the Arduino Board.

And check the serial monitor. You should see something like this:

Congratulations, you’ve successfully compiled, uploaded and communicated serially with the Duemilanove.

Next, load the “Blink” sketch.

You should see the onboard LED next to the digital pin 13 blinking.

Anatomy of a Sketch

In this section, I’ll explain the different parts of the sketches you just uploaded. There are two mandatory functions in every sketch: setup() and loop(). As their names imply, setup() is where you will choose how to use the board, and loop() can be thought of as a never-ending while-loop.

In the “HelloWorld” sketch, the need for serial communication is declared in setup(). Then the board constantly returns “Hello World!” via the USB serial port. This explains why the serial monitor is saturated with “Hello World!”.

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println("Hello World!");
}

The “Blink” sketch is more interesting.  In setup(), the pin 13 is declared to be an output. Then in loop(), digitalWrite sets pin 13 to logical HIGH, and nothing else is done as we wait for a delay of 1000ms. After which, pin 13 is set of logical LOW, and turned off. This behavior is then repeated ad nauseum.

int ledPin =  13;    // LED connected to digital pin 13

void setup()   {               
pinMode(ledPin, OUTPUT);    
}

void loop()                    
{
digitalWrite(ledPin, HIGH);  
delay(1000);
digitalWrite(ledPin, LOW);   
delay(1000);                 
}

The next part of the lab focuses on setting up buffers to protect your board from mistakes. Although the Arduino is relatively cheap, not all microprocessors are.

2| Setting up the hardware environment

While the sensors and outputs in the labs generate and draw little current, that is not the case for everything you will encounter in the course of the ME102 project. Buffering the inputs to and outputs from the Arduino adds a layer of protection. If an accidental short suddenly appears, the cheap buffer will break, and the board will be preserved.

. Powering the breadboard

  1. Supply 5V to the rails of the breadboard from the power supply provided in lab.
  2. Alternatively, you may choose to power your breadboard with the 5V supply from the Arduino. The Arduino is capable of supplying ~ 50mA.
  3. Make sure that the two rails on your breadboard share a common ground with whichever power supply you choose.

Digital input buffering with the 74LS14

To buffer the digital input of the Arduino, we use the 74LS14 (datasheet). The 74LS14 is a hex schmidtt trigger inverter. It takes a digital input and outputs the opposite. HIGH becomes LOW, and LOW becomes HIGH. In TTL (Transistor-to-Transistor Logic), a HIGH signal is anything from 2.2V to 5V whereas a LOW signal is anything from 0V to .8V. The area from.8V to 2.2V is essentially undefined behavior.The schmidtt trigger is a property of this particular chip that allows it to be slightly less responsive to noise. And finally, there are six such inverters on a single chip (hence hex).

To setup the 74LS14 :

  1. Connect the Vcc to the 5V rail and GND to ground
  2. Verify that the installed IC behaves correctly. For example, you could use the oscilloscope to monitor both input from a function generator and the inverter’s output. Using a square wave is the easiest, but you could use anything signal from the function generator as long as the minimum voltage is 0 and maximum voltage is 5.

Digital output buffering with the SN7417

Digital output buffering with the SN7417 (datasheet) protects the Arduino. The SN7414 is a hex buffer with open collector high voltage output. An open-collector only guarantees that a LOW input results in a LOW output. There are no guarantees for a HIGH input.

By using a pull-up resistor on the output end, one can supply any level of voltage within the operational specifications of the IC. For the SN7414, it is 15V.

The basic function of a pull-up resistor is to insure that given no other input, a circuit assumes a default value.  Consider the circuit in “Configuration of SN7417”, when the digital signal input is HIGH, the IC acts as a high impedance part so current flows to the right. When the digital signal input is LOW, the IC becomes a current sink. IN order to prevent IC destruction, pull-up resistors are generally in the range of 10k to 47k ohms. Special cases do exist as you will see at the check-off task.

  1. Connect the Vcc to the 5V rail and GND to ground
  2. Connect 10k Ω pull-up resistors between each of the IC outputs and the 5V rail
  3. Verify that the installed IC behaves correctly. . For example, you could use the oscilloscope to monitor both input from a function generator and the buffer’s output. It will be pretty boring since the buffer’s output value is its input value if a square wave is used.

ADC setup with the 4342

We protect the ADC with a voltage follower. In your lab kits, you may either have a OPA4342(datasheet) or a TLV2374I(datasheet). Both are suitable for our purposes.

To setup the voltage follower with the op amp:

  1. Connect the +V pin to 5V and the –V pin to ground
  2. Connect the inverting input (-In C) to the output (Out C) for any one of the four op amps on the IC. This creates the voltage follower.
  3. Verify that there is unity gain or Vin = Vout for your voltage follower. You can easily do this by connecting the wiper of your potentiometer, which has been connected between 5V and ground, to the non-inverting input (+ In C) . The wiper is the part that changes voltage as the knob turns.

3| Clean up and check off

Blinking LED with the buffered setup

The check off for this lab is a blinking LED that works with your buffered system.
  1. Connect Pin13 to the one of the 7417’s inputs
  2. Connect the corresponding output from the 7417 to the anode of the LED.
  3. 3) The pull-up resistor limits current flow. With a 10k resistor, current flow through it is limited to .5mA. This is not enough to drive an LED. Given that the SN7417 can sink 40mA, use a resistor of around 1k ohms as your pull-up resistor.
  4. Note that the onboard LED and your recently connected LED should blink in phase.

4| References

Arduino.cc

For your troubleshooting needs, please visit the Arduino homepage. It contains a wealth of information on both troubleshooting the Arduino and different sensors that have been used with the board.