PDF of this portion of workshop notes:

Similar documents
PDF of this portion of workshop notes:

PDF of these workshop notes:

Digital Pins and Constants

Procedure: Determine the polarity of the LED. Use the following image to help:

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

IME-100 ECE. Lab 3. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

Introduction to Arduino

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Prototyping & Engineering Electronics Kits Basic Kit Guide

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

Alessandra de Vitis. Arduino

Thursday, September 15, electronic components

Serial.begin ( ); Serial.println( ); analogread ( ); map ( );

Blinking an LED 1 PARTS: Circuit 2 LED. Wire. 330Ω Resistor

Lesson 8: Digital Input, If Else

IME-100 Interdisciplinary Design and Manufacturing

Advanced Activities - Information and Ideas

Robotics Adventure Book Scouter manual STEM 1

Halloween Pumpkinusing. Wednesday, October 17, 12

Arduino Programming. Arduino UNO & Innoesys Educational Shield

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

Arduino Prof. Dr. Magdy M. Abdelhameed

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

How to Use an Arduino

Laboratory of Sensors Engineering Sciences 9 CFU

Arduino 05: Digital I/O. Jeffrey A. Meunier University of Connecticut

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Introduction To Arduino

Robotics and Electronics Unit 5

Physics 364, Fall 2012, Lab #9 (Introduction to microprocessor programming with the Arduino) Lab for Monday, November 5

RedBoard Hookup Guide

Sten-SLATE ESP Kit. Description and Programming

Goal: We want to build an autonomous vehicle (robot)

Lab 2.2 Ohm s Law and Introduction to Arduinos

Counter & LED (LED Blink)

IME-100 ECE. Lab 4. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

ARDUINO INDUSTRIAL 1 01 Code: A000126

Finite State Machine Lab

Specification. 1.Power Supply direct from Microcontroller Board. 2.The circuit can be used with Microcontroller Board such as Arduino UNO R3.

Arduino Micro Breadboard Laboratory Interface Processor (Micro BLIP) User Manual

keyestudio Keyestudio MEGA 2560 R3 Board

Fall Harris & Harris

USER MANUAL ARDUINO I/O EXPANSION SHIELD

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

ARDUINO YÚN Code: A000008

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

Digital Design through. Arduino

EK307 Lab: Microcontrollers

ArdOS The Arduino Operating System Quick Start Guide and Examples

3. The circuit is composed of 1 set of Relay circuit.

SPDM Level 2 Smart Electronics Unit, Level 2

OBSTACLE AVOIDANCE ROBOT

Arduino 07 ARDUINO WORKSHOP 2007

Code&Drive First steps

Physical Computing Self-Quiz

Update: Ver 1.3 Dec Arduino Learning Guide For Beginner Using. Created by Cytron Technologies Sdn Bhd - All Rights Reserved

Laboratory 1 Introduction to the Arduino boards

Arduino and Matlab for prototyping and manufacturing

Lecture 6: Embedded Systems and Microcontrollers

Arduino Programming and Interfacing

About SunFounder Preface SunFounder is a technology company focused on Raspberry Pi and Arduino open source community development. Committed to the pr

EXPERIMENT 7 Please visit to learn all features of arduino before you start the experiments

Arduino - DigitalReadSerial

1/Build a Mintronics: MintDuino

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

3.The circuit board is composed of 4 sets which are 16x2 LCD Shield, 3 pieces of Switch, 2

ENGR 40M Project 3c: Switch debouncing

TANGIBLE MEDIA & PHYSICAL COMPUTING INTRODUCTION TO ARDUINO

Update: Ver 1.3 Dec Arduino Learning Guide For Beginner Using. Created by Cytron Technologies Sdn Bhd - All Rights Reserved

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

Schedule. Sanford Bernhardt, Sangster, Kumfer, Michalaka. 3:10-5:00 Workshop: Build a speedometer 5:15-7:30 Dinner and Symposium: Group 2

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

analogwrite(); The analogwrite function writes an analog value (PWM wave) to a PWM-enabled pin.

IAS0430 MICROPROCESSOR SYSTEMS

ARDUINO LEONARDO ETH Code: A000022

ARDUINO YÚN MINI Code: A000108

ARDUINO M0 PRO Code: A000111

Arduino Internals. Dale Wheat. Apress

Arduino ADK Rev.3 Board A000069

Embedded Systems and Kinetic Art. CS5968: Erik Brunvand School of Computing. FA3800: Paul Stout Department of Art and Art History.

Logistics. Embedded Systems. Kinetic Art. This Class. Embedded Systems and Kinetic Art. Kinetic Art

CARTOOINO Projects Book

CS12020 (Computer Graphics, Vision and Games) Worksheet 1

Workshop on Microcontroller Based Project Development

Introduction to Arduino. Wilson Wingston Sharon

Introduction to Microcontrollers Using Arduino. PhilRobotics

Arduino Uno. Arduino Uno R3 Front. Arduino Uno R2 Front

The Big Idea: Background:

TA0297 WEMOS D1 R2 WIFI ARDUINO DEVELOPMENT BOARD ESP8266

Intro to Arduino. Zero to Prototyping in a Flash! Material designed by Linz Craig and Brian Huang

REQUIRED MATERIALS Epiphany-DAQ board Wire Jumpers Switch LED Resistors Breadboard Multimeter (if needed)

Smart Objects. SAPIENZA Università di Roma, M.Sc. in Product Design Fabio Patrizi

Microcontrollers for Ham Radio

Layad Circuits Arduino Basic Kit B. Content Summary

BASIC ARDUINO WORKSHOP. Mr. Aldwin and Mr. Bernardo

Megamark Processing 3.0 Setup Guide. Downloading and Installing Processing 3.0

Introduction to Arduino

Transcription:

PDF of this portion of workshop notes: http://goo.gl/jfpeym

Teaching Engineering Design with Student-Owned Digital and Analog Lab Equipment John B. Schneider Washington State University June 15, 2015

Overview 3/61

Overview 3/61 Concentrate on the digital, microcontroller part of Digilent s products: chipkit.

Overview 3/61 Concentrate on the digital, microcontroller part of Digilent s products: chipkit. Introduction to Digilent.

Overview 3/61 Concentrate on the digital, microcontroller part of Digilent s products: chipkit. Introduction to Digilent. What is chipkit?

Overview 3/61 Concentrate on the digital, microcontroller part of Digilent s products: chipkit. Introduction to Digilent. What is chipkit? Why use chipkit in the engineering curriculum?

