Topics and Techniques for Week 1 Lab

Slides:



Advertisements
Similar presentations
Sensing and Control.
Advertisements

EMS1EP Lecture 6 Digital Inputs
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
EMS1EP Lecture 8 Pulse Width Modulation (PWM)
Lab7: Introduction to Arduino
Lecture 17: Analog to Digital Converters Lecturers: Professor John Devlin Mr Robert Ross.
IR Control Materials taken from a variety of sources including IR Remote for the Boe-Bot by Andy Lindsay.
Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.
Physics 124: Lecture 2 Topics and Techniques for Week 1 Lab.
Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically.
Digital I/O Connecting to the Outside World
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Physics 120B: Lecture 2 Topics and Techniques for Week 1 Lab.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Embedded Programming and Robotics
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
Week 10 Today 1.Homework presentations and critique. 2.Review digital and analog inputs. 3.DIY - jumpers, soldering etc.
The Basic Stamp Instruction Set Architecture. The Microprocessor A microprocessor is a computer that typically has an architecture that is well suited.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Introduction to the Arduino
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Pulse Width Modulation (PWM). 100% Pulse Width Modulation (PWM) 0% On the chipKIT there are 490 periods per second. Use analogWrite(pin, value) to control.
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)
CSCI1600: Embedded and Real Time Software Lecture 14: Input/Output II Steven Reiss, Fall 2015.
Analog/Digital Conversion
Microcontrollers, Microcomputers, and Microprocessors
Rebecca Bruce and Susan Reiser, May 2015 Analog Input and Output.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
Embedded systems and sensors 1 Part 2 Interaction technology Lennart Herlaar.
Electronic instrumentation Digitization of Analog Signal in TD
Application Case Study Christmas Lights Controller
BM-305 Mikrodenetleyiciler Güz 2016 (3. Sunu)
Outline Introduction to digital-to-analog converter (DAC)
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Val Manes Department of Math & Computer Science
Microcontroller basics
AS Computer Studies Finite State Machines 1.
Arduino - Introduction
Memory Units Memories store data in units from one to eight bits. The most common unit is the byte, which by definition is 8 bits. Computer memories are.
BM-305 Mikrodenetleyiciler Güz 2017 (3. Sunu)
IR Control Materials taken from a variety of sources including IR Remote for the Boe-Bot by Andy Lindsay.
How to avoid catching things on fire.
Week 6: Microcontrollers II
IoT Programming the Particle Photon.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
EET 2261 Unit 14 INCOMPLETE Analog-to-Digital Conversion (ADC) & Digital-to-Analog Conversion (DAC) Read. Homework #13 and Lab #13 due next week. Quiz.
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Basic Electronics Part Two: Electronic Components.
Arduino programs Arduino toolchain Cross-compilation Arduino sketches
Chapter 1 Introduction of Arduino
Coding Concepts (Data- Types)
Guest Lecture by David Johnston
Sensors and actuators Sensors Resistive sensors
CSCI1600: Embedded and Real Time Software
Digital INPUTS/OUTPUTS and interrupts
UNIT 7: INFRARED SENSORS
UNIT 11: RC-SERVOMOTOR CONTROL
UNIT 5 Analog signals.
Arduino Uno circuit basics
CSCI1600: Embedded and Real Time Software
Setting up a basic program with Arduino
Introduction to Arduinos
UNIT 7: INFRARED SENSORS
Interrupts.
Chapter 1: Creating a Program.
Presentation transcript:

Topics and Techniques for Week 1 Lab Physics 124: Lecture 2 Topics and Techniques for Week 1 Lab

Week 1 Lab has 4 Exercises Blinking an LED in a Morse Code pattern Modulating LED brightness via PWM Using a switch to toggle LED and set brightness Analog input, reading a photocell and possibly doing something about it Note that the last two constitute miniature versions of the final project sense something in the real world; make some decisions accordingly; manipulate something in the real world in response These tasks largely follow from the Getting Started book Phys 124: Lecture 2

LED hookup The output of Arduino digital I/O pins will be either 0 or 5 volts An LED has a diode-like I-V curve Can’t just put 5 V across it’ll blow, unless current is limited Put resistor in series, so ~2.5 V drop across each 250 W would mean 10 mA 10 mA is pretty bright Phys 124: Lecture 2

