CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall...

18
CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015

Transcript of CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall...

Page 1: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

CSCI1600: Embedded and Real Time SoftwareLecture 4: Introduction to the Arduino

Steven Reiss, Fall 2015

Page 2: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

What is an Arduino

Page 3: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Arduino Chip: ATmega48

Page 4: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Arduino CPU

Page 5: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Embedded Processors Arduino: a microcontroller

Others exist as well

General purpose processors ARM processor (low power)

Raspberry Pi

Special purpose processors DSP for sound, video processing

Graphics processors

Page 6: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Other alternatives Field-Programmable Gate Arrays

Less expensive than creating chip

Like having a bucket of parts to wire together Except the wiring is done programmatically

And the whole thing fits on a chip

Easy and cheap to make in quantity

Programmed in a high-level language

Page 7: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Arduino Restrictions

Simple CPUSingle core, single threaded

No pipelining

No floating point processorHow is floating point done

Page 8: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

What you need to knowPower/USB InputGround and power outputsDigital input/outputsAnalog input/outputsReset button

Page 9: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Clapper

Two circuitsOne to provide input

Analog based on sound intensity

One to provide outputTwo lights

Digital (on or off)

Page 10: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Clapper Input Circuit

Page 11: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

How does this workMicrophone generates a weak signal

https://www.jameco.com/Jameco/Products/ProdDS/136574.pdf

LM386 is an amplifier chipAmount controlled by resistor, capacitor

http://www.ti.com/lit/ds/symlink/lm386.pdf

Output balanced between 0 and 5 volts

Page 12: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Output circuit

Connect Digital Output Pin to LEDThrough a resistor (why)

Other side of LED is grounded

Page 13: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

How should the clapper work?Read the input

How often

Check if we have a clapWhat does a clap look like

How would you find out

Check if we have a clap sequence

Page 14: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Clapper requirements

Turn lights on or offBased on clap input

Handle flashing lightsHow often to check

Page 15: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Tasks The basic concept in RT/EM software

Break your project into tasks

Tasks are independent Communicate via shared variables

Communicate via network, etc.

Tasks are run periodically or on demand Periodic – run every k microseconds

Demand – run on event, interrupt

Page 16: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Clapper Tasks

Listen for soundHandle clapper logicHandle first lightHandle second light

Page 17: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Clapper Stateclap_count (# claps)clap_done (clap interval over) last_clap (whether clap has ended)do_clap (take action based on clap)cur_state (state of lights)orig_state (state at start of all claps)

Page 18: CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.

Homework

https://www.arduino.cc/en/Tutorial/HomePage

Think about what the code should look like logically