Overview 3/61 Concentrate on the digital, microcontroller part of Digilent s products: chipkit. Introduction to Digilent. What is chipkit? Why use chipkit in the engineering curriculum? Introduction to chipkit with hands-on exercises.

Overview 3/61 Concentrate on the digital, microcontroller part of Digilent s products: chipkit. Introduction to Digilent. What is chipkit? Why use chipkit in the engineering curriculum? Introduction to chipkit with hands-on exercises. Keep discussion at introductory level: Material suitable for an introductory course on engineering design, independent of discipline.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level. World s leading supplier of programmable logic boards.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level. World s leading supplier of programmable logic boards. More than 1200 schools worldwide and 100,000 students/semester.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level. World s leading supplier of programmable logic boards. More than 1200 schools worldwide and 100,000 students/semester. More than 250,000 academic/demo boards/kits shipped.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level. World s leading supplier of programmable logic boards. More than 1200 schools worldwide and 100,000 students/semester. More than 250,000 academic/demo boards/kits shipped. Used in more than 90% of the world s top universities.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level. World s leading supplier of programmable logic boards. More than 1200 schools worldwide and 100,000 students/semester. More than 250,000 academic/demo boards/kits shipped. Used in more than 90% of the world s top universities. Previously concentrated efforts in higher education.

Digilent 4/61 www.digilentinc.com learn.digilentinc.com Founded in 2000 specifically to promote electrical and computer engineering education at the university level. World s leading supplier of programmable logic boards. More than 1200 schools worldwide and 100,000 students/semester. More than 250,000 academic/demo boards/kits shipped. Used in more than 90% of the world s top universities. Previously concentrated efforts in higher education. Now interested in also serving the needs of hobbyists, K-12 students, and non-traditional students (e.g., those involved in free online courses).

chipkit 5/61 chipkit denotes open-source microcontroller-based hardware and software.

chipkit 5/61 chipkit denotes open-source microcontroller-based hardware and software. Inspired by (and generally compatible with) Arduino.

chipkit 5/61 chipkit denotes open-source microcontroller-based hardware and software. Inspired by (and generally compatible with) Arduino. From arduino.cc, Arduino is: Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

chipkit 5/61 chipkit denotes open-source microcontroller-based hardware and software. Inspired by (and generally compatible with) Arduino. From arduino.cc, Arduino is: Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. From wikipedia.org, Arduino is: Arduino is a single-board microcontroller designed to make the process of using electronics in multidisciplinary projects more accessible.

What Is Engineering? 6/61

What Is Engineering? 6/61 What is a scientist?

What Is Engineering? 6/61 What is a scientist? What is an engineer?

What Is Engineering? 6/61 What is a scientist? What is an engineer? The scientist describes what is.

What Is Engineering? 6/61 What is a scientist? What is an engineer? The scientist describes what is. The engineer creates what never was. Theodore von Kármán

What Is Engineering? 6/61 What is a scientist? What is an engineer? The scientist describes what is. The engineer creates what never was. Theodore von Kármán Engineering is a creative process.

Microprocessor vs. Microcontroller Microprocessor: heart of most computers; the central processing unit (CPU). 7/61

Microprocessor vs. Microcontroller Microprocessor: heart of most computers; the central processing unit (CPU). Microcontroller: a CPU plus added systems such as on-board memory, analog-to-digital converters, peripheral interfaces, etc. 7/61

Microprocessor vs. Microcontroller Microprocessor: heart of most computers; the central processing unit (CPU). Microcontroller: a CPU plus added systems such as on-board memory, analog-to-digital converters, peripheral interfaces, etc. Microcontrollers are the heart of most embedded systems, i.e., systems or devices that perform (dedicated) computations, often with some time constraint. 7/61

Teaching/Engaging 8/61 To teach students you have to engage them.

Teaching/Engaging 8/61 To teach students you have to engage them. But how?

Teaching/Engaging 8/61 To teach students you have to engage them. But how? By imparting knowledge and teaching skills such that:

Teaching/Engaging 8/61 To teach students you have to engage them. But how? By imparting knowledge and teaching skills such that: The link between the knowledge and the application of that knowledge is clear.

Teaching/Engaging 8/61 To teach students you have to engage them. But how? By imparting knowledge and teaching skills such that: The link between the knowledge and the application of that knowledge is clear. The skills are directly relevant to exciting technologies (and good careers!).

Teaching/Engaging 8/61 To teach students you have to engage them. But how? By imparting knowledge and teaching skills such that: The link between the knowledge and the application of that knowledge is clear. The skills are directly relevant to exciting technologies (and good careers!). Students learn through project-based activities.

Physical Computing 9/61 Physical Computing: A framework for engaging students.

Physical Computing 9/61 Physical Computing: A framework for engaging students. Traditional computing involves the manipulation of data within the computer and displaying data (text, music, images, videos).

Physical Computing 9/61 Physical Computing: A framework for engaging students. Traditional computing involves the manipulation of data within the computer and displaying data (text, music, images, videos). Physical computing involves using a computer (microcontroller) to interact with the physical world through sensors and various output devices (lights, displays, motors, actuators, etc.).

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy.

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy. This describes ten disruptive technologies they believe could have a large impact by 2025 (only 12 years from now!).

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy. This describes ten disruptive technologies they believe could have a large impact by 2025 (only 12 years from now!). Arguably every one of these technologies will have engineers and/or computer scientists intimately involved in their development, deployment, operation, and maintenance.

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy. This describes ten disruptive technologies they believe could have a large impact by 2025 (only 12 years from now!). Arguably every one of these technologies will have engineers and/or computer scientists intimately involved in their development, deployment, operation, and maintenance. Examples: Internet of Things (network of low-cost sensors and actuators for decision making and process optimization).

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy. This describes ten disruptive technologies they believe could have a large impact by 2025 (only 12 years from now!). Arguably every one of these technologies will have engineers and/or computer scientists intimately involved in their development, deployment, operation, and maintenance. Examples: Internet of Things (network of low-cost sensors and actuators for decision making and process optimization). Advanced Robotics (enhanced dexterity, sensing, and intelligence).

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy. This describes ten disruptive technologies they believe could have a large impact by 2025 (only 12 years from now!). Arguably every one of these technologies will have engineers and/or computer scientists intimately involved in their development, deployment, operation, and maintenance. Examples: Internet of Things (network of low-cost sensors and actuators for decision making and process optimization). Advanced Robotics (enhanced dexterity, sensing, and intelligence). Autonomous and Near-Autonomous Vehicles.

