SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Datalogger Programming Using
Arduino - Part 1
Jeffery S. Horsburgh
Hydroinformatics
Fall 2018
Objectives
• Learn basic data collection concepts for hydrologic
data
• Examine more closely observation dimensionality,
including the scale triplet of support, spacing, and
extent
• Learn the basic datalogger program structure for
logging data
Arduino Programs – “Sketches”
• Sketch = Program
• Unit of code uploaded to and run on an Arduino
board
• 5 parts:
1. A descriptive header comment block
2. Definition of global variables
3. Setup() function
4. Loop() function
5. User-defined functions
• Arduino Language Reference:
https://www.arduino.cc/en/Reference/HomePage
Arduino Language
• Roughly based on C
• All statements must end with a ;
• Variables are storage compartments for numbers
• Variables must be defined before use
• // Comments are preceded by two forward slashes
What’s the best way to learn the language?
Study the examples and other people’s code!!!
Exercise – The “Blink” Sketch
• Plug your Arduino into your computer via the USB
cable
• Open the Arduino IDE software
• From the Tools drop down menu select:
Board  Arduino/Genuino UNO
Port  <whichever port is labeled Arduino/Genuino Uno>
• From the File drop down menu select:
Examples  01. Basics  Blink
The header
block
describes
the sketch
Import
libraries or
declare Global
variables here
The setup()
function
The loop()
function
User-defined
functions here
Example Sketch
Exercise – The “Blink” Sketch
• Plug your Arduino into your computer via the USB
cable
• Open the Arduino IDE software
• From the Tools drop down menu select:
Board  Arduino/Genuino UNO
Port  <whichever port is labeled Arduino/Genuino Uno>
• From the File drop down menu select:
Examples  01. Basics  Blink
• On the toolbar, click the “verify” button
• On the toolbar, click the “upload” button
Closer Look – the setup() function
• Run once when you power the Arduino or when
you send a new program
• Put everything in the setup() function that you
want to happen before the main program loop
starts
Closer look – the loop() function
• Runs continuously as long as the Arduino is
powered
• Yep – its an endless loop!
• Put everything in the loop() function that you want
to execute continuously
• Measurements
• Control logic
• Data output
• Etc.
How do we turn an Arduino into a
datalogger?
•Some things we have to figure out:
o Debugging
o Timing
o Interfacing with sensors and making
measurements
o Recording data to a file
Debugging Using the Output Pane
• When you
compile your
code, errors
will show up
here
Exercise – “Blink_Example2”
• Send the program, then open the serial monitor by
clicking the button on the toolbar (top right)
Start a serial
port and print a
line of text to it.
Print a line of
text with LED
status
Debugging with
Serial Output
• Useful when you want to
see what’s going on as
the program executes
• Print values and
messages to a serial
monitor
• The Arduino IDE has it’s
own serial monitor
• Super helpful for
debugging
Make sure the baud rate
matches your Serial.begin()
statement in your sketch
Timing
• The loop() function runs indefinitely as fast as it can
• The loop itself takes a couple of clock cycles, but
total time is dependent on what is in the loop
• Arduino UNO has no realtime clock (bummer!)
• But, it has some useful timing functions:
• millis() – number of milliseconds since the Arduino
board began running the current program
• micros() – same as millis, but for microseconds
• delay() – pauses the program for an amount of time (in
milliseconds)
• delayMicroseconds() – same as delay but for
microseconds
NOTE: millis() and micros() will overflow and go back to zero after a certain
period of time
Exercise – “Timing_Example1”
Timing
• millis() and delay() are great, but not exact
• Plus, delay() pauses the program and you can’t do
anything else at the same time
• What if I want the Arduino to do something (like
make a measurement) on a more precise, set time
interval?
• What if I want to do multiple things at the same
time?
Measurement Concepts
• Remember the scale triplet – support, spacing, and
extent
• We want to control these with our program
The Scale Triplet of Measurements
length or time
quantity
(a) Extent
length or time
quantity
(b) Spacing
length or time
quantity
(c) Support
Measurement Concepts - Spacing
How often should we record
values to capture this signal?
“When one can verify that additional
measurements will merely ‘connect
the dots’ between the existing
observations, the hydrochemical
record can be considered continuous
for all practical purposes.”
Kirchner, J.W., Feng, X., Neal, C., Robson, A.J. (2004). The fine structure of water-
quality dynamics: the (high-frequency) wave of the future, Hydrological Processes,
18(7), 1353-1359, http://dx.doi.org/10.1002/hyp.5537.
Remember this Slide?
Sampling Frequency
• Half hourly data
subsampled
-Hourly
-Daily
-Weekly
-Monthly
Half hourly
Hourly
Daily
Weekly
Monthly
Measurement Concepts - Spacing
Looks good…
But, what do we record?
One instantaneous value
every 5 seconds?
What if the sensor is “noisy?”
What if the signal is “noisy?”
Time Support and Spacing
• Generally handled using a scan interval and a
recording interval
• Scan Interval = the time between sensor measurements
• Recording Interval = the time between recorded
observations
What is the difference?
Measurement Concepts
Scan Interval vs. Recording Interval
• Recording Interval = spacing
• Scan Interval = what we do within a recording
interval that determines what values we record
• How many times we sample the sensor(s)
• What statistic (if any) we calculate
Measurement Concepts
Scan Interval vs. Recording Interval
Measurement Concepts
Scan Interval vs. Recording Interval
• There are several reasons to scan sensors more
frequently than you record data:
oReduce error in sensor observations by aggregation
(e.g., calculate an average value)
oReduce noise in the observed phenomena by
aggregation – again, averaging
oAdaptive sampling – record values at a slow rate until
something interesting happens (e.g., a storm event),
then increase recording frequency
• Tradeoff: Scanning sensors requires power
Measurement Concepts
Time Support
• The time window / footprint
over which an observation is
made
• Not always equal to the recording interval
• Depends on scanning and recording strategy
oInstantaneous values: time support = 0
oAverage (or other aggregate statistic) values: time
support = whatever time window over which you
calculate the statistic
• Regular averaging
• Burst sampling
Exercise – “Timing_Example2”
Pseduo-code of loop:
1. Get the current value of the micros() function
2. Check to see if a scan interval has passed
3. If a scan interval has passed
a. Perform scan instructions (e.g.,
measurements, calculations, etc.)
b. Check to see if a recording interval has passed
c. If a recording interval has passed
i. Perform necessary calculations
ii. Record an output record
Some Notes about Timing
• On the Arduino UNO, the micros() function has a
resolution of 4 microseconds
• The “Timing_Example2” sketch will accumulate
error in timing
• More sophisticated examples might use interrupts
and the UNO’s internal timers, but for our work,
this example will suffice
How do we turn an Arduino into a
datalogger?
•Some things we have to figure out:
 Debugging
 Timing
