IOT Design: An Embedded System Overview MicroControllers

Slides:



Advertisements
Similar presentations
Khaled A. Al-Utaibi Interfacing an LED The Light Emitting Diode (LED) Applications DC Characteristics & Operation Interfacing to.
Advertisements

EMS1EP Lecture 6 Digital Inputs
Electrical team Arduino tutorial I BY: JOSHUA arduini
Microcontroller Fundamentals
Lab7: Introduction to Arduino
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Programming Microcontrollers B. Furman 19MAR2011.
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Intro to Programming and Microcontrollers. Activity Group into pairs and sit back-to-back. Pick one person who is going to draw. The other person will.
Programming the ATmega16
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Embedded Programming and Robotics
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Lecture 9: Microcontrollers – part 1 BJ Furman 29OCT2012.
chipKit Sense Switch & Control LED
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Cascade switching of an LED EAS 199B Winter 2013.
Franz Duran INTRODUCTION TO A RDUINO PROGRAMMING & INTERFACING Engr. Franz Duran, MEP-ECE RapidSignal Electronics.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Lecture 7: Microcontrollers & I/O Bryan Burlingame 14 October 2015.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
Warmup – 16FEB2012 This one is for practice. I have paper if you need it. Suppose there are eight, single-pole, single-throw (SPST) switches connected.
ECE Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
Microcontrollers, Microcomputers, and Microprocessors
Arduino libraries Datatekniker Udvidet hardware/software.
Microcontroller basics Embedded systems for mortals.
Week 5: Microcontrollers & Flow Control Bryan Burlingame 2 March 2016.
Robotics Grant Agreement No LLP UK-LEONARDO-LMP Project acronym: CLEM Project title: Cloud services for E-Learning in Mechatronics Technology.
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Application Case Study Christmas Lights Controller
Having fun with code, using Arduino in a middle school CS classroom
Arduino.
Getting Started: Building & Programming
IOT Design: An Embedded System Overview Definitions DAY
Week 4: Microcontrollers & Flow Control
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Microcontroller basics
UTA010 : Engineering Design – II
Cascade switching of an LED
Welcome to Arduino A Microcontroller.
Get Your Project Started with Arduino
UCD ElecSoc Robotics Club 2017/2018
INC 161 , CPE 100 Computer Programming
Introduction to Arduino Microcontrollers
Introduction to Arduino Microcontrollers
AQA GCSE 6 Systems approach to designing Design and Technology 8552
Continuing with LED’s and Arduino
IoT Programming the Particle Photon.
Arduino 101 Credit(s):
using the Arduino to make LEDs flash
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Welcome to Digital Electronics using the Arduino Board
Copier Jam Detector Design Problem
Combinational Logic - An Overview
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Multiplexing seven-segment displays
Arduino Uno circuit basics
Setting up a basic program with Arduino
Introduction to Arduinos
SAURABH GINGADE.
Electronic systems 7.
Combinational Logic - An Overview
Arduino程式範例.
Interrupts.
Presentation transcript:

IOT Design: An Embedded System Overview MicroControllers NETW 1010 IOT Design: An Embedded System Overview MicroControllers Dr. Eng. Amr T. Abdel-Hamid Fall 2016

Handling electronics - How NOT to Do It! Improper Handling - NEVER!!!

Handling electronics - The Proper Way Proper Handling - by the edges!!! Wash your hands after handling the boards. Solder contains lead (not RoHS compliant yet!)

ATmega328 Microcontroller Pin number Pin name Special function

Microcontroller Ports and Pins The communication channels through which information flows into or out of the microcontroller Ex. PORTB Pins PB0 – PB7 May not be contiguous Often bi-directional C

Port Pin Data Directionality Input When you want to take information from the external world (sensors) into the MCU Output When you want to change the state of something outside the MCU (turn a motor on or off, etc.) Pins default to input direction on power-up or reset Your program can set or change the directionality of a pin at any time This is really important!

ATmega328 Block Diagram Input Output

Setting the Pin Data Direction Arduino pinMode(pin_no., dir) Ex. Make Arduino pin 3 (PD3) an output pinMode(3, OUTPUT); pinMode(PIN_D3, OUTPUT); // with me106.h Note: one pin at a time Suppose you wanted Arduino pins 3, 5, and 7 (PD3, PD5, and PD7) to be outputs? Is there a way to make them all outputs at the same time? Yes! Answer coming later…

Pin Voltages Microcontrollers are fundamentally digital devices. For digital IO pins: Information is ‘coded’ in two discrete states: HIGH or LOW (logic: 1 or 0) Voltages TTL 5 V (for HIGH) 0 V (for LOW) 3.3 V CMOS 3.3 V (for HIGH)

