Table of Contents

Intro to Arduino

store-cdn.arduino.cc_uni_catalog_product_cache_1_image_520x330_604a3538c15e081937dbfbd20aa60aad_a_0_a000066_featured_1_.jpg
Fig.: Arduino UNO Rev 3. CPU: Microchip (Atmel) ATmega328p, 8-bit AVR Core. https://store.arduino.cc/arduino-uno-rev3

Technical data (Arduino UNO processor)

Lecture Notes

University of Washington, Computer Sciences (CS), Course Number CSE P567

Keywords

Lab / Exercises

Background: Atmega328P Processor

The CPU used is ATmega328p having been designed by the former company Atmel which has been taken over by Microchip.

Setting up the Arduino IDE tool chain

Please follow the instructions on Getting started with the Arduino and Genuino UNO.

0. General Basic Commands

We have to learn the following commands:

pinMode(pin, mode) 
myval = digitalRead(pin)
digitalWrite(pin, value)
myval = analogRead(pin)
analogWrite(pin, value)
delay(ms)
Serial.begin(baudrate)
Serial.println(data)
map(value, fromLow, fromHigh, toLow, toHigh)

Keywords: Arduino IDE, directories, libraries, code files, compile, upload, terminal (monitor)

<note> For the following exercises use the
Arduino Online Language Reference and the
Programmers Notebook (pdf) by Brian Evans. </note>

1. Digital Output

Write a program which lets and LED blink “SOS” in Morse code:

. . .   - - -  . . . 

(three short, three long, three short blinks). The LED is connected to pin 13. By default all pins are input so you have to define the pin direction to be an output explicitly. Use digitalWrite(pin,HIGH) and digitalWrite(pin,LOW).

Write two functions void morse_S() and void morse_O() and use for next loops for the loops within the functions.

Write two functions void blink_short() and void blink_long() including the pauses (LED off).

2. Digital Input

<note important> ATTENTION: 3.3V or 5V?
Some Arduino platforms use 3.3V as supply voltage or VCC (not 5V). In this case you might damage the microcontroller if you connect 5V to its pins! The input voltage would exceed the supply voltage (overvoltage). Avoid this! Some microcontrollers with 3.3V VCC have 5V tolerant inputs but this is not generally the case! Read the MC datasheets. </note>

3. Analog Input

4. Analog Output by Pulse Width Modulation

The “old” AVR microcontrollers such as ATmege328, the core of Arduino UNO, do not have a real analog output. To work around this limitation a method called Pulse Width Modulation (PWM) is used. A square wave signal of fixed frequency is generated and provided at a port pin (digital output). The pulse width of the square wave (the time for the signal being logic high) can be changed whereas the total signal period T is kept constant (as a result of constant frequency).

The ratio $r = \mathrm{\frac{pulse\;width}{period}}$ is called duty cycle.

The average voltage of the signal is then a linear function of $r$:

$V_\mathrm{avg} = r\cdot V_\mathrm{cc} + (1-r)\cdot 0V = r\cdot V_\mathrm{cc}$

5. Serial Communication (UART)

6. Bus systems

7. Interrupts, Timers

8. Libraries

Homework

Literature