Student Engagement: Exciting Technologies 10/61 In May 2013, the McKinsey Global Institute published Disruptive Technologies: Advances that will transform life, business, and the global economy. This describes ten disruptive technologies they believe could have a large impact by 2025 (only 12 years from now!). Arguably every one of these technologies will have engineers and/or computer scientists intimately involved in their development, deployment, operation, and maintenance. Examples: Internet of Things (network of low-cost sensors and actuators for decision making and process optimization). Advanced Robotics (enhanced dexterity, sensing, and intelligence). Autonomous and Near-Autonomous Vehicles. 3D Printing.

Multidisciplinary 11/61 The four technologies on the previous page all involve physical computing.

Multidisciplinary 11/61 The four technologies on the previous page all involve physical computing. Note that none of these technologies fit neatly into a discipline you would find at a typical university (nor within a curriculum at most high schools).

Multidisciplinary 11/61 The four technologies on the previous page all involve physical computing. Note that none of these technologies fit neatly into a discipline you would find at a typical university (nor within a curriculum at most high schools). These technologies definitely involve computer science, electrical engineering, and mechanical engineering.

Multidisciplinary 11/61 The four technologies on the previous page all involve physical computing. Note that none of these technologies fit neatly into a discipline you would find at a typical university (nor within a curriculum at most high schools). These technologies definitely involve computer science, electrical engineering, and mechanical engineering. They also combine various aspects of multiple foundational disciplines such as mathematics, physics, and material science/chemistry.

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment).

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE.

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free).

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free). Works on Mac, Windows, Linux.

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free). Works on Mac, Windows, Linux. Created with beginners in mind (easy to learn).

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free). Works on Mac, Windows, Linux. Created with beginners in mind (easy to learn). Programming done in C/C++.

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free). Works on Mac, Windows, Linux. Created with beginners in mind (easy to learn). Programming done in C/C++. C and C++: Two of the most common and important programming languages!

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free). Works on Mac, Windows, Linux. Created with beginners in mind (easy to learn). Programming done in C/C++. C and C++: Two of the most common and important programming languages! Used throughout academia and industry.

chipkit Programming 12/61 chipkit programming: Done using MPIDE (MultiPlatform Integrated Development Environment). Fork from the Arduino IDE. Completely open source (free). Works on Mac, Windows, Linux. Created with beginners in mind (easy to learn). Programming done in C/C++. C and C++: Two of the most common and important programming languages! Used throughout academia and industry. Especially common in embedded systems applications.

chipkit: Using It! 13/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

P1: MPIDE, Part 1 14/61 Installing MPIDE and running a sketch:

P1: MPIDE, Part 1 14/61 Installing MPIDE and running a sketch: Obtain from: http://chipkit.net/started/install-chipkit-software/ Or, from a thumbdrive!

P1: MPIDE, Part 1 14/61 Installing MPIDE and running a sketch: Obtain from: http://chipkit.net/started/install-chipkit-software/ Or, from a thumbdrive! Unzip the file (right click and select Extract file... ). Name of resulting folder will be same as file less.zip.

P1: MPIDE, Part 1 14/61 Installing MPIDE and running a sketch: Obtain from: http://chipkit.net/started/install-chipkit-software/ Or, from a thumbdrive! Unzip the file (right click and select Extract file... ). Name of resulting folder will be same as file less.zip. Connect cable from computer to chipkit board (a driver will be installed automatically causing LEDs to flash).

P1: MPIDE, Part 1 14/61 Installing MPIDE and running a sketch: Obtain from: http://chipkit.net/started/install-chipkit-software/ Or, from a thumbdrive! Unzip the file (right click and select Extract file... ). Name of resulting folder will be same as file less.zip. Connect cable from computer to chipkit board (a driver will be installed automatically causing LEDs to flash). Locate and double-click on mpide application within the extracted files (located in a sub-folder with same name as main folder).

P1: MPIDE, Part 2 15/61 After starting MPIDE, a window should appear similar to the one on the right.

P1: MPIDE, Part 2 15/61 After starting MPIDE, a window should appear similar to the one on the right. Rather than writing our own sketch, select File>Examples>1.Basics>Blink.

P1: MPIDE, Part 2 15/61 After starting MPIDE, a window should appear similar to the one on the right. Rather than writing our own sketch, select File>Examples>1.Basics>Blink. This sketch blinks an on-board LED.

P1: MPIDE, Part 2 15/61 After starting MPIDE, a window should appear similar to the one on the right. Rather than writing our own sketch, select File>Examples>1.Basics>Blink. This sketch blinks an on-board LED. We need to compile the sketch and transfer it to the chipkit board.

P1: MPIDE, Part 2 15/61 After starting MPIDE, a window should appear similar to the one on the right. Rather than writing our own sketch, select File>Examples>1.Basics>Blink. This sketch blinks an on-board LED. We need to compile the sketch and transfer it to the chipkit board. Go to Tools>Board>chipKIT and select chipkit Uno32 (or whatever board you have).

P1: MPIDE, Part 2 15/61 After starting MPIDE, a window should appear similar to the one on the right. Rather than writing our own sketch, select File>Examples>1.Basics>Blink. This sketch blinks an on-board LED. We need to compile the sketch and transfer it to the chipkit board. Go to Tools>Board>chipKIT and select chipkit Uno32 (or whatever board you have). Go to Tools>Serial Port and select the port connected to the chipkit board. (Windows: usually COM3 or higher. If unsure, can disconnect board and see which port disappears. Mac: something like /dev/tty.usbserial-ae00dnwc.)

P1: MPIDE, Part 3 16/61 Click the upload button to compile and transfer the code to the board. (Or, type Ctrl+U.)

P1: MPIDE, Part 3 16/61 Click the upload button to compile and transfer the code to the board. (Or, type Ctrl+U.) During the upload, two LEDS will flicker briefly.

P1: MPIDE, Part 3 16/61 Click the upload button to compile and transfer the code to the board. (Or, type Ctrl+U.) During the upload, two LEDS will flicker briefly. Then one LED should blink at two-second intervals (one second on; one second off).

Cost 17/61 Cost associated with using chipkit to do physical computing:

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free!

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free! $26.95 for chipkit Uno32.

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free! $26.95 for chipkit Uno32. Cost of parts for the project of interest (often pennies).

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free! $26.95 for chipkit Uno32. Cost of parts for the project of interest (often pennies). Must program using a computer.

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free! $26.95 for chipkit Uno32. Cost of parts for the project of interest (often pennies). Must program using a computer. (Laptop, desktop; Mac, Windows, Linux.)

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free! $26.95 for chipkit Uno32. Cost of parts for the project of interest (often pennies). Must program using a computer. (Laptop, desktop; Mac, Windows, Linux.) Cost is low enough that students can easily purchase their own hardware (less than the cost of textbook!).