o Interfacing with sensors and making
measurements
o Recording data to a file
Summary
• Every hydrologic observation, regardless of how it was
created, has support, spacing, and extent
• The scale triplet determines how we interpret and use
data
• Arduino gives us an inexpensive prototyping platform
for environmental sensors and datalogging
• Arduino’s IDE and programming language provide a
coding environment for measurement and control
• Arduino sketches rely on setup() and loop() functions
• Controlling time support and spacing of observations
relies on Arduino’s timing functions (or an external
realtime clock)
• Timing/sampling strategies can be used to
capture/overcome noisy signals and sensors

Weitere ähnliche Inhalte

Ähnlich wie Class5_DataloggerProgrammingArduino.pptx

CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...
CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...
CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...
WalterJaramillo7
 
Resource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time SystemsResource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time Systems
jeronimored
 

Ähnlich wie Class5_DataloggerProgrammingArduino.pptx (20)

I/O systems chapter 12 OS
I/O systems chapter 12 OS I/O systems chapter 12 OS
I/O systems chapter 12 OS
 
04 performance
04 performance04 performance
04 performance
 
01 introduction to cpp
01   introduction to cpp01   introduction to cpp
01 introduction to cpp
 
QuickIntroduction to Arduino and Sensors
QuickIntroduction to Arduino and SensorsQuickIntroduction to Arduino and Sensors
QuickIntroduction to Arduino and Sensors
 
13223971.ppt
13223971.ppt13223971.ppt
13223971.ppt
 
Machine Learning and Apache Edgent with STM32F401 to Firebase
Machine Learning and Apache Edgent with STM32F401 to Firebase Machine Learning and Apache Edgent with STM32F401 to Firebase
Machine Learning and Apache Edgent with STM32F401 to Firebase
 
PILOT Session for Embedded Systems
PILOT Session for Embedded Systems PILOT Session for Embedded Systems
PILOT Session for Embedded Systems
 
2018 FRecure CISSP Mentor Program- Session 4
2018 FRecure CISSP Mentor Program- Session 42018 FRecure CISSP Mentor Program- Session 4
2018 FRecure CISSP Mentor Program- Session 4
 