Pin Used as an Output Turn on an LED, which is connected to pin Arduino pin 0 (PD0) (note the resistor!) What should the data direction be for pin 0 (PD0)? pinMode(____, ____); Turn on the LED digitalWrite(PIN_LED,HIGH); Turn off the LED digitalWrite(PIN_LED,LOW); ATmega328 Arduino pin 0 (PD0) Explain circuit schematic symbol and behavior of an LED Sources for parts: HSC Electronics (Ryder St. near Lawrence and Central) 10% discount with student ID; Electronics Flea Market (coming on March 8, 2014); Jameco; DigiKey; Avnet; Mouser; Adafruit; SparkFun; Seeed; NKC; eBay pinMode(0,OUTPUT);

Pins as Inputs and Pull-up Resistors - 1 Using a switch as a sensor Ex. Seat belt sensor Detect the switch state What should the data direction be for Arduino pin 3 (PD3)? pinMode(____, ____); What will the voltage be on PD3 when the switch is closed? What will the voltage be on PD3 when the switch is open? Indeterminate! ATmega328 Arduino pin 3 (PD3) SPST Schematic symbol for the switch is a single-pole, single-throw (SPST). Poles are the number of separate circuits controlled by the switch. Throws are the number of separate contacts that the movable element can mate with. pinMode(3, INPUT); momentary

Pins as Inputs and Pull-up Resistors - 2 Switch as a sensor, cont. Make the voltage on the pin determinate by turning on the pull-up resistor for PD3 Assuming PD3 is an input: digitalWrite(PIN_SWITCH,HIGH); turns on the “pull-up” resistor pinMode(PIN_SWITCH,INPUT_PULLUP); What will the voltage on PD3 be when the switch is open? VTG What will the voltage on PD3 be when the switch is closed? ATmega328 VTG= +5V 1 PD3 To here 9/4/12

Pins as Inputs and Pull-up Resistors - 3 Switch as a sensor, cont. To turn off the pull-up resistor Assuming PD3 is an input: digitalWrite(PIN_SWITCH,LOW); turns the “pull-up” resistor off ATmega328 PD3 VTG= +5V 1 Refer them to the schematic of the PortMaster board, which they are building.

Pins as Inputs and Pull-up Resistors - 4 Possibility of ‘weak drive’ when pull-up resistor is turned on Pin set as an input with a pull-up resistor turned on can source a small current Remember this! ATmega328 PD3 VTG= +5V 1 iweak

Example 1 Make Arduino pins 3, 5, and 7 (PD3, PD5, and PD7) to be outputs Arduino approach Alternate approach pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(7, OUTPUT); DDRD = 0b10101000; or DDRD = 0xA8; Or if me106.h is used: pinMode(PIN_D3, OUTPUT); pinMode(PIN_D5, OUTPUT); pinMode(PIN_D7, OUTPUT); DDRD | = 1<<PD7 | 1<<PD5 | 1<<PD3; More on this coming soon!

Example 2 Make pins Arduino pins 0 and 1 (PD0 and PD1) inputs, and turn on pull-up resistors Arduino approach Alternate approach pinMode(0, INPUT); pinMode(1, INPUT); digitalWrite(0, HIGH); digitalWrite(1, HIGH); DDRD = 0; // all PORTD pins inputs PORTD = 0b00000011; or PORTD = 0x03; or better yet: Or if me106.h is used: pinMode(PIN_D0, INPUT); pinMode(PIN_D1, INPUT); digitalWrite(PIN_D0, HIGH); digitalWrite(PIN_D1, HIGH); DDRD & = ~(1<<PD1 | 1<<PD0); PORTD | = (1<<PD1 | 1<<PD0); More on this coming soon!

Structure of an Arduino Program /* Blink - turns on an LED for DELAY_ON msec, then off for DELAY_OFF msec, and repeats BJ Furman rev. 1.1 Last rev: 22JAN2011 */ #define LED_PIN 13 // LED on digital pin 13 #define DELAY_ON 1000 #define DELAY_OFF 1000 void setup() { // initialize the digital pin as an output: pinMode(LED_PIN, OUTPUT); } // loop() method runs forever, // as long as the Arduino has power void loop() digitalWrite(LED_PIN, HIGH); // set the LED on delay(DELAY_ON); // wait for DELAY_ON msec digitalWrite(LED_PIN, LOW); // set the LED off delay(DELAY_OFF); // wait for DELAY_OFF msec An arduino program == ‘sketch’ Must have: setup() loop() configures pin modes and registers runs the main body of the program forever like while(1) {…} Where is main() ? Arduino simplifis things Does things for you This slide is meant as a quick overview of an Arduino sketch. We’ll unpack and describe the pieces in more detail later. Think of setup() as what you would do when you first get in a rental car or a car you have borrowed from a friend: adjust the mirrors, adjust the steering wheel, the seats, change the stereo channel settings, etc. The car can be driven by anyone, but everyone likes to customize it for their comfort. main() {    init();    setup();    while (1)       loop(); } And the reason that they do it this way is so it's guaranteed that init() gets called, which is critical for Arduino initialization.