Cost 17/61 Cost associated with using chipkit to do physical computing: Software is free! $26.95 for chipkit Uno32. Cost of parts for the project of interest (often pennies). Must program using a computer. (Laptop, desktop; Mac, Windows, Linux.) Cost is low enough that students can easily purchase their own hardware (less than the cost of textbook!). chipkit boards (and peripherals) available at www.digilentinc.com.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge. In contrast to text-based programming, many graphical programming tools exist: LabVIEW, Simulink, NXT-G, etc.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge. In contrast to text-based programming, many graphical programming tools exist: LabVIEW, Simulink, NXT-G, etc. Provide a different way of creating and thinking about a program.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge. In contrast to text-based programming, many graphical programming tools exist: LabVIEW, Simulink, NXT-G, etc. Provide a different way of creating and thinking about a program. Some can be used for embedded systems programming.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge. In contrast to text-based programming, many graphical programming tools exist: LabVIEW, Simulink, NXT-G, etc. Provide a different way of creating and thinking about a program. Some can be used for embedded systems programming. Often proprietary (additional cost).

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge. In contrast to text-based programming, many graphical programming tools exist: LabVIEW, Simulink, NXT-G, etc. Provide a different way of creating and thinking about a program. Some can be used for embedded systems programming. Often proprietary (additional cost). Both text-based and graphical programming have strengths and weaknesses.

Graphical vs. Text-Based Programming 18/61 C/C++: Have their roots in work from Bell Labs in the 1960 s. Text-based instructions. Produce clean code that can execute very quickly. Program statements unambiguously describe the flow of execution. Have a syntactic overhead that presents an initial learning challenge. In contrast to text-based programming, many graphical programming tools exist: LabVIEW, Simulink, NXT-G, etc. Provide a different way of creating and thinking about a program. Some can be used for embedded systems programming. Often proprietary (additional cost). Both text-based and graphical programming have strengths and weaknesses. Compelling reasons to be exposed to both!

chipkit: Using It! 19/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions.

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions.

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments.

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ).

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ). Each function has:

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ). Each function has: A return type (specifying what type of data the function returns; possibly void for nothing).

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ). Each function has: A return type (specifying what type of data the function returns; possibly void for nothing). A name (certain restrictions apply).

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ). Each function has: A return type (specifying what type of data the function returns; possibly void for nothing). A name (certain restrictions apply). An argument list (possibly empty).

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ). Each function has: A return type (specifying what type of data the function returns; possibly void for nothing). A name (certain restrictions apply). An argument list (possibly empty). A body where the statements that specify what the function does are given.

P2: C/C++ Fundamentals, Part 1 20/61 C/C++ sketches (programs) organized in terms of functions. C/C++ functions share many properties with mathematical functions. Information is passed in via arguments. Functions can return data (or be used for their side effects ). Each function has: A return type (specifying what type of data the function returns; possibly void for nothing). A name (certain restrictions apply). An argument list (possibly empty). A body where the statements that specify what the function does are given. Body is enclosed in braces.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 }

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().)

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches!

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches! Instead, a sketch must have a setup() function.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches! Instead, a sketch must have a setup() function. This is run once at the start of execution.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches! Instead, a sketch must have a setup() function. This is run once at the start of execution. It is used to initialize the chipkit board in whatever way is necessary.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches! Instead, a sketch must have a setup() function. This is run once at the start of execution. It is used to initialize the chipkit board in whatever way is necessary. Also, a sketch must have a loop() function.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches! Instead, a sketch must have a setup() function. This is run once at the start of execution. It is used to initialize the chipkit board in whatever way is necessary. Also, a sketch must have a loop() function. This is run repeatedly after setup() is run.