Android talks #08 android profiling
Android talks #08   android profilingAndroid talks #08   android profiling
Android talks #08 android profiling
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012
 
Compute fast of computer
Compute fast of computerCompute fast of computer
Compute fast of computer
 
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
 
Unit 1, ADA.pptx
Unit 1, ADA.pptxUnit 1, ADA.pptx
Unit 1, ADA.pptx
 
Arduino Workshop @ MSA University
Arduino Workshop @ MSA UniversityArduino Workshop @ MSA University
Arduino Workshop @ MSA University
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
L-2 (Computer Performance).ppt
L-2 (Computer Performance).pptL-2 (Computer Performance).ppt
L-2 (Computer Performance).ppt
 
Computer architecture short note (version 8)
Computer architecture short note (version 8)Computer architecture short note (version 8)
Computer architecture short note (version 8)
 
CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...
CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...
CM7_Op_Simplicity_Boston-Chromeleon CDS-Instrumentos, Inteligencia, Informaci...
 
Resource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time SystemsResource Management in (Embedded) Real-Time Systems
Resource Management in (Embedded) Real-Time Systems
 
Time Series Anomaly Detection with Azure and .NETT
Time Series Anomaly Detection with Azure and .NETTTime Series Anomaly Detection with Azure and .NETT
Time Series Anomaly Detection with Azure and .NETT
 

Mehr von HebaEng

MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfMATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
HebaEng
 
Estimate the value of the following limits.pptx
Estimate the value of the following limits.pptxEstimate the value of the following limits.pptx
Estimate the value of the following limits.pptx
HebaEng
 
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdflecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
HebaEng
 
LECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxLECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptx
HebaEng
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
HebaEng
 
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdflect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
HebaEng
 
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxsensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
HebaEng
 
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHomework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
HebaEng
 
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggPIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
HebaEng
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
HebaEng
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdf
HebaEng
 
IO and MAX 2.pptx
IO and MAX 2.pptxIO and MAX 2.pptx
IO and MAX 2.pptx
HebaEng
 
BUS DRIVER.pptx
BUS DRIVER.pptxBUS DRIVER.pptx
BUS DRIVER.pptx
HebaEng
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
HebaEng
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
HebaEng
 

Mehr von HebaEng (20)

MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdfMATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
 
Estimate the value of the following limits.pptx
Estimate the value of the following limits.pptxEstimate the value of the following limits.pptx
Estimate the value of the following limits.pptx
 
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdflecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
 
LECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptxLECtttttttttttttttttttttttttttttt2 M.pptx
LECtttttttttttttttttttttttttttttt2 M.pptx
 
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdflect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
 
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdflect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
 
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptxsensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
 
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdfHomework lehhhhghjjjjhgd thvfgycture 1.pdf
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
 
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging huggPIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
 
lecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).pptlecture1ddddgggggggggggghhhhhhh (11).ppt
lecture1ddddgggggggggggghhhhhhh (11).ppt
 
math6.pdf
math6.pdfmath6.pdf
math6.pdf
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
 
digital10.pdf
digital10.pdfdigital10.pdf
digital10.pdf
 
PIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdfPIC Serial Communication_P2 (2).pdf
PIC Serial Communication_P2 (2).pdf
 
Instruction 3.pptx
Instruction 3.pptxInstruction 3.pptx
Instruction 3.pptx
 
IO and MAX 2.pptx
IO and MAX 2.pptxIO and MAX 2.pptx
IO and MAX 2.pptx
 
BUS DRIVER.pptx
BUS DRIVER.pptxBUS DRIVER.pptx
BUS DRIVER.pptx
 
VRAM & DEBUG.pptx
VRAM & DEBUG.pptxVRAM & DEBUG.pptx
VRAM & DEBUG.pptx
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
 
8086 memory interface.pptx
8086 memory interface.pptx8086 memory interface.pptx
8086 memory interface.pptx
 

Kürzlich hochgeladen

Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
wpkuukw
 
Simple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptxSimple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptx
balqisyamutia
 
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
eeanqy
 
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
HyderabadDolls
 
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
wpkuukw
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
ehyxf
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion pills in Kuwait Cytotec pills in Kuwait
 
ab-initio-training basics and architecture
ab-initio-training basics and architectureab-initio-training basics and architecture
ab-initio-training basics and architecture
saipriyacoool
 