Digital IO – Practice 1 ‘Reading a pin’ Write some lines of C code for the Arduino to determine a course of action if the seat belt has been latched (switch close). If latched, the ignition should be enabled through a call to a function ig_enable(). If not latched, the ignition should be disabled through a call to a function ig_disable() Write pseudocode first ATmega328 PD3 Assumes D3 is set as an input and pull-up resistor is turned on. Work up as an in-class active learning exercise. Problem statement: “Write a short program that calls a function, ig_enable() if the seat belt is latched or a function ig_disable() if the seatbelt is not latched.” If latched, then call function ig_enable() If not latched then call function ig_disabled()

Digital IO – Practice 1 Pseudocode ‘Reading a pin’ Pseudocode: Set up PD3 as an input Turn on PD3 pull-up resistor Read voltage on Arduino pin 3 (PIN_D3) IF PIN_D3 voltage is LOW (latched), THEN call function ig_enable() ELSE call function ig_disable() ATmega328 PD3 VTG= +5V 1 Assumes D3 is set as an input and pull-up resistor is turned on. Work up as an in-class active learning exercise. Problem statement: “Write a short program that calls a function, ig_enable() if the seat belt is latched or a function ig_disable() if the seatbelt is not latched.”

Digital IO – Practice 1 Code ‘Reading a pin’ Pseudocode: Set up PD3 as an input Turn on PD3 pull-up resistor Read voltage on Arduino pin 3 (PIN_D3) IF PIN_D3 voltage is LOW (latched), THEN call function ig_enable() ELSE call function ig_disable() ATmega328 PD3 VTG= +5V 1 #define PIN_SWITCH 3 #define LATCHED LOW pinMode(PIN_SWITCH,INPUT_PULLUP); belt_state = digitalRead(PIN_SWITCH); if (belt_state == LATCHED) { ig_enable(); } else { ig_disabled(); } One way  (snippet, not full program) Assumes D3 is set as an input and pull-up resistor is turned on. Work up as an in-class active learning exercise. Problem statement: “Write a short program that calls a function, ig_enable() if the seat belt is latched or a function ig_disable() if the seatbelt is not latched.”

Digital IO – Practice 2 ‘Reading from and writing to a pin’ Write some lines of C code for the Arduino to turn on a lamp (PD2) and buzzer (PD3) if the key is in the ignition (PD0 closed), but seat belt is not latched (PD1 open) (diagram shows only one of the two switches, but both are similar) Pseudocode first ATmega328 PD0, PD1 PD2 PD3 Set up data direction of pins Make PD0 and PD1 inputs Turn on pull up resistors for PD0 and PD1 Make PD2 and PD3 outputs Loop forever IF key is in ignition THEN IF belt is latched, THEN Turn off buzzer Turn off lamp ELSE Turn on lamp Turn on buzzer

Digital IO – Practice 2 Pseudocode Set up data direction of pins Make PD0 and PD1 inputs Turn on pull up resistors for PD0 and PD1 Make PD2 and PD3 outputs Loop forever IF key is in ignition THEN IF belt is latched, THEN Turn off buzzer Turn off lamp ELSE Turn on lamp Turn on buzzer ATmega328 PD0, PD1 VTG= +5V 1 PD2 PD3 Arduino style Note #define for state of switches – an Abstraction

Digital IO – Practice 2 (Arduino style code) #define PIN_IGNITION 0 #define PIN_SEATBELT 1 #define PIN_LED 2 #define PIN_BUZZER 3 #define SEATBELT_LATCHED LOW #define KEY_IN_IGNITION LOW #define LED_ON HIGH #define LED_OFF LOW #define BUZZER_ON HIGH #define BUZZER_OFF LOW void setup() { pinMode(PIN_IGNITION, INPUT_PULLUP); // key switch pinMode(PIN_SEATBELT, INPUT_PULLUP); // belt latch switch pinMode(PIN_LED, OUTPUT); // lamp pinMode(PIN_BUZZER, OUTPUT); // buzzer } void loop() { /* see next page for code */} ATmega328 PD0, PD1 VTG= +5V 1 PD2 PD3 Arduino style Note #define for state of switches – an Abstraction. Deals with the condition as a concept rather than just a number.

Digital IO – Practice 2 (Arduino style code) /* see previous page for code before loop() */ void loop() { int key_state = digitalRead(PIN_IGNITION); int belt_state = digitalRead(PIN_SEATBELT); if (key_state == KEY_IN_IGNITION) if (belt_state == SEATBELT_LATCHED) digitalWrite(PIN_BUZZER, BUZZER_OFF); digitalWrite(PIN_LED, LED_OFF); } else // key is in ignition, but seatbelt NOT latched digitalWrite(PIN_BUZZER, BUZZER_ON); digitalWrite(PIN_LED, LED_ON); else // key is NOT in ignition ATmega328 PD0, PD1 VTG= +5V 1 PD2 PD3 Arduino style Note #define for state of switches – an Abstraction. Deals with the condition as a concept rather than just a number.

Assignment 1 Use protus Software to build a knight rider light

http://www. instructables http://www.instructables.com/tag/type-id/category-technology/channel-arduino/ https://www.arduino.cc/ https://www.arduino.cc/en/Reference/HomePage