P2: C/C++ Fundamentals, Part 2 21/61 A function adheres to the following template: 1 return_type function_name(list, of, arguments) { 2 // This is a comment. 3 // Body of function enclosed in braces. 4 /* This is also a comment. It spans multiple lines. 5 Statements (instructions) in C/C++ must end with 6 a semicolon. */ 7 } C/C++ programs typically must have a function named main() which is where execution starts. (Other functions can be, and usually are, called from main().) There is no main() function in chipkit sketches! Instead, a sketch must have a setup() function. This is run once at the start of execution. It is used to initialize the chipkit board in whatever way is necessary. Also, a sketch must have a loop() function. This is run repeatedly after setup() is run. Execution only stops when power is removed.

P2: setup() and loop() 22/61 Flow of execution in a sketch: Execution starts here. Run once. setup() Run repeatedly. loop()

P2: setup() and loop() 22/61 Flow of execution in a sketch: Execution starts here. Run once. setup() Run repeatedly. loop() Both setup() and loop() are void functions (they don t return anything).

P2: setup() and loop() 22/61 Flow of execution in a sketch: Execution starts here. Run once. setup() Run repeatedly. loop() Both setup() and loop() are void functions (they don t return anything). Important: functions can be called from within other functions.

P2: setup() and loop() 22/61 Flow of execution in a sketch: Execution starts here. Run once. setup() Run repeatedly. loop() Both setup() and loop() are void functions (they don t return anything). Important: functions can be called from within other functions. When a function completes doing whatever it does, execution returns to the point in the sketch where it was called.

P2: setup() and loop() 22/61 Flow of execution in a sketch: Execution starts here. Run once. setup() Run repeatedly. loop() Both setup() and loop() are void functions (they don t return anything). Important: functions can be called from within other functions. When a function completes doing whatever it does, execution returns to the point in the sketch where it was called. There are many, many predefined functions that we can call!

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices.

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices. Inherently they operate with binary numbers where all data are a collection of ones and zeros.

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices. Inherently they operate with binary numbers where all data are a collection of ones and zeros. Instead of one and zero, sometime we call these different values HIGH and LOW, or perhaps True and False, or even on and off.

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices. Inherently they operate with binary numbers where all data are a collection of ones and zeros. Instead of one and zero, sometime we call these different values HIGH and LOW, or perhaps True and False, or even on and off. Computers use a voltage to represent different binary values.

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices. Inherently they operate with binary numbers where all data are a collection of ones and zeros. Instead of one and zero, sometime we call these different values HIGH and LOW, or perhaps True and False, or even on and off. Computers use a voltage to represent different binary values. Typically a voltage of zero is taken to correspond to zero/low/false and a non-zero voltage is taken to correspond to one/high/true.

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices. Inherently they operate with binary numbers where all data are a collection of ones and zeros. Instead of one and zero, sometime we call these different values HIGH and LOW, or perhaps True and False, or even on and off. Computers use a voltage to represent different binary values. Typically a voltage of zero is taken to correspond to zero/low/false and a non-zero voltage is taken to correspond to one/high/true. The chipkit boards operate at 3.3 Volts, i.e., voltages are either zero or 3.3 V.

P2: Digital Devices 23/61 Nearly all computers (and microcontrollers) are digital devices. Inherently they operate with binary numbers where all data are a collection of ones and zeros. Instead of one and zero, sometime we call these different values HIGH and LOW, or perhaps True and False, or even on and off. Computers use a voltage to represent different binary values. Typically a voltage of zero is taken to correspond to zero/low/false and a non-zero voltage is taken to correspond to one/high/true. The chipkit boards operate at 3.3 Volts, i.e., voltages are either zero or 3.3 V. Voltage is a measure of potential energy; basically how hard charges are being pushed to flow.

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler.

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler. Comments can also be enclosed between /* and */.

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler. Comments can also be enclosed between /* and */. Line 1 specifies that setup() is a void function (it doesn t return anything).

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler. Comments can also be enclosed between /* and */. Line 1 specifies that setup() is a void function (it doesn t return anything). setup() has an empty argument list (i.e., nothing appears between the parentheses) in line 1.

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler. Comments can also be enclosed between /* and */. Line 1 specifies that setup() is a void function (it doesn t return anything). setup() has an empty argument list (i.e., nothing appears between the parentheses) in line 1. The body of setup() is given in lines 2 to 4.

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler. Comments can also be enclosed between /* and */. Line 1 specifies that setup() is a void function (it doesn t return anything). setup() has an empty argument list (i.e., nothing appears between the parentheses) in line 1. The body of setup() is given in lines 2 to 4. Two of these lines are comments.

P2: Blink Sketch, Part 1 24/61 Here is the setup() function from the example Blink sketch: 1 void setup() { 2 // initialize the digital pin as an output. 3 // Pin 13 has an LED connected on most Arduino boards: 4 pinmode(13, OUTPUT); 5 } Anything from // to the end of the line is a comment and is ignored by the compiler. Comments can also be enclosed between /* and */. Line 1 specifies that setup() is a void function (it doesn t return anything). setup() has an empty argument list (i.e., nothing appears between the parentheses) in line 1. The body of setup() is given in lines 2 to 4. Two of these lines are comments. Connectors on the chipkit board are known as pins. Each pin has a number.

P2: Pins 25/61 The pins/connectors on a chipkit board are physically more like holes.

P2: Pins 25/61 The pins/connectors on a chipkit board are physically more like holes. On the board the pins are labeled with their corresponding numbers.

P2: Pins 25/61 The pins/connectors on a chipkit board are physically more like holes. On the board the pins are labeled with their corresponding numbers. Ground pin Digital pins Digital pin and its corresponding number Ground pins 5V source pin 3.3V source pin

P2: Pins 25/61 The pins/connectors on a chipkit board are physically more like holes. On the board the pins are labeled with their corresponding numbers. Ground pin Digital pins Digital pin and its corresponding number Ground pins 5V source pin 3.3V source pin Internally, pin 13 is tied to one of the LEDs (LD3).

P2: Pins 25/61 The pins/connectors on a chipkit board are physically more like holes. On the board the pins are labeled with their corresponding numbers. Ground pin Digital pins Digital pin and its corresponding number Ground pins 5V source pin 3.3V source pin Internally, pin 13 is tied to one of the LEDs (LD3). If pin 13 is HIGH, the LED is on.

P2: Pins 25/61 The pins/connectors on a chipkit board are physically more like holes. On the board the pins are labeled with their corresponding numbers. Ground pin Digital pins Digital pin and its corresponding number Ground pins 5V source pin 3.3V source pin Internally, pin 13 is tied to one of the LEDs (LD3). If pin 13 is HIGH, the LED is on. If pin 13 is LOW, the LED is off.

P2: Blink Sketch, Part 2 26/61 In setup() we call pinmode() to specify that pin 13 will be used for output.

P2: Blink Sketch, Part 2 26/61 In setup() we call pinmode() to specify that pin 13 will be used for output. pinmode(13, OUTPUT); // Set pin 13 to OUTPUT. pinmode() takes two arguments: the pin number and a value that specifies the mode.

P2: Blink Sketch, Part 2 26/61 In setup() we call pinmode() to specify that pin 13 will be used for output. pinmode(13, OUTPUT); // Set pin 13 to OUTPUT. pinmode() takes two arguments: the pin number and a value that specifies the mode. The mode is either INPUT or OUTPUT (predefined).

P2: Blink Sketch, Part 2 26/61 In setup() we call pinmode() to specify that pin 13 will be used for output. pinmode(13, OUTPUT); // Set pin 13 to OUTPUT. pinmode() takes two arguments: the pin number and a value that specifies the mode. The mode is either INPUT or OUTPUT (predefined). The loop() function in the Blink sketch is, essentially: 1 void loop() 2 { 3 digitalwrite(13, HIGH); // Turn on the LED. 4 delay(1000); // LED remains on for 1 second. 5 digitalwrite(13, LOW); // Turn off the LED. 6 delay(1000); // LED remains off for 1 second. 7 }

P2: Blink Sketch, Part 2 26/61 In setup() we call pinmode() to specify that pin 13 will be used for output. pinmode(13, OUTPUT); // Set pin 13 to OUTPUT. pinmode() takes two arguments: the pin number and a value that specifies the mode. The mode is either INPUT or OUTPUT (predefined). The loop() function in the Blink sketch is, essentially: 1 void loop() 2 { 3 digitalwrite(13, HIGH); // Turn on the LED. 4 delay(1000); // LED remains on for 1 second. 5 digitalwrite(13, LOW); // Turn off the LED. 6 delay(1000); // LED remains off for 1 second. 7 } digitalwrite() specifies the state of a pin (HIGH or LOW).

P2: Blink Sketch, Part 2 26/61 In setup() we call pinmode() to specify that pin 13 will be used for output. pinmode(13, OUTPUT); // Set pin 13 to OUTPUT. pinmode() takes two arguments: the pin number and a value that specifies the mode. The mode is either INPUT or OUTPUT (predefined). The loop() function in the Blink sketch is, essentially: 1 void loop() 2 { 3 digitalwrite(13, HIGH); // Turn on the LED. 4 delay(1000); // LED remains on for 1 second. 5 digitalwrite(13, LOW); // Turn off the LED. 6 delay(1000); // LED remains off for 1 second. 7 } digitalwrite() specifies the state of a pin (HIGH or LOW). delay() specifies an amount of delay in milliseconds.

Obtaining Help 27/61 To learn about predefined functions, and much, much more(!), in MPIDE go to Help>Reference.

Obtaining Help 27/61 To learn about predefined functions, and much, much more(!), in MPIDE go to Help>Reference. Yes, do it now!

Obtaining Help 27/61 To learn about predefined functions, and much, much more(!), in MPIDE go to Help>Reference. Yes, do it now! See what information you get for setup, HIGH, delay(), and/or digitalwrite().

Obtaining Help 27/61 To learn about predefined functions, and much, much more(!), in MPIDE go to Help>Reference. Yes, do it now! See what information you get for setup, HIGH, delay(), and/or digitalwrite(). QUIZ: Does the function pinmode() return anything?

chipkit: Using It! 28/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

1 5 1 5 P3: External LED Circuit 29/61 10 H 15 20 25 30 G F H G A A B B C C D D E E 10 15 20 25 30 F I I J J LED has a long leg and a short leg.

1 5 1 5 P3: External LED Circuit 29/61 H G F H G F 10 15 20 25 30 I A B C D E 10 15 I 20 J 25 J 30 LED has a long leg and a short leg. A B C D E Long leg is the anode (positive side) and must be attached to a pin (here, pin 3).

1 5 1 5 P3: External LED Circuit 29/61 H G F H G F 10 15 20 25 30 I I A B C D E 10 15 J 20 J 25 LED has a long leg and a short leg. 30 Long leg is the anode (positive side) and must be attached to a pin (here, pin 3). A B C D E Short leg is the cathode and connected to a 220 Ω resistor which is then connected to ground (0 V).

1 5 1 5 P3: External LED Circuit 29/61 H G F H G F 10 15 20 25 30 I I J A B C D E 10 15 J 20 LED has a long leg and a short leg. 25 Long leg is the anode (positive side) and must be attached to a pin (here, pin 3). 30 A B C D E Short leg is the cathode and connected to a 220 Ω resistor which is then connected to ground (0 V). Color bands on 220 Ω resistor: red, red, brown (and gold).

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number).

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here):

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here): Voltage and current.

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here): Voltage and current. Resistance and resistors.

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here): Voltage and current. Resistance and resistors. LED behavior (non-linear device).

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here): Voltage and current. Resistance and resistors. LED behavior (non-linear device). Why a resistor must be placed in series with an LED.