Kürzlich hochgeladen (20)

Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In eluru [ 7014168258 ] Call Me For Genuine Models We ...
 
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdfJordan_Amanda_DMBS202404_PB1_2024-04.pdf
Jordan_Amanda_DMBS202404_PB1_2024-04.pdf
 
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
一比一定(购)卡尔顿大学毕业证(CU毕业证)成绩单学位证
 
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
 
LANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEK
LANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEKLANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEK
LANDSCAPE ARCHITECTURE PORTFOLIO - MAREK MITACEK
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
 
BLOCK CHAIN PROJECT block chain project
BLOCK CHAIN  PROJECT block chain projectBLOCK CHAIN  PROJECT block chain project
BLOCK CHAIN PROJECT block chain project
 
TRose UXPA Experience Design Concord .pptx
TRose UXPA Experience Design Concord .pptxTRose UXPA Experience Design Concord .pptx
TRose UXPA Experience Design Concord .pptx
 
Simple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptxSimple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptx
 
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
怎样办理伯明翰大学学院毕业证(Birmingham毕业证书)成绩单留信认证
 
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
 
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
一比一定(购)滑铁卢大学毕业证(UW毕业证)成绩单学位证
 
Furniture & Joinery Details_Designs.pptx
Furniture & Joinery Details_Designs.pptxFurniture & Joinery Details_Designs.pptx
Furniture & Joinery Details_Designs.pptx
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
 
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman MuscatAbortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
Abortion Pills in Oman (+918133066128) Cytotec clinic buy Oman Muscat
 
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime PondicherryPondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
Pondicherry Escorts Service Girl ^ 9332606886, WhatsApp Anytime Pondicherry
 
ab-initio-training basics and architecture
ab-initio-training basics and architectureab-initio-training basics and architecture
ab-initio-training basics and architecture
 
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
 
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Jalaun Just Call 8617370543 Top Class Call Girl Service Available
 

