Microcontroller basics Embedded systems for mortals.

Slides:



Advertisements
Similar presentations
Intermediate Electronics and Lilypad Where Electronics Meet Textiles Workshop with Lynne Bruning and Troy Robert Nachtigall Sponsored by Spark Fun and.
Advertisements

Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
How to use Arduino By: Andrew Hoffmaster.
Digital & Analog Inputs. Review Fundamental parts of an Arduino program are … Setting output types using pinMode. Declaring variables Can write a digital.
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
Intro to Arduino with LilyPad Make a MakerSpace, Artisan’s Asylum Linz Craig, Chris Taylor, Mike Hord & Joel Bartlett.
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.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
PROGRAMMING WITH ARDUINO. Arduino An open-source hardware platform based on an Atmel AVR 8-bit microcontroller and a C++ based IDE Over boards.
Arduino Part 1 Topics: Microcontrollers Programming Basics: structure and variables Digital Output Analog to Digital Conversion.
Basic Circuits – Lab 2 Arduino and Sensors
Image of Arduino. Arduino discussion Address issues with circuit walk-through – Electricity, Programming, Arduino Concepts Work on BeatTable (next week)
chipKit Sense Switch & Control LED
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Franz Duran INTRODUCTION TO A RDUINO PROGRAMMING & INTERFACING Engr. Franz Duran, MEP-ECE RapidSignal Electronics.
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.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Good LED Circuit 5V0 GND. What Voltage Does Meter See? Answer: 5 V.
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
Code The Arduino Environment.
Programming, Serial and Virtual Prototyping. Code if ( You like semicolons ) { Stay here for intro to Arduino code } else { Join the MODKit group for.
智慧電子應用設計導論(1/3) Arduino MEGA 2560
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Arduino Circuits and Code. int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, LOW); delay(1000); digitalWrite(ledPin,
Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011.
Servo Demonstration In MPIDE, select File > Examples > Servo > Sweep.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
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.
Photoresistor resistance changes dramatically with light level living with the lab Using Photoresistors with an Arduino © 2011 LWTL faculty team.
Welcome to Processing Who does not have access to digital camera?
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
Microcontroller basics Embedded systems for mortals.
Embedded systems and sensors 1 Part 2 Interaction technology Lennart Herlaar.
Microcontroller basics Embedded systems for mortals.
Lecture 9: Introduction to Arduino Topics: Arduino Fundamentals, Bean Date: Mar 22, 2016.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
Electronic instrumentation Digitization of Analog Signal in TD
Pulse-Width Modulation: Simulating variable DC output
Microcontroller basics Embedded systems for mortals.
Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
Hacking on Arduino George Patterson
physical computing .2 – Day 3
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Microcontroller basics
Microcontroller basics
Get Your Project Started with Arduino
UCD ElecSoc Robotics Club 2017/2018
Lab 1: Arduino Basics Topics: Arduino Fundamentals, First Circuit
INC 161 , CPE 100 Computer Programming
Arduino - Introduction
Introduction to Arduinos
IoT Programming the Particle Photon.
1 Code
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
Programming 2: The Arduino IDE & First Sketches
Arduino Practice: Photoresistors, PWM, Potentiometers, Motors
CTY SAR FCPS Shawn Lupoli, Elliot Tan
Introduction to Arduinos
Interrupts.
Pulse-Width Modulation: Simulating variable DC output
Presentation transcript:

Microcontroller basics Embedded systems for mortals

Lesson 2 Repetetion Analog input Interrupts Basic serial

Repetition Make a connection for a LED that can be controlled with a button Code it by yourself Don’t use the code you used last time! Try to do it by yourself

LED with button control

Code byte ledPin = 24; //new ledPin value byte buttonPin = 12; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH); } void loop() { if(digitalRead(buttonPin) == LOW) { digitalWrite(ledPin, HIGH); //LED ON } else { digitalWrite(ledPin, LOW); //LED OFF } Controlling external LED with push button

Analog input in Teensy Multiple voltages can be read between 0-5V Input voltage is compared to a reference voltage By default the reference voltage has to be connected to AREF-pin 10 bit conversion

How A/D conversion works With 10 bits you can have 2 10 = 1024 different values Linearly scaled 0V = 0 | 2,5V = 512 | 5V = 1023

Potentiometer The resistance value on potentiometer is the resistance between pins A and B Moving the wiper creates a variable voltage divider between pins A-W-B The voltage on any point between pins A and B can be read from pin W

Example 4 - Schematic

Example 4 – Breadboard Setup

Example 4 – Code byte analogPin = 38; //Analog pin F0 byte ledPin = 6; int value = 0; //can store value from -32,768 to 32,767 void setup() { pinMode(analogPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); } void loop() { value = analogRead(analogPin); //Read analog value digitalWrite(ledPin, HIGH); delay(value); digitalWrite(ledPin, LOW); delay(value); } Basic A/D

Arduino C – Analog functions analogRead(var1) analogRead function performs an analog reading operation on a selected pin. Var1 is the number of the analog pin. analogWrite can be used on PWM pins to generated a square wave. Var1 is the number of the pin and var2 is the value (0-255) analogWrite(var1, var2) IMPORTANT TO NOTICE: These analog functions are generic functions that are supposed to work on all Arduino boards. The actual effect might not be what you initially expect! Using analogRead will force the reference voltage to be whatever has been set with analogReference -function analogReference is used to change the source of reference voltage for ADC. Var1 defines the source: (DEFAULT, INTERNAL or EXTERNAL) analogReference(var1)

Interrupts There are both internal and external interrupts Internal interrupts Generated by timers, communication protocols, ADC and many other internal components External interrupts Generated by changes in certain pins

Interrupts When an interrupt is detected the processor moves directly to execute the code related to given interrupt After the interrupt routine is completed the processor returns to it’s previous position before the interrupt occured

Example 5 - Schematic

Example 5 – Breadboard Setup

Example 5 - Code byte analogPin = 38; byte ledPin = 6; byte interruptPin = 0; //External interrupt pin D0 int value = 0; //can store value from -32,768 to 32,767 void setup() { pinMode(analogPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); pinMode(interruptPin, INPUT_PULLUP); attachInterrupt(interruptPin, interrupt1, FALLING); } void loop() { value = analogRead(analogPin); //Read analog value if(digitalRead(ledPin)) { delay(value); digitalWrite(ledPin, LOW); } void interrupt1() { digitalWrite(ledPin, HIGH); } External interrupt

Arduino C – Interrupt functions attachInterrupt(var1, var2, var3) attachInterrupt creates a connection with external interrupt source and a function. Var 1 is the number of the external interrupt pin, var 2 is the name of the function to call when interrupt occurs and var3 is the mode of operation: (LOW, CHANGE, FALLING or RISING) Opposite of attachInterrupt. Brakes the connection between external interrupt pin and a function. Var1 is the number of the external interrupt pin. detachInterrupt(var1) IMPORTANT TO NOTICE: These functions only work for external interrupts. Internal interrupts have to be programmed using the registers and basic C -code

Serial communication over USB Can be used for multiple things Communicating with computer programs Debugging Requires the use of Serial library Serial library is automatically included when Serial.begin() -function is called

Example 7 - Code byte ledPin = 6; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); Serial.begin(9600); //Begin serial communication with baud rate 9600 } void loop() { digitalWrite(ledPin, HIGH); Serial.println(“LED ON”); //Send a line of text to serial port delay(1000); digitalWrite(ledPin, LOW); Serial.println(“LED OFF”); delay(1000); } Using Serial communication over USB

Arduino C – Serial functions Serial.begin(baud, config) Serial.println(”text”) Serial.println(var) Starts the serial communication over the USB. Baud is the desired speed of communication (baud rate) and config is the configuration mode (optional). Print a line to the serial port. After printing send a new line character (“\n”). With quotes it sends text and without, it prints the contents of the variable. Serial.print(”text”) Serial.print(var) Same as the Serial.println() except it doesn’t send the new line character. MORE INFO:

In next lesson Serial communication (deivces) I2C communication SPI communication