P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here): Voltage and current. Resistance and resistors. LED behavior (non-linear device). Why a resistor must be placed in series with an LED. How to connect elements (the use of wires) and the arrangement of electrical connections in a circuit breadboard.

1 5 1 5 P3: Blink External LED 30/61 To blink an external LED, we can use nearly the same sketch (just change LED pin number). But, now we must understand some basic circuit theory (which we won t get into here): Voltage and current. Resistance and resistors. LED behavior (non-linear device). Why a resistor must be placed in series with an LED. How to connect elements (the use of wires) and the arrangement of electrical connections in a circuit breadboard. 10 15 20 25 30 A A B B C C D D E F E F G H G H 10 15 20 25 30 I I J J Wire Wires connect these three nodes

P3: Breadboards 31/61 Underlying electrical connections in a typical breadboard look like this (dark gray bands are metal strips):

1 5 1 5 P3: Breadboards 31/61 Underlying electrical connections in a typical breadboard look like this (dark gray bands are metal strips): 10 15 10 20 15 25 20 30 25 A 30 A B B C C D D E F E F G H G H I I J J Strip of metal called a rail Strip of metal called a node "valley"

1 5 1 5 P3: Breadboards 31/61 Underlying electrical connections in a typical breadboard look like this (dark gray bands are metal strips): 10 15 10 20 15 25 20 30 25 A 30 A B B C C D D E F E F G H G H I I J J Strip of metal called a rail Strip of metal called a node "valley" Wires that are electrically connected are all at the same voltage (metal/wires have almost no resistance).

1 5 1 5 P3: Breadboards 31/61 Underlying electrical connections in a typical breadboard look like this (dark gray bands are metal strips): 10 15 10 20 15 25 20 30 25 A 30 A B B C C D D E F E F G H G H I I J J Strip of metal called a rail Strip of metal called a node "valley" Wires that are electrically connected are all at the same voltage (metal/wires have almost no resistance). To blink an external LED, we need to connect, in series, an LED and current limiting resistor between a pin and ground (0 V).

1 5 1 5 P3: External LED Circuit 32/61 10 15 20 25 30 F G D A B C 10 15 20 25 30 D E H F G E H I I J J(Repeat of earlier slide.) LED has a long leg and a short leg. Long leg is the anode (positive side) and must be attached to a pin (here, pin 3). A B C Short leg is the cathode and connected to a 220 Ω resistor which is then connected to ground (0 V). Color bands on 220 Ω resistor: red, red, brown (and gold).

Engineering in the 21st Century 33/61 As a university professor for 25 years, I have often told my students: Math is the language of engineering.

Engineering in the 21st Century 33/61 As a university professor for 25 years, I have often told my students: Math is the language of engineering. I no longer say this!

Engineering in the 21st Century 33/61 As a university professor for 25 years, I have often told my students: Math is the language of engineering. I no longer say this! I now tell them, As an engineer you have to be bilingual, understanding both mathematics and algorithmic problem solving.

Engineering in the 21st Century 33/61 As a university professor for 25 years, I have often told my students: Math is the language of engineering. I no longer say this! I now tell them, As an engineer you have to be bilingual, understanding both mathematics and algorithmic problem solving. Engineers must understand various aspects of programming and computer science.

Engineering in the 21st Century 33/61 As a university professor for 25 years, I have often told my students: Math is the language of engineering. I no longer say this! I now tell them, As an engineer you have to be bilingual, understanding both mathematics and algorithmic problem solving. Engineers must understand various aspects of programming and computer science. It has often been said that a person does not really understand something until after teaching it to someone else.

Engineering in the 21st Century 33/61 As a university professor for 25 years, I have often told my students: Math is the language of engineering. I no longer say this! I now tell them, As an engineer you have to be bilingual, understanding both mathematics and algorithmic problem solving. Engineers must understand various aspects of programming and computer science. It has often been said that a person does not really understand something until after teaching it to someone else. Actually a person does not really understand something until after teaching it to a computer, i.e., expressing it as an algorithm. Donald E. Knuth

chipkit: Using It! 34/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

P4: Button-Controlled LED Circuit 35/61 1 1 5 5 10 10 15 15 20 20 25 25 30 30 35 35 40 40 45 45 50 50 55 55 60 60 A A B B C C D D E E F F G G H H I I J J

