Programming with the Arduino: open-source hardware in an introductory programming laboratory. Paul Cruickshank

Size: px
Start display at page:

Download "Programming with the Arduino: open-source hardware in an introductory programming laboratory. Paul Cruickshank pasc@st-andrews.ac."

Transcription

1 Programming with the Arduino: open-source hardware in an introductory programming laboratory Paul Cruickshank

2 Motivation Prior to 2013, no formal programming for St Andrews physics students until 3 rd 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

3 Context: computing in the St Andrews physics degree 2 nd year: some Python in modules taught by School of Maths 2 nd year: 7.5 hours of C in Arduino lab (all physics/astrophysics students) 3 rd year: Computational Physics module,10 credits, Mathematica (all physics/astrophysics students) 3 rd year: Computational Astrophysics, 15 credits, Fortran 3 rd year: 15 hours of LabView as part of physics lab module

4 The Arduino (UNO R3) Atmel ATmega328 8-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 Many other variants available (including versions with more grunt) inc VAT (Farnell)

5 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

6 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

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

8 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

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

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

11 Lab structure Three 2.5 hr afternoon sessions Before starting, students answer pre-lab questions based on content of lab script

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

13 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 prewritten library functions)

14 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

15 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

16 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

17 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

18 Demonstrator support 4 demonstrators for ~30 students Demonstrators encouraged to be proactive More than half required no time outside scheduled periods Of those who did, an hour was adequate

19 Approx. costs for 40 sets (inc. VAT) Arduino boards & 880 cables: Touchscreens: 330 Accelerometers: 330 PCBs: 400 Other components: 400 Most of these oneoffs, less than 100 per year

20 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

21 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

22 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

23 Feedback How difficult did you find this lab compared to other second year labs? (N=79) 3.2

24 Feedback How enjoyable did you find the Arduino lab? (N=79) 3.3

25 Feedback This lab opened up a whole new area of physics to me (N=77) 4.2

26 Feedback Overall impression: (N=78) 5.1

27 Feedback Overall impression: perceived gain from the lab (N=78) 5.3

28 Example applications from elsewhere 10 by 10 temperature sensor array Eric Ayars, California State University, Chico used with permission (Very instructive blog, used with permission

29 Example applications from elsewhere Orthopaedic rehab studies using Arduino based data acquisition systems of accelerometer and goniometer data obtained from the knee Graham Brooker, AFCR, University of Sydney used with permission

30 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

31 Simple demos