A First Course in Computer Programming f
A First Course in Computer Programming f
Engineers
71
A second consideration regarding which sotware would B. Microcontroller Plaform
be included in the renovated ME 30 was the absence of any The major criteria we employed to select a suitable
formal exposure to Matlab in the ME and AE curriculum. microcontroller 'platfom' was that it should inexpensive
Prior to fall 2007, our E10 Introduction to Engineering (approximately $20-$30 US), current, easy for beginners to
course, included Matlab training in some of its laboratory use, compatible with other courses in the mechatronics area,
sessions. However, beginning in the fall 2007 semester, and that it have a signiicant user community. We looked at a
Matlab was dropped to make room for other content. Matlab number of the most popular platforms in wide use (e.g.,
is widely used in academia and industry and is viewed by Microchip starter/dev kits, Atmel STK500, AVR Butterly,
many educators as the language of choice for reshman Parallax Stamp, Freescale Tower, Cypress PSoC) as well as
engineering students [9]. Because of Matlab's importance, a number of third-party development hardware (e.g., Olimex,
especially in Mechtronics and controls, we include two MELabs, Futurlec) that have been in wide use over the past
weeks of coverage around weeks 13 and 14. Students ind ive years, and we inally settled on the Arduino platfom as
Matlab relatively easy to lean especially ater the prior shown in Figure 1.
weeks spent with C.
We try to alleviate the major drawbacks of Matlab: its
proprietay nature and its relatively high cost by also
exposing students to GNU Octave at the same time we cover
Matlab. GNU Octave is an open-source, reely available,
high-level language primarily intended for numerical
computations that is highly similar to Matlab [10]. Octave
provides a way for students to lean much of the
functionality of Matlab without becoming dependent upon it
[11].
The third consideration in choice of sotware has to do
with the students' ability to use a spreadsheet for engineering
computation and presentation of data. The spreadsheet is
arguably the most important computer application that
Fig. I. Arduino board. The Arduino is an embedded development
engineers should know and be able to use well [12]-[16]. platform based on the A Tmega328, an 8-bit microcontroller rom
Our E10 class does cover some of the basics of Excel for Atmel [17] - [18].
engineering applications, but most students need more
Arduino is a name for a number of interrelated and
practice with spreadsheets and more instruction in how to
overlapping elements of hardware and sotware [17] - [18].
create high quality charts. In the two weeks we allocate to
It can be used to designate the physical layout and
Excel, we also cover advanced features such as the Solver
interconnects of the original hardware board, the entire series
and VBA macros.
of boards and compatibles in the family, the IDE, the variant
of the C language that is mostly used for programming it, the
IV. EXPOSURE TO MECHATRONICS
C-language APIs for the family, or any combination of all
these depending on the context. Compatible boards designed
A. Student Enthusiasm for Mechatronics
and produced by others may not be called Arduinos, but are
Our experience rom ME 106 is that students really enjoy
oten named *duinos, or said to be 'Arduino-compatible'. To
the hands-on nature of mechatronics and leaning how to
date, all Arduino-compatibles use 8-bit microcontrollers
bring together electromechanical hardware, sensors, and
rom Atmel's AVR family.
microcontrollers into a functioning 'intelligent' system.
Everything that is produced by the Arduino team is open
However, by the time most of the students take ME 106, they
source - hardware and sotware alike. Most, if not all, of the
have already decided on their area of specialization, and, as
sotware on which the Arduino sotware is built is also open
mentioned earlier, the majority chooses Design over
source, particularly the cross-compiler, the IDE, and the Java
mechatronics or Thermal/Fluids. However, for some
language used by the IDE.
students, the positive experience in ME 106 causes them to
There is a substantial and growing community of
switch focus to Mechatronics for their elective courses and
developers of and for the Arduino - hardware, sotware,
senior capstone course or to at least want to lean more about
documentation and users [18].
Mechatronics. We thought it prudent therefore to capitalize
on the enthusiasm around Mechatronics by exposing the ME . Experimenter Shield
30 students to microcontrollers and embedded programming. A ubiquitous hardware accessory that many in the Arduino
Exit surveys also indicate that satisfaction with ME 106 and community develop for extending the unctionality of the
Mechatronics is correlated with a student's ability to write Arduino is a 'shield'. A shield is a printed circuit board
sotware. (PCB) designed to be connected on top of an original
72
Arduino that follows the connector layout of the original
Arduino PCB. The Arduino website contains a long list of
shield designs contributed by the user community [19].
We designed our own shield so that we could readily
provide means for digital input, digital output, analog input,
and pseudo-analog (PWM) output directly on the project
board without needing extra equipment and components and
without requiring extra knowledge of mechatronics rom the
students. Figure 2 shows the irst prototype of the
Spartronics Experimenter Shield (SES). Thirty of these
boards were fabricated in the fall of 2009 to use in ME 30
that same semester.
This early version of the SES features a potentiometer for one laboratory assignment for the students to get familiar
analog input, a momentary push-button switch for digital with embedded hardware and programming. The lecture
input, an ROB LED, and a two-pin header for a piezo covered the Arduino hardware, proper handling to minimize
speaker. ESD damage, the concepts of digital and analog input and
Figure 3 shows the more complete version 1.0 of the SES output, reading rom and writing to pins, and PWM output.
that is planned for use in the spring 2010 semester and The laboratory experiment consisted of several exercises
beyond. This board uses a professionally fabricated PCB and (which will be explained in more detail below):
includes more elements, such as a temperature sensor, 1. Oetting familiar with the Arduino and its integrated
A unique feature of the new SES is that it can be used with The irst exercise had four parts. In part 1, the students
the original Arduino (and its clones) as well as with the connect the Arduino to the PC and download a pre-written
Seeeduino Mega, an Arduino Mega-type board based on the program (called a 'sketch' in the Arduino community) to the
ATmega1280 microcontroller [20] available rom Seeed Arduino that blinks an LED on the main Arduino board at
Studio [21]. The 'duinoMega-type boards are based on the 0.5 Hz. In Part 2, the students are asked to modiy the code
ATmega1280 microcontroller [20]. The ATmega1280 has rom Part 1, so that the LED blinks at 2 Hz. In Part 3, the
four times as much lash memory, SRAM, and EEPROM student is asked to modiy the code rom Part 2, and blink
(128 kB, 8 kB, and 4096 bytes respectively) and 86 10 pins the green channel of the ROB LED on the SES. In Part 4, the
compared to 23 on the ATmega328 [22]. When the SES is students are asked to modiy the code rom Part 3 so that the
used with the Seeeduino Mega, its additional 10 pins make program blinks the red, green, and blue colors (in that order)
all eight switches, mono-color LEDs, and the dual seven- of the ROB LED on the SES.
73
The second exercise has two parts. In Part 1, the students be done using an of-the-shelf television IR remote in case
write a program that ns on the blue LED when the switch students were unable to complete the requirements of the ull
is pressed, and ns it of when the switch is not pressed. In assignment. The complementary goals were to demonstrate
Part 2, the student is asked to write a program that ns on the values in both being able to leverage known-good
the green LED when the switch is not pressed, and ns on starting points in a design, as well as breaking down a larger
the red LED when the button is pressed. problem into more manageable pieces that can be attacked
The third exercise has two parts. In Part 1, the students separately - and parallelized as time and resources permit.
write a program that controls the brightness of the green The laboratory assignment consisted of four exercises.
LED by reading the pot voltage and setting the brightness The rst exercise built upon the color mixing challenge rom
according to the rotation angle of the pot: all the way in one the last part of the previous week's lab project, however it
direction ns the LED off; all the way in the opposite added two requirements. First, mixing of the RGB LED
direction tuns the LED to ull brightness; and in between, colors could only occur only when one of three designated
the brightness varies in proportion to the angle of the pot. In switches respectively were pressed and held down. Second,
Part 2, the students are asked to write a program that mixes the program would have to continuously output the raw pot
the red and blue LEDs in proportional amounts as the pot voltages (0 to 1023) for the respective color and two mapped
wheel is ned. When ned all the way in one direction, values, one for the respective PWM value (0 to 255) and the
the LED is just red. When ned all the way the other other a digit (0 to 9).
direction, the LED is just blue. In between, the amount of red The remaining three exercises had pairs of teams work
and blue vary inversely as the pot wheel is ned rom one together to set up IR communication between two Arduinos.
extreme to the other. We gave the students an application progrmming interface
Unlike the other laboratory assignments, we had the (API) and implementation code for several unctions that
students work in pairs to develop and debug the Arduino would enable them to send and receive arbitrary sequences
programs. This was done in part because of limited of digits (0 - 9). In the irst of the three exercises, the
hardware, but also in part to provide the students with some transmit team had to write a program that continuously sent a
comradeship in facing a new and different programming stream of digits: 1, 2, 3, 4, and 0 with 250 ms delays between
situation. them. The receive team had to write a program to light up the
For the spring 2010 semester, which is just ending at the red gumdrop LEDs on the Experimenter board
time of this writing, we allocated two lectures and two corresponding the digit sent. In the second exercise, the
laboratory periods for embedded hardware and transmit team had to write a program that allowed a user to
progrmming. The irst of these lectures and labs repeated set the mixed color of their RGB LED and send it to another
what we did in fall 2009. The lecture in the second week Arduino. The receive team had to write a program to capture
extended concepts of modularizing C programs (i.e., into a the RGB data that was sent by the transmit team, and display
user-interface description (.h ile(s» and implementation (.c the same mixed color on their RGB LED. The transmitting
ile(s», went into more detail about analog output via PWM, Arduino had to encode the mixed color of its RGB LED as a
and introduced the laboratory assignment for the week. In the sequence of three values, each in the range of 0 - 9. Finally,
laboratory for the second week, we had the students work in the third exercise, the transmit team had to write a
with the Arduino, Spartronics Experimenter, nd a small program that allowed a user to send one of eight tones in an
inrared (lR) transceiver board that we designed and octave scale determined by pressing four switches on the
fabricated by hand. The core elements of the transceiver Experimenter and by the setting of the pot: CCW of 'center'
were a TSOP2438 IR receiver module and an LTE-302-M allows the lower four notes to be sent; CW of center allows
IRLED. the higher four notes to be sent. The tones were to be coded
We wanted the experiment in the second week to build by a digit in the range of 0 to 7. The receive team had to
upon what the students leaned in the previous week nd give write a program to capture the tone data and play the
them a taste of how a relatively sophisticated application corresponding tone on their Arduino.
(essentially an IR remote control) could be implemented with
a microcontroller, a few simple components, and sotware v. OUTCOME ND FUTURE PLNS
that thy could write. We were guided by the desire to Feedback rom the students about the renovated course
demonstrate a practical solution to a problem that could be has been positive so far. Table 1 below includes excerpts of
understood completely in both its sotware and hardware the results rom questions asked in the exit survey:
implementation. Another goal was to enable multiple teams In response to open-ended questions about what they liked
to solve a single-system solution in cooperation with each best about ME 30 many students had eusive praise for the
other, as complete success was not achievable having only microcontroller laboratoy project. For example:
one side (transmitter or receiver) unctioning correctly. We HI liked working with the microcontroller where
designed the experiment to be compatible with a consumer you can proram the device to actually do
product IR remote control, so that intermediate testing could something, instead ofjust seeing the output on the
74
screen. More hans-on work with devices like the to purchase components and to get boards fabricated, as well
Arduino would be reat. " as help rom the technicians in the College of Engineering
75