P4: Button-Controlled LED 36/61 Next, add a button such that when it is pressed, a HIGH voltage (3.3 V) is present at one of the pins and when it is not pressed, a LOW voltage (0 V) is present.

P4: Button-Controlled LED 36/61 Next, add a button such that when it is pressed, a HIGH voltage (3.3 V) is present at one of the pins and when it is not pressed, a LOW voltage (0 V) is present. We can use the function digitalread() to determine the voltage present at the pin and then make a decision in our sketch whether or not to turn on the LED.

P4: Button-Controlled LED 36/61 Next, add a button such that when it is pressed, a HIGH voltage (3.3 V) is present at one of the pins and when it is not pressed, a LOW voltage (0 V) is present. We can use the function digitalread() to determine the voltage present at the pin and then make a decision in our sketch whether or not to turn on the LED. Create simple light switch.

P4: Button-Controlled LED 36/61 Next, add a button such that when it is pressed, a HIGH voltage (3.3 V) is present at one of the pins and when it is not pressed, a LOW voltage (0 V) is present. We can use the function digitalread() to determine the voltage present at the pin and then make a decision in our sketch whether or not to turn on the LED. Create simple light switch. To accomplish this, we need to understand logical constructs, relational operators, and the use of pull-down resistors (which we won t delve into here).

P4: Button-Controlled LED 36/61 Next, add a button such that when it is pressed, a HIGH voltage (3.3 V) is present at one of the pins and when it is not pressed, a LOW voltage (0 V) is present. We can use the function digitalread() to determine the voltage present at the pin and then make a decision in our sketch whether or not to turn on the LED. Create simple light switch. To accomplish this, we need to understand logical constructs, relational operators, and the use of pull-down resistors (which we won t delve into here). The previous slide provides the circuit layout and the following slides the associated sketch.

P4: Button-Controlled LED 36/61 Next, add a button such that when it is pressed, a HIGH voltage (3.3 V) is present at one of the pins and when it is not pressed, a LOW voltage (0 V) is present. We can use the function digitalread() to determine the voltage present at the pin and then make a decision in our sketch whether or not to turn on the LED. Create simple light switch. To accomplish this, we need to understand logical constructs, relational operators, and the use of pull-down resistors (which we won t delve into here). The previous slide provides the circuit layout and the following slides the associated sketch. Here pin 12 controls the LED and pin 7 detects the voltage from the button. Pull-down resistor of 10 kω: brown, black, orange (and gold).

P4: Button with Pull-Down Resistor 37/61 Button and resistor are in series between 3.3 V and 0 V. chipkit pin is attached to point between between button and resistor.

P4: Button with Pull-Down Resistor 37/61 Button and resistor are in series between 3.3 V and 0 V. chipkit pin is attached to point between between button and resistor.

P4: Button with Pull-Down Resistor 37/61 Button and resistor are in series between 3.3 V and 0 V. chipkit pin is attached to point between between button and resistor. When button not pushed, pin is LOW.

P4: Button with Pull-Down Resistor 37/61 Button and resistor are in series between 3.3 V and 0 V. chipkit pin is attached to point between between button and resistor. When button not pushed, pin is LOW.

P4: Button with Pull-Down Resistor 37/61 Button and resistor are in series between 3.3 V and 0 V. chipkit pin is attached to point between between button and resistor. When button not pushed, pin is LOW. When pushed, pin is HIGH.

P4: Button-Controlled LED 38/61 Sketch uses variables to provide meaningful labels for the pins. 1 const int leda = 12; // LED pin used for output. 2 const int btna = 7; // Button pin used for input. 3 4 void setup() { 5 pinmode(leda, OUTPUT); // Set the LED pin to OUTPUT. 6 pinmode(btna, INPUT); // Set the button pin to INPUT. 7 } 8 9 void loop() { 10 // Read and determine button A state. 11 if (digitalread(btna) == HIGH){ 12 digitalwrite(leda, HIGH); 13 } 14 else { 15 digitalwrite(leda, LOW); 16 } 17 }

P4: Button-Controlled LED Circuit 39/61 1 1 5 5 10 10 15 15 20 20 25 25 30 30 35 35 40 40 45 45 50 50 55 55 60 60 A A B B C C D D E E F F G G H H I I J J

Simulating vs. Doing 40/61 Something every child has said to a parent:

Simulating vs. Doing 40/61 Something every child has said to a parent: Look at what I made!

Simulating vs. Doing 40/61 Something every child has said to a parent: Look at what I made! Something almost no child has said to a parent:

Simulating vs. Doing 40/61 Something every child has said to a parent: Look at what I made! Something almost no child has said to a parent: Look at what I simulated.

Simulating vs. Doing 40/61 Something every child has said to a parent: Look at what I made! Something almost no child has said to a parent: Look at what I simulated. Building things is inherently more satisfying (engaging!) than simulating things.

Simulating vs. Doing 40/61 Something every child has said to a parent: Look at what I made! Something almost no child has said to a parent: Look at what I simulated. Building things is inherently more satisfying (engaging!) than simulating things. The following is definitely true: In theory there is no difference between theory and practice, but in practice there is! Attributed to several people

Simulating vs. Doing 40/61 Something every child has said to a parent: Look at what I made! Something almost no child has said to a parent: Look at what I simulated. Building things is inherently more satisfying (engaging!) than simulating things. The following is definitely true: In theory there is no difference between theory and practice, but in practice there is! Attributed to several people Building actual working physical systems enhances, reinforces, and extends the learning that is possible via simulation.

chipkit: Using It! 41/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

P5: Trainable Blinking LED 42/61

P5: Trainable Blinking LED 42/61 Use same circuit as before.

P5: Trainable Blinking LED 42/61 Use same circuit as before. Blink the LED.

P5: Trainable Blinking LED 42/61 Use same circuit as before. Blink the LED. On and off time is determined by a button push: duration the user pushes button dictates on and off time.

P5: Trainable Blinking LED 42/61 Use same circuit as before. Blink the LED. On and off time is determined by a button push: duration the user pushes button dictates on and off time. Must use a non-blocking delay to accomplish this!

P5: Trainable Blinking LED 42/61 Use same circuit as before. Blink the LED. On and off time is determined by a button push: duration the user pushes button dictates on and off time. Must use a non-blocking delay to accomplish this! Useful function: millis() which returns number of milliseconds since sketch started to execute.

P5: Trainable Blinking LED 42/61 Use same circuit as before. Blink the LED. On and off time is determined by a button push: duration the user pushes button dictates on and off time. Must use a non-blocking delay to accomplish this! Useful function: millis() which returns number of milliseconds since sketch started to execute. Useful programming construct: while(/* Conditional. */) {/* Statements. */} This repeatedly executes the code within braces (if any) while conditional within parentheses is true.

