programming with the arduino: open-source hardware in an ...€¦ · arduino: open-source hardware...
TRANSCRIPT
![Page 1: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/1.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Programming with the Arduino: open-source
hardware in an introductory programming laboratory
Paul [email protected]
![Page 2: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/2.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Motivation
�Prior to 2013, no formal programming for St Andrews physics students until 3rd
year�Earlier programming experience thought
desirable�Aims to introduce 3 key concepts:
loops, decision making and functions�Available time: 7.5 hours over three
weeks
![Page 3: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/3.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Context: computing in the St Andrews physics degree
� 2nd year: some Python in modules taught by School of Maths
� 2nd year: 7.5 hours of C in Arduino lab (all physics/astrophysics students)
� 3rd year: Computational Physics module,10 credits, Mathematica (all physics/astrophysics students)
� 3rd year: Computational Astrophysics, 15 credits, Fortran
� 3rd year: 15 hours of LabView as part of physics lab module
![Page 4: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/4.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
The Arduino (UNO R3)Atmel ATmega3288-bit microcontroller, 16MHz
14 digital I/O pins
6 analogue input pins (10-bit)
5V supply via USB, 7-12V external, on-board 5V and 3.3V regulators
HUGE community of users
£21.66 inc VAT (Farnell)Many other variants available (including versions with more grunt)
![Page 5: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/5.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
The Arduino IDE
� Java based, so platform agnostic*
� Programs written in C/C++
� Hardware functions abstracted away from hardware pretty well
� Core function set pretty minimal, but easy to learn
*Disclaimer: I haven’t tried it on Linux
![Page 6: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/6.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
The Arduino IDE
� All Arduino programs MUST contain TWO functions, called ‘setup’ and ‘loop’
� When program compiled, IDE adds these and other code to generate a ‘proper’ C++ file, then compiles that
![Page 7: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/7.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Why use Arduino?
�Replaced part of an electronics practical, so wanted to retain practical feel
�Very easy to interface to�Built-in analogue to digital converter�Digital input/output�Libraries and examples for most things
you can think of (not always a good thing)
![Page 8: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/8.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Good things about the Arduino
�Programmed in C/C++�Low barrier to entry (cost, availability,
computer requirements)�Exercises have a good practical feel:
easy to write programs that interact with outside world
![Page 9: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/9.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Less good things about the Arduino
� (Deliberately) not designed for teaching programming
�Programmed in C/C++�Compiler error messages less than
transparent�Development environment can be restrictive�Occasional driver issues�No console (although serial monitor works out
ok)
![Page 10: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/10.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Development
�Spring 2012: final-year student project devising trial script (Adam Hollan)
�Single afternoon trial run with 9 volunteers from intended target group
�All student questions to demonstrators recorded
�Spring 2013: final-year student project evaluating first live run (Duncan Downie)
![Page 11: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/11.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Lab structure
�Three 2.5 hr afternoon sessions�Before starting, students answer pre-lab
questions based on content of lab script
![Page 12: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/12.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Lab afternoon one
� Introduction to environment� Introduction to syntax�Analogue input: start with a potentiometer
(dull but straightforward), on to thermistor, LDR and analogue accelerometer
�Digital input and output (switches and LEDs)
![Page 13: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/13.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Lab afternoon two
�Analogue output (using external DAC, with pre-written library functions)
�Decision making (i.e. if and if…else statements)
� Introduction to flowcharts� Loops: for and while �Resistive touchscreen sensor (with pre-
written library functions)
![Page 14: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/14.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Lab afternoon three
�Write and use program to measure the IV characteristic of a diode
�Develops the automation of an experiment students will already have done by hand
�Designed to link in with previous work and make use of experience of first two afternoons
�Also shows utility of automation of measurement tasks
![Page 15: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/15.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Lab supporting materials
�Script entirely self-contained�Include text of sample programs so that
students can read in advance�Extensively footnoted to point out
parallels and differences with standard C
![Page 16: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/16.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Lab supporting materials
� Try hard to separate programming aspect from electronics aspect
� Provide suggested breadboard layouts for exercises: found some students get bogged down in assembling circuits, leaving less time for the main point of the lab
![Page 17: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/17.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Demonstrator training and support
�Demonstrators work independently through lab few weeks before start
�Deliberate move to develop familiarity�Also uncovers errors in script/libraries
and ensures manageable load for lab time (7.5 hours)
�Typically ~3.5hrs for no C/C++ prior experience
![Page 18: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/18.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Demonstrator support
�4 demonstrators for ~30 students�Demonstrators encouraged to be pro-
active�More than half required no time outside
scheduled periods�Of those who did, an hour was
adequate
![Page 19: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/19.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Approx. costs for 40 sets (inc.VAT)
Arduino boards & cables:
£880
Touchscreens: £330
Accelerometers: £330
PCBs: £400
Other components: £400
Most of these one-offs, less than £100 per year
![Page 20: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/20.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Difficulties
�Mark distribution is poor, and marks generally high (~80%)
�Tension between teaching a skill and having to put a number on the end result
�Lab doesn’t discriminate amongst the most capable students effectively
![Page 21: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/21.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Evaluation (2013)
�Comprehensive questionnaire�Recruited volunteers to record audio of
their lab experience along with their written text, using LiveScribe pens
�Most surprising sources of difficulty related to experimental technique rather than programming
![Page 22: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/22.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Student reception (2013 evaluation)
�Overall, pretty positive: they didn’t hate it, and no-one died
�Asked students to respond to a series of questions or statements on a five-point Likert scale
![Page 23: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/23.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Feedback
How difficult did you find this lab compared to other second year labs?
(N=79)
3.2
![Page 24: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/24.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Feedback
How enjoyable did you find the Arduino lab?
(N=79)
3.3
![Page 25: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/25.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Feedback
This lab opened up a whole new area of physics to me
(N=77)
4.2
![Page 26: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/26.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Feedback
Overall impression:
(N=78)
5.1
![Page 27: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/27.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Feedback
Overall impression: perceived gain from the lab
(N=78)
5.3
![Page 28: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/28.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Example applications from elsewhere
10 by 10 temperature sensor array
Eric Ayars, California State University, Chico
(Very instructive blog,http://hacks.ayars.org/)
used with permission
used with permission
![Page 29: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/29.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Example applications from elsewhere
used with permission
Orthopaedic rehab studies using Arduinobased data acquisition systems of accelerometer and goniometer data obtained from the knee
Graham Brooker,AFCR, University of Sydney
![Page 30: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/30.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Our plans for Arduino
�From spring next year: take-home lab�Give all students a box with necessary
kit�Keep same amount of available contact
time�If successful, consider adding extra
content
![Page 31: Programming with the Arduino: open-source hardware in an ...€¦ · Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank pasc@st-andrews.ac.uk](https://reader034.vdocuments.net/reader034/viewer/2022052519/604ecf37e62d2f7d4f3e27b9/html5/thumbnails/31.jpg)
School of Physics & AstronomySchool of Physics & Astronomy
Simple demos