Blink Function (Subroutine) For complex blink patterns, it pays to consolidate blink operation into a function Now call with, e.g., blink(600,300) Note function definition expects two integer arguments LED is assumed to be global variable (defined outside of loop) void blink(int ontime, int offtime) { // turns on LED (externally defined) for ontime ms // then off for offtime ms before returning digitalWrite(LED, HIGH); delay(ontime); digitalWrite(LED, LOW); delay(offtime); } Phys 124: Lecture 2

Blink Constructs For something like Morse Code, could imagine building functions on functions, like Note use of #define to specify duration of dot and therefore overall cadence: change in one place! #define DOTDUR 200 void dot() // dot, plus gap { blink(DOTDUR,DOTDUR); } void dash() // dash, plus gap { blink(3*DOTDUR,DOTDUR); } void letterspace() // aim for gap of 3 { delay(2*DOTDUR); } // already have one void wordspace() // aim for gap of 7 { delay(4*DOTDUR); } // already have three Phys 124: Lecture 2

Morse, continued And then perhaps letter functions: You could then spell out a word pretty easily like: Once you have a library of all the letters, it would be very simple to blink out anything you wanted could even cleverly Morse-out string, like “HELLO” void morse_s() { dot(); dot(); dot(); letterspace(); } void morse_o() { dash(); dash(); dash(); letterspace(); } morse_s(); morse_o(); wordspace(); Phys 124: Lecture 2

Pulse Width Modulation A “poor man’s” analog output can be synthesized out of a digital (0−5 V) signal by pulsing at variable duty cycle the time average voltage can then be anything between 0 and 5 V Arduino provides analogWrite(pin, value), valid for 6 of the 14 digital I/O pins on the Uno value is a number from 0 to 255 (one byte) For controlling LED brightness, the fraction of time in the ON state determines perceived brightness For other applications, may want capacitor to average (smooth) out the frenzied pulse sequence Phys 124: Lecture 2

PWM, Visually At right, pulse period denoted by green markers Can go from always LOW (0% duty cycle) to always HIGH (100% duty cycle) or anything in between, in 255 steps Can change period, if needed though only among limited selection of options Phys 124: Lecture 2 low pass filter can smooth out

Switches & Debouncing Switches come in a dizzying variety SPST Switches come in a dizzying variety normally open (NO), normally closed (NC) applies to single throw, typically single pole (SP), double pole (DP), etc. how many inputs to the switch single throw (ST), double throw (DT), etc. how many contacts each input may make DT can also come in CO variety: center open The Arduino kit button is NO, SPST it is normally open, one input (shared two pins), one output (shared two pins) But switches are not as simple as you think transition from open to closed can be erratic, random, fast oscillation, bouncing many times between states before settling SPDT DPST DPDT input side Phys 124: Lecture 2

Typical Bounce from softsolder.com On the tens of milliseconds timescale, a switch can actually go through any number of transitions Each time will look completely different Idea is to catch first transition, then hold off until you’re sure things have settled out Phys 124: Lecture 2

Delay Can Save the Day A fast microprocessor looking for switch transitions can catch all these bounces, as if you had pressed the button many times in fast succession this is seldom the behavior we want Inserting a delay gives the physical switch time to settle out something like 50−100 ms is usually good; faster than you can intentionally press twice (see dt_pair) Often use hardware solution too, with flip-flops lock in first edge Will also be relevant when we get to interrupts Phys 124: Lecture 2

Thinking Through Complex Logic In the dimmer exercise, it’s tough to keep track of the states Tendency to want to grasp entire scheme at once Brains don’t often work that way break it down to pieces you understand: divide & conquer ask yourself questions throughout the process Do I just need to know the state of the button, or catch change? If catching a change, what am I comparing against? Do I need a variable to keep track of a previous state? If so, when do I store the “old” value? If the button has just been pressed, what should I do? Does the answer depend on the LED state? Then do I need a variable to track this? (and the list goes on!) Phys 124: Lecture 2

Analog to Digital Conversion (ADC) Computers are digital, while the physical world is analog Converting voltage (analog value expressed electrically) into a digital number is a fundamental task in computer/world interface Internally, the processor is doing a “guess and check” approach from most significant bit (MSB) to LSB Arduino Uno has six analog inputs, turning each into a 10-bit number, 0..1023 measure 0−5 V range to 0.1%, or 5 mV precision This is your key portal into using sensors Phys 124: Lecture 2

Assignments/Announcements First week exercises due Tue/Wed, 1-17/18 by 2PM depends on whether you are in Tue or Wed lab session can drop in slot on TA room in back of MHA 3544 expect code printout (can be common to group), and some paragraphs from each group member as to contribution: how do we know you did something and learned? TA office hours: Clayton M 3-4 PM; Tu 1-2 PM Caleb M 2-3 PM; F 10-11 AM Phys 124: Lecture 2