Class5_DataloggerProgrammingArduino.pptx

  • 1. Datalogger Programming Using Arduino - Part 1 Jeffery S. Horsburgh Hydroinformatics Fall 2018
  • 2. Objectives • Learn basic data collection concepts for hydrologic data • Examine more closely observation dimensionality, including the scale triplet of support, spacing, and extent • Learn the basic datalogger program structure for logging data
  • 3. Arduino Programs – “Sketches” • Sketch = Program • Unit of code uploaded to and run on an Arduino board • 5 parts: 1. A descriptive header comment block 2. Definition of global variables 3. Setup() function 4. Loop() function 5. User-defined functions • Arduino Language Reference: https://www.arduino.cc/en/Reference/HomePage
  • 4. Arduino Language • Roughly based on C • All statements must end with a ; • Variables are storage compartments for numbers • Variables must be defined before use • // Comments are preceded by two forward slashes What’s the best way to learn the language? Study the examples and other people’s code!!!
  • 5. Exercise – The “Blink” Sketch • Plug your Arduino into your computer via the USB cable • Open the Arduino IDE software • From the Tools drop down menu select: Board  Arduino/Genuino UNO Port  <whichever port is labeled Arduino/Genuino Uno> • From the File drop down menu select: Examples  01. Basics  Blink
  • 6. The header block describes the sketch Import libraries or declare Global variables here The setup() function The loop() function User-defined functions here Example Sketch
  • 7. Exercise – The “Blink” Sketch • Plug your Arduino into your computer via the USB cable • Open the Arduino IDE software • From the Tools drop down menu select: Board  Arduino/Genuino UNO Port  <whichever port is labeled Arduino/Genuino Uno> • From the File drop down menu select: Examples  01. Basics  Blink • On the toolbar, click the “verify” button • On the toolbar, click the “upload” button
  • 8. Closer Look – the setup() function • Run once when you power the Arduino or when you send a new program • Put everything in the setup() function that you want to happen before the main program loop starts
  • 9. Closer look – the loop() function • Runs continuously as long as the Arduino is powered • Yep – its an endless loop! • Put everything in the loop() function that you want to execute continuously • Measurements • Control logic • Data output • Etc.
  • 10. How do we turn an Arduino into a datalogger? •Some things we have to figure out: o Debugging o Timing o Interfacing with sensors and making measurements o Recording data to a file
  • 11. Debugging Using the Output Pane • When you compile your code, errors will show up here
  • 12. Exercise – “Blink_Example2” • Send the program, then open the serial monitor by clicking the button on the toolbar (top right) Start a serial port and print a line of text to it. Print a line of text with LED status
  • 13. Debugging with Serial Output • Useful when you want to see what’s going on as the program executes • Print values and messages to a serial monitor • The Arduino IDE has it’s own serial monitor • Super helpful for debugging Make sure the baud rate matches your Serial.begin() statement in your sketch
  • 14. Timing • The loop() function runs indefinitely as fast as it can • The loop itself takes a couple of clock cycles, but total time is dependent on what is in the loop • Arduino UNO has no realtime clock (bummer!) • But, it has some useful timing functions: • millis() – number of milliseconds since the Arduino board began running the current program • micros() – same as millis, but for microseconds • delay() – pauses the program for an amount of time (in milliseconds) • delayMicroseconds() – same as delay but for microseconds NOTE: millis() and micros() will overflow and go back to zero after a certain period of time
  • 16. Timing • millis() and delay() are great, but not exact • Plus, delay() pauses the program and you can’t do anything else at the same time • What if I want the Arduino to do something (like make a measurement) on a more precise, set time interval? • What if I want to do multiple things at the same time?
  • 17. Measurement Concepts • Remember the scale triplet – support, spacing, and extent • We want to control these with our program The Scale Triplet of Measurements length or time quantity (a) Extent length or time quantity (b) Spacing length or time quantity (c) Support
  • 18. Measurement Concepts - Spacing How often should we record values to capture this signal?
  • 19. “When one can verify that additional measurements will merely ‘connect the dots’ between the existing observations, the hydrochemical record can be considered continuous for all practical purposes.” Kirchner, J.W., Feng, X., Neal, C., Robson, A.J. (2004). The fine structure of water- quality dynamics: the (high-frequency) wave of the future, Hydrological Processes, 18(7), 1353-1359, http://dx.doi.org/10.1002/hyp.5537.
  • 20. Remember this Slide? Sampling Frequency • Half hourly data subsampled -Hourly -Daily -Weekly -Monthly Half hourly Hourly Daily Weekly Monthly
  • 21. Measurement Concepts - Spacing Looks good… But, what do we record? One instantaneous value every 5 seconds?
  • 22. What if the sensor is “noisy?”
  • 23. What if the signal is “noisy?”
  • 24. Time Support and Spacing • Generally handled using a scan interval and a recording interval • Scan Interval = the time between sensor measurements • Recording Interval = the time between recorded observations What is the difference?
  • 25. Measurement Concepts Scan Interval vs. Recording Interval • Recording Interval = spacing • Scan Interval = what we do within a recording interval that determines what values we record • How many times we sample the sensor(s) • What statistic (if any) we calculate
  • 26. Measurement Concepts Scan Interval vs. Recording Interval
  • 27. Measurement Concepts Scan Interval vs. Recording Interval • There are several reasons to scan sensors more frequently than you record data: oReduce error in sensor observations by aggregation (e.g., calculate an average value) oReduce noise in the observed phenomena by aggregation – again, averaging oAdaptive sampling – record values at a slow rate until something interesting happens (e.g., a storm event), then increase recording frequency • Tradeoff: Scanning sensors requires power
  • 28. Measurement Concepts Time Support • The time window / footprint over which an observation is made • Not always equal to the recording interval • Depends on scanning and recording strategy oInstantaneous values: time support = 0 oAverage (or other aggregate statistic) values: time support = whatever time window over which you calculate the statistic • Regular averaging • Burst sampling
  • 29. Exercise – “Timing_Example2” Pseduo-code of loop: 1. Get the current value of the micros() function 2. Check to see if a scan interval has passed 3. If a scan interval has passed a. Perform scan instructions (e.g., measurements, calculations, etc.) b. Check to see if a recording interval has passed c. If a recording interval has passed i. Perform necessary calculations ii. Record an output record
  • 30. Some Notes about Timing • On the Arduino UNO, the micros() function has a resolution of 4 microseconds • The “Timing_Example2” sketch will accumulate error in timing • More sophisticated examples might use interrupts and the UNO’s internal timers, but for our work, this example will suffice
  • 31. How do we turn an Arduino into a datalogger? •Some things we have to figure out:  Debugging  Timing o Interfacing with sensors and making measurements o Recording data to a file
  • 32. Summary • Every hydrologic observation, regardless of how it was created, has support, spacing, and extent • The scale triplet determines how we interpret and use data • Arduino gives us an inexpensive prototyping platform for environmental sensors and datalogging • Arduino’s IDE and programming language provide a coding environment for measurement and control • Arduino sketches rely on setup() and loop() functions • Controlling time support and spacing of observations relies on Arduino’s timing functions (or an external realtime clock) • Timing/sampling strategies can be used to capture/overcome noisy signals and sensors