introduction to sensor technology week five adam taylor [email protected]

15
Introduction to Sensor Technology Week Five Adam Taylor [email protected]

Upload: grace-ray

Post on 02-Jan-2016

226 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Introduction to Sensor Technology

Week Five

Adam Taylor [email protected]

Page 2: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Error Checking

• Simple Comparison• Max Min values• Calibration• Averaging• Median Filtering• Debouncing• Kalman Filtering

Page 3: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Sensors

• Location- GPS, WiFi, Cell Based, Ping Based• Item ID- RFID• Non-Sensor Sensors- Calendars, Logging Data,

Preferences …

Page 4: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Multi Task Programming

• Might want to do more than 1 thing at a time• Might not know when things will happen• Different priorities for jobs• Responsiveness etc.

Page 5: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Threads

• On most computers this is achieved through threads and processes

• A desktop computer has many cores, so it is able to do several things at once.

• Arduino can not so it needs to be clever (or you do)

Page 6: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Time

• Using delay(n) is ok for waiting but some times you want to do other things while you wait

• millis() returns the time in mS since the program started as an unsigned long

• If you save the time you do something then wait until it + some time you have a delay that you can do other things during

• Unsigned longs are 32 bits (4 bytes) so…

Page 7: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Time

• Max 2^32 -1 mS can be counted =4294967295• 4294967295/1000 = seconds• 4294967/60/60=hours• 1193.04638889/24=days• 49.71 days is max time you can do

Page 8: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Interrupt Driven Programming

• In more complicated programs for when things can happen at any time (i.e. user input)

• Arduino has ~2 interrupt lines, if these happen then a function is called

• http://arduino.cc/en/Reference/attachInterrupt

• Interrupts can happen because of users or things like timers

Page 9: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Interrupt Driven Programming

• attachInterrupt(interrupt, myFunction, mode)• Interrupt can be 0/1 for pin 2/3 on uno• Mode can be LOW, CHANGE, RISING, FALLING• myFunction can be any function but Delay(n)

won’t work and they should be a quick as possible

Page 10: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

• int pin = 13;volatile int state = LOW;//a variable that can change from outside program

void setup(){ pinMode(pin, OUTPUT); attachInterrupt(0, blink, CHANGE);//if pin 2 changes call blink}

void loop(){ digitalWrite(pin, state);//set the LED}

void blink(){ state = !state;}

Page 11: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Serial Event

• Serial events are a lot like interrupts but caused by typing

• When they happen a special function is called• serialEvent() is its name• Takes less set up than ‘normal’ interrupts

Page 12: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Serial Event• void serialEvent() {

while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } }}

Page 13: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Shields

Page 14: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Shields

• Shields allow Arduino’s to do things that the basic hardware wouldn’t allow

• Connect to WiFi, Ethernet, Xbees, GSM• Cameras, Voice recognition, Motor Control

Page 15: Introduction to Sensor Technology Week Five Adam Taylor tayloral@tcd.ie

Project Deadlines

• Demo: April 15th from 11:00• Report: ~1pg due April 20th at 23:59• If you change the project make sure to check

with me first.• Submit by email to

[email protected] with your report and code attached