<<

Getting Started with the

What is an Arduino?

Arduino is a family of PC board-based- systems built around a ( if you wish). Currently, the most popular are the UNO, Leonardo, MEGA, NANO, Due, and LilyPad. https://www.arduino.cc/en/Main/Products

The primary differences between configurations include such features as operating voltage, number of /output pins, on-board memory, form factor, and other subtleties.

We will be using on of the most popular Arduinos' the UNO R3 (Revision 3) based on the Atmel ATmega328 microprocessor .

Arduino UNO R3 Image https://www.arduino.cc/en/Main/ArduinoBoardUno

What is a microcontroller?

A microcontroller is on a single containing a core, memory, and programmable input/output .

ATmega328 Image http://www.atmel.com/devices/atmega328.aspx

What is a computer? In it simplest form, a computer consists of Inputs, Processing, and Outputs. The processing system consists of Storage (Memory), (CPU) including a System Clock The CPU general consists of a and a .

Computer Block Diagram

Computer Block Diagram (Expanded) What is a Central Processing Unit (CPU)?

The processor core or Central Processing Unit (CPU) is the electronic circuitry that carries out the instructions of a by performing basic arithmetic including AND and OR, logical control (branching), and input/output (I/O) operations. Internally the CPU has many different sub-components that perform each of the above steps, and generally they can all happen independently of each other. This is analogous to a physical production line, where there are many stations where each step has a particular task to perform. Once done it can pass the results to the station and take a new input to work on.

Accordingly, principal components of a CPU includes the Arithmetic Logic Unit (ALU) that performs arithmetic and logic operations, Processor Registers that supply to the ALU and store the results of ALU operations, and a Control Unit (CU) that fetches instructions from memory and "executes" them by directing the coordinated operations of the ALU, registers and other components.

Clock Speed, Cycles per Second, MIPS , FLOPS The speed of the computer, given in Megahertz or Gigahertz (millions or thousands of millions cycles per second). This is called the clock speed since it is the speed that an internal clock within the computer pulses. The pulses are used within the processor to keep it internally synchronized. On each tick or pulse another operation can be started; think of the clock like the person beating the drum to keep the rower's oars in sync. MIPS Instructions per Seconds FLOPS Floating Point Operations per Second

Machine Instructions The CPU executes instructions that are read from memory. There are two categories of instructions: 1. Those that values from memory into registers and store values from registers to memory. 2. Those that operate on values stored in registers. For example adding, subtracting, multiplying, or dividing the values in two registers, performing bitwise operations (AND, OR, XOR, etc); or performing other mathematical operations (square root, sin, cos, tan, etc).

Branching Apart from loading or storing, the other important operation of a CPU is branching. Internally, the CPU keeps a record of the next instruction to be executed in the instruction pointer. Usually, the instruction pointer is incremented to point to the next instruction sequentially; the branch instruction will usually check if a specific register is zero or if a flag is set and, if so, will modify the pointer to a different address. Thus the next instruction to execute will be from a different part of program; this is how loops and decision statements work.

Control Unit (Fetch, Decode, Execute, Store) A single instruction consists of a particular cycle of events: fetching, decoding, executing and storing. For example, to do the add instruction the CPU must: Fetch - get the instruction from memory into the processor. Decode - internally decode what it has to do (in this case add). Execute - take the values from the registers, actually add them together. Store - store the result back into another register.

Comparing an Arduino to a Computer Computer

Power Supply Clock Central Processing Unit Arithmetic Logic Unit Inputs Control Unit Outputs

Keyboard Display

Mouse Storage (Memory)

Touch Pad

Touch Screen 3D Printer Audio / Video

External Storage. External Storage R3

Power Supply (), USB-UART, Clock (16 MHz), CPU (Atmel ATmega 328)

ATmega328 Memory: 32K Flash (Program), 2K RAM (Variables), 1K EEPROM () Input/Output: 14 Digital & 6 Analog, , USB, SPI, I2C, TWI

Inputs ( Voltages): Audio, Light, IR, UV, PIR, Motion, Temperature, Humidity, Pressure, Chemical

Outputs: Relays, Actuators, Motors, Visual Displays (LEDs & LCDs), Audio, SD Chip, Data Logger

Arduino Microcontroller Memory System Timer System Port System Serial System System Analog-to-Digital Converter (ADC)

Arduino UNO R3 ATmega328 ATmega 328

Memory System Port System Serial Communications ADC 32K Programmable Flash 14 Digital I/O Pins Serial USART 6 Channel 10- 2K RAM 6 Analog Input Pins SPI 1K Addressable EEPROM TWI

Timer System Interrupt System Two 8-bit Timers 26 total Interrupts One 16-bit Timer 2 External Pin Interrupts Six PWM Channels

Interfacing with the Arduino

Getting Started with the Arduino (Input/Output Pin Configuration)

Arduino UNO R3 ATmega 328 ATmega 328

Memory System Port System Serial Communications ADC 32K Programmable Flash 14 Digital I/O Pins Serial USART 6 Channel 10-bit 2K RAM 6 Analog Input Pins SPI 1K Addressable EEPROM TWI

Timer System Interrupt System Two 8-bit Timers 26 total Interrupts One 16-bit Timer 2 External Pin Interrupts Six PWM Channels

Power Supply (Voltage Regulator), USB-UART, Clock (16 MHz), CPU (Atmel ATmega 328)

Atmel328 Memory: 32K Flash (Program), 2K RAM (Variables), 1K EEPROM (Data) Input/Output: 14 Digital & 6 Analog, Interrupts, USB, SPI, I2C, TWI

Inputs (Sensor Voltages): Audio, Light, IR, UV, PIR, Motion, Temperature, Humidity, Pressure, Chemical

Outputs: Relays, Actuators, Motors, Visual Displays (LEDs & LCDs), Audio, SD Chip, Data Logger

Arduino Input and Output

14 Digital I/O Pins Each of the 14 digital pins on the UNO can be used as an input or output, using pinMode( ), digitalWrite( ), and digitalRead( ) functions. They operate at 5 . Each pin can provide or receive a maximum of 40 mA and has an internal pull-up (disconnected by default) of 20-50 kOhms.

In addition, some pins have specialized functions:

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip.

External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt( ) function for details.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite( ) function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI using the SPI library.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

6 Analog I/O Pins The UNO has 6 analog inputs, labeled A0 through A5, each of which provide 10 of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference( ) function. Additionally, some pins have specialized functionality:

TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the library.

Power Pins

The power pins are as follows: Vin The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.

5V This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the Vin pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator.

3.3V supply generated by the on-board regulator. Maximum current draw is 50 mA.

GND Ground pins.

IOREF. This pin on the Arduino board provides the voltage reference with which the microcontroller operates. A properly configured shield can read the IOREF pin voltage and select the appropriate power source or enable voltage translators on the outputs for working with the 5V or 3.3V. AREF Reference voltage for the analog inputs. Used with analogReference( ).

Reset Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board.