Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Sensor Technology Week Five Adam Taylor

Similar presentations


Presentation on theme: "Introduction to Sensor Technology Week Five Adam Taylor"— Presentation transcript:

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

2 Error Checking Simple Comparison Max Min values Calibration Averaging Median Filtering Debouncing Kalman Filtering

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

4 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.

5 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)

6 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…

7 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

8 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/attachInterru pt http://arduino.cc/en/Reference/attachInterru pt Interrupts can happen because of users or things like timers

9 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

10 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; }

11 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

12 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; } } }

13 Shields

14 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

15 Project Deadlines Demo: April 15 th from 11:00 Report: ~1pg due April 20 th at 23:59 If you change the project make sure to check with me first. Submit by email to tayloral+sensorTech@tcd.ie with your report and code attached tayloral+sensorTech@tcd.ie


Download ppt "Introduction to Sensor Technology Week Five Adam Taylor"

Similar presentations


Ads by Google