P5: Trainable Blinking LED 42/61 Use same circuit as before. Blink the LED. On and off time is determined by a button push: duration the user pushes button dictates on and off time. Must use a non-blocking delay to accomplish this! Useful function: millis() which returns number of milliseconds since sketch started to execute. Useful programming construct: while(/* Conditional. */) {/* Statements. */} This repeatedly executes the code within braces (if any) while conditional within parentheses is true. One way to do nothing while the button is pressed: while (digitalread(buttonpin) == HIGH) {}

P5: Trainable Blinking LED, Part 1/3 43/61 Sketch to create a trainable blinking LED. 1 int ledpin = 12; // Label Pin 12 ledpin. 2 int buttonpin = 7; // Label Pin 7 buttonpin. 3 4 // Initialize delay and start time. 5 int msdelay = 500; // 500 ms delay = 0.5 seconds. 6 unsigned int starttime = 0; // Time of last LED change. 7 int ledstate = LOW; 8 9 void setup() { 10 pinmode(buttonpin, INPUT); // Set buttonpin for input. 11 pinmode(ledpin, OUTPUT); // Set ledpin for output. 12 }

P5: Trainable Blinking LED, Part 2/3 44/61 1 void loop() { 2 starttime = millis(); // Time at start of loop. 3 // If the button is pressed "record" amount of delay. 4 if (digitalread(buttonpin) == HIGH) { 5 digitalwrite(ledpin, HIGH); // Turn on LED. 6 while (digitalread(buttonpin) == HIGH) {} 7 msdelay = (millis() - starttime); 8 9 } else { 10 // If button not pressed, blink the LED without blocking. 11. 12. 13.

P5: Trainable Blinking LED, Part 3/3 45/61 1 // If button not pressed, blink the LED without blocking. 2 while (digitalread(buttonpin) == LOW) { 3 if ((millis() - starttime) > msdelay) { 4 starttime = millis(); 5 if (ledstate == LOW) { 6 ledstate = HIGH; 7 } else { 8 ledstate = LOW; 9 } 10 // Set LED in accordance with ledstate variable. 11 digitalwrite(ledpin, ledstate); 12 } 13 } 14 } 15 }

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED:

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED: Sometimes it doesn t work!

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED: Sometimes it doesn t work! Sometimes when the user releases the button the LED glows continuously with a dim glow.

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED: Sometimes it doesn t work! Sometimes when the user releases the button the LED glows continuously with a dim glow. Why???

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED: Sometimes it doesn t work! Sometimes when the user releases the button the LED glows continuously with a dim glow. Why??? Button bounce.

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED: Sometimes it doesn t work! Sometimes when the user releases the button the LED glows continuously with a dim glow. Why??? Button bounce. Voltage transition is not necessarily a smooth thing.

P5: Trainable Blinking LED 46/61 Wonderful thing about the trainable blinking LED: Sometimes it doesn t work! Sometimes when the user releases the button the LED glows continuously with a dim glow. Why??? Button bounce. Voltage transition is not necessarily a smooth thing. Great opportunity to explore need to address real world issues that are often abstracted away in the classroom.

chipkit: Using It! 47/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

P6: Serial Monitor 48/61 Debugging sketches using MPIDE can be challenging!

P6: Serial Monitor 48/61 Debugging sketches using MPIDE can be challenging! Often helpful to display information on the computer that is communicated using the Serial Monitor.

P6: Serial Monitor 48/61 Debugging sketches using MPIDE can be challenging! Often helpful to display information on the computer that is communicated using the Serial Monitor. Once a sketch has started running, click on window. to open the Serial Monitor

P6: Serial Monitor 48/61 Debugging sketches using MPIDE can be challenging! Often helpful to display information on the computer that is communicated using the Serial Monitor. Once a sketch has started running, click on to open the Serial Monitor window. A window should open similar to the following:

P6: Serial Monitor 49/61 Must initialize the serial connection in the setup() function, e.g, make the following call in setup(): Serial.begin(9600)}

P6: Serial Monitor 49/61 Must initialize the serial connection in the setup() function, e.g, make the following call in setup(): Serial.begin(9600)} Note that Serial is a global object that has already been created for you.

P6: Serial Monitor 49/61 Must initialize the serial connection in the setup() function, e.g, make the following call in setup(): Serial.begin(9600)} Note that Serial is a global object that has already been created for you. Generate output using class functions Serial.print() (produces no line terminator)

P6: Serial Monitor 49/61 Must initialize the serial connection in the setup() function, e.g, make the following call in setup(): Serial.begin(9600)} Note that Serial is a global object that has already been created for you. Generate output using class functions Serial.print() (produces no line terminator) or Serial.println() (produces newline terminator).

P6: Serial Monitor 49/61 Must initialize the serial connection in the setup() function, e.g, make the following call in setup(): Serial.begin(9600)} Note that Serial is a global object that has already been created for you. Generate output using class functions Serial.print() (produces no line terminator) or Serial.println() (produces newline terminator). Be sure to see what the Help reference manual has to say about these!

P6: Serial Monitor 50/61 Simple example: display an integer count starting from 1 with a half second delay between increments.

P6: Serial Monitor 50/61 Simple example: display an integer count starting from 1 with a half second delay between increments. 1 int count = 0; 2 3 void setup() 4 { 5 Serial.begin(9600); 6 } 7 8 void loop() { 9 count = count + 1; 10 Serial.print(count); 11 Serial.print(" "); 12 delay(500); 13 }

chipkit: Using It! 51/61 Project 1: Installing and running MPIDE. Installing a sketch on a chipkit board. Project 2: Blink an internal LED. Digital systems. Basic C/C++ syntax. Structure of a sketch. Project 3: Blink an external LED. Basic electric principles. Breadboards. Project 4: Button-controlled LEDs. Pull-up and pull-down resistors. Obtaining input. Logical operations. Project 5: A Trainable Blinking LED. Nonblocking delay. Button bounce. Project 6: The Serial Monitor. Serial communication. Debouncing. Project 7: Introduction to logic (controlling multiple LEDs). Truth tables. Project 8: Analog Output (a breathing LED). Pulse width modulation (PWM). Analog to digital conversion.

P7: Logic (Circuit) 52/61 1 1 5 5 10 10 15 15 20 20 25 25 30 30 35 35 40 40 45 45 50 50 55 55 60 60 A A B B C C D D E E F F G G H H I I J J