You are on page 1of 10

Proceedings of the ASME 2015 International Design Engineering Technical Conferences &

Computers and Information in Engineering Conference


IDETC/CIE 2015
August 2-5, 2015, Boston, Massachusetts, USA

DETC2015-47837

PROGRAMMING ARDUINO BOARDS WITH THE C/C++ INTERPRETER CH

Curtis Turley, URA∗ Maria Alessandra Montironi, PhD candidate†


Integration Engineering Laboratory Harry H Cheng, Professor‡
Department of Mechanical and Aerospace Engineering Integration Engineering Laboratory
University of California Department of Mechanical and Aerospace Engineering
Davis, California 95616 University of California
Email: caturley@ucdavis.edu Davis, California 95616

ABSTRACT merical analysis, and plotting capabilities. The supported com-


This paper presents the ChArduino package which is de- munication protocols between the Arduino board and the com-
signed to control the Atmel AVR microcontroller based Arduino puter are serial and Bluetooth. The application code written us-
boards through the C/C++ interpreter Ch. Traditionally, Ar- ing this package is completely compatible with the entire spec-
duino boards are programmed using the official Arduino IDE trum of Arduino boards and can be ported to the Arduino IDE
or lower-level AVR C libraries. These methods require specific with minimal changes. The applications of the method described
cross-compilation tools to compile the code and upload it onto in this paper are general but apply especially to the K-12 educa-
the board. Whenever a change is made to the source code, it tion field in that the package creates a simple, user-friendly, envi-
needs to be recompiled and uploaded, making application de- ronment for the absolute beginner to learn the basic principles of
velopment cumbersome, especially for beginners and as the size mechatronic systems including programming, microcontrollers,
of the application grows. The approach presented in this paper and electrical circuits. Lesson plans are being developed to use
is aimed at reducing the effort associated with code compilation, the ChArduino package in microcontroller introductory courses
especially in classroom environments where microcontroller pro- and the package is currently being introduced for preliminary
gramming is first introduced. In fact, when using this method, testing in schools through the UC Davis C-STEM Center.
code is executed in an interpreted manner and every function
call is processed separately by the interpreter, thus compilation
and uploading are not required to make changes effective. The
INTRODUCTION
ChArduino package consists of a library of functions running on
a computer and a specialized firmware loaded onto the Arduino Microcontrollers are computers designed to accomplish a
board. The firmware on the Arduino board is pre-compiled and specific task. Usually, the task they are designed for is to in-
the latest version is automatically uploaded at run time, if not terface with and control some hardware components. Due to the
already. At power-up, the firmware initializes the board and then specific applications they are designed for, microcontrollers have
waits for a command from the computer. The use of the C/C++ some distinctive characteristics, for example: small size to be
interpreter Ch also makes available line-by-line debugging, nu- embedded in the device they need to control, dedicated I/O lines
to directly interface with the hardware and low power consump-
tion [1]. Many different examples of microcontrollers can be
∗ Undergraduate
found currently on the market.
Research Assistant
† mmontironi@ucdavis.edu Exploiting the functionalities of microcontrollers, in the last
‡ Address all correspondence to this author: hhcheng@ucdavis.edu

1 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


decade, many electronic boards have been developed to simplify project grows or when the program is still in the development
the use of microcontrollers in hardware interfacing and control. phase and frequent changes need to be made.
Examples are the Arduino [2], the BeagleBone Black [3] or the The strategy presented in this paper aims to overcome this
Parallax Propeller [4]. All these boards have different layouts, issue. It consist of a software package named ChArduino that
processing power and type of hardware with which they can in- allows the user to control an Arduino board from the C/C++ in-
terface. However, they are based on the same core concept: ex- terpreter Ch [15].The package allows the user to use most of the
posing the I/O functionalities of a microcontroller to simplify functions available in the Arduino IDE but, since the code is in-
interfacing with the hardware. terpreted, there is no need to recompile and upload the program
Applications of these boards are diversified from sensor net- to the board every time a change is made.
works [5] [6] [7] to home automation [8] [9] to robotics [10] [11] This software package was developed at the UC Davis C-
and to education [12] [13] [14]. When associated with a STEM Center [16] with the specific purpose of providing be-
well structured programming environment, these boards have ginners a tool to learn how to program microcontrollers without
proven to be a powerful tool to teach beginners the concepts of having to deal with lower-lever programming issues.
programming and how to apply microcontrollers to real-world The rest of the paper has the following structure. First, a
problems. brief description of the C/C++ interpreter Ch is given, then, the
implementation of the ChArduino package is described in detail.
Some sample code is shown and compared to the same one writ-
ten in the Arduino IDE. Finally, some applications are described.

THE C/C++ INTERPRETER Ch


Ch is a C/C++ interpreter and scripting language environ-
ment that supports all the features in the ISO C90 standard [17].
When running a C/C++ program through Ch, code can also be
written and executed from the graphical interface ChIDE. Run-
ning interpreted code means that there is no need to compile the
program. This feature makes Ch particularly suited for teach-
ing applications because it relieves students from having to deal
with lower level compilation issues and allows to focus only on
learning the language [18] [19] .
Ch also supports a number of advanced mathematical fea-
tures like variable length arrays [20], complex numbers [21]
and plotting that make it an useful tool for engineering applica-
tions [22] [23] [24]. These features make Ch a particularly suited
development environment for the software package described in
this paper.
FIGURE 1: SEQUENCE OF STEPS TO PROGRAM A MICRO- Ch runs on many different Operating Systems, among which
CONTROLLER Windows, Linux and Mac OS thus allowing to easily run the
same application program on different platforms.

Figure 1 shows the general programming procedure used to


write, compile and upload a program into a microcontroller. The STRUCTURE OF THE ChArduino PACKAGE
code needs to be written on a host computer, the developing sys- Figure 2 shows the some of the hardware and software com-
tem, usually in C. Then, specific software tools are needed to ponents that are integrated by the ChArduino package. Code
cross-compile the code for the target microcontroller architecture is written in ChIDE to program and Arduino board and make
and to upload it. it interface with different hardware components such as LEDs,
When using a board like Arduino, usually, its I/O pins are small DC motors, or an LCD. The ChArduino software package
connected to an external actuator or electric circuit that can be is composed of two parts whose implementation is described in
controlled by a program running on the microcontroller. When- the following sections. One part runs on the host computer and
ever a change is made to the code, the whole application program the other runs on the target Arduino board. Figure 3 shows how
needs to be recompiled and uploaded onto the board. This pro- the different software components of the package are intercon-
cess becomes more and more time consuming as the size of the nected and the data flow in a generic operating system.

2 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


FIGURE 2: HARDWARE AND SOFTWARE COMPONENTS
INTEGRATED BY THE ChArduino PACKAGE

Software that runs on the host computer


The computer-side of the ChArduino package consists of
two header files, ”arduino.h” and ”bluetooth.h”, a single Ch
function file, ”arduino.chf”, and the firmware upload utility,
”avrdude”. The header file ”arduino.h” contains the prototypes
of all the functions for controlling the I/O pins, programming
an LCD, and driving a servo motor. It also contains all the
functions needed to establish the serial connection between the
FIGURE 3: ChArduino COMMUNICATION FLOW
board and the host computer. The header file ”bluetooth.h” con-
tains a macro that configures the communication for Bluetooth
instead of wired. The Ch function file ”arduino.chf” contains
the definition of all the functions declared in the header file ”ar- ”avrdude” utility as a separate process. If the firmware is suc-
duino.h”. The firmware upload program, ”avrdude”, is an open cessfully uploaded, the application program begins.
source utility for uploading firmware from a host computer onto If Bluetooth communication is desired, the ”bluetooth.h”
a target AVR-based microcontroller. The ChArduino software is header file also needs to be included at the beginning of the ap-
currently supported and tested for Windows 7, 8, and 8.1. plication program, before ”arduino.h”. This header file defines
To run a Ch program to control an Arduino through a wired a macro that disables the automatic scanning of the serial ports.
USB-serial connection, a user only needs to include the ”ar- Instead, a function must be called to explicitly establish the con-
duino.h” header file. When the header file is included, functions nection using the ID of the serial port with the Bluetooth device.
are called to automatically detect the Arduino board and establish When a function is called from Ch, a message composed of
a connection. a sequence of bytes is sent to execute the corresponding func-
Once the connection has been successfully established, a tion on the Arduino. This sequence of bytes follows a predefined
string of bytes is sent to the Arduino containing to verify the protocol where the value of the first byte identifies the function
type of firmware running on the board. If the version number to be executed, the second byte is the number, n, of bytes in the
matches, then the board will respond with an acknowledgment message, the third to n-1 bytes are the arguments of the function
and the execution of the application program begins. If there is to be executed, and the last byte is the end-of-message byte, 255.
no response from the Arduino, or the response is incorrect, then Once the message is sent, the function waits for a response from
it is assumed the firmware is missing or incorrect and the user the Arduino, and assigns the content of the response message as
is prompted to upload the correct firmware. Through a series of the return values of the function call, if necessary. This process is
prompts, the user inputs the target platform and the appropriate repeated for every function call. The Arduino responds to every
firmware is uploaded. The firmware is uploaded by using the message sent with a byte whose value identifies the status of the

3 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


TABLE 1: LIST OF THE FUNCTIONS IMPLEMENTED IN countering the EOM byte. If successfully received, the message
THE ChArduino PACKAGE. is then parsed by a processing function. The processing func-
tion uses the first byte of the message, the byte representing the
command, to access a switch statement. Each case of the switch
statement corresponds to a specific function call. If the first byte
SUPPORTED BASIC FUNCTIONS of the message does not match any of the commands known to
the firmware, a special byte is sent back to the host computer in-
void pinMode(int pin, int mode) dicating that the firmware did not recognize the command. The
int digitalRead(int pin) arguments needed for a specific command are acquired by pars-
ing the body of the message. Once the appropriate function has
void digitalWrite (int pin, int value) been called, a string containing a response message is sent back
int analogRead(int pin) to the host computer. The first byte of the response indicates suc-
cess or failure, the middle bytes contain any return data, and the
void analogWrite (int pin, int value) last byte is an end-of-message byte. Once the response is sent
void delay(int milliseconds) back to the computer the serial handler function resumes check-
ing for incoming messages.
int millis(void) During compilation, the firmware code is linked against the
int random(int min, int max) basic Arduino libraries and the ”Servo” and ”LiquidCrystal”
libraries allowing for the use of standard, pre-written, functions
void tone(int pin, int frequency, int time) for serial communication and I/O interfacing. In particular,
void noTone(int pin) the ”Servo” library allows to control servo motors and the
”LiquidCrystal” library allows to interface with an LCD. The
ADDITIONAL SUPPORTED LIBRARIES source code for these libraries is distributed with the Arduino
Serial IDE. The firmware to upload on the Arduino board is distributed
as a pre-compiled .hex file for all the supported Arduino boards
Servo and provided within the ChArduino package.
LiquidCrystal

Sample Code
Figure 4 shows a simple Ardiuno program written in Ch.
function execution. The response can have three different values The code is written using the same structure as programs writ-
corresponding to success, failure or command not recognized. If ten in the Arduino IDE. First, variables are defined, then the
a failure or command not recognized response is received, an- ”setup()” function is defined to initialize the I/O pins. Finally,
other attempt is made to resend the message for a maximum of the ”loop()” function is defined for repeatedly performing a spe-
10 trials. Some of the Arduino-specific functions currently im- cific task. This first section of the sample code is completely
plemented in the ChArduino package are shown in Table 1. compatible with that written the Arduino IDE. The only differ-
ences are that, in the Ch program, the ”arduino.h” header must
be included at the beginning and the ”main()” function must be
Firmware
called at the end. Inside it, the ”setup()” function is called once
The ChArduino firmware consists of one header file and
and ”loop()” repeatedly using an infinite while-loop. When writ-
one C program file. The header file contains function decla-
ing a program in the Arduino IDE, this last block of code does
rations and an enumeration structure for listing all the possible
not need to be included because all of the standard headers are
commands that can be received. The function file contains all
automatically included and the ”main()” function is automati-
the function definitions. An infinite while-loop in the ”main()”
cally added to the end of the code during compilation.
function continuously calls a serial handler function to process
incoming commands. The serial handling function will recur-
sively read any incoming data and store that into an array until the
end-of-message (EOM) byte, 255, is encountered. The incoming
message is only considered valid if the length of the message in
bytes matches the value of the second byte of the message. If
the length and second byte do not match, an error byte is sent to
the computer and the message is not parsed and is cleared on en-

4 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


1 #include <arduino.h> other Arduino functions can be supported in Ch by ChSDK [25]
2 Any such incompatibilities must be removed or replaced before
3 int pinNumber = 13; porting the code from one platform to the other.
4
5 void setup(){
6 pinMode(pinNumber, OUTPUT); Initialization Overhead and Function Execution Time
7 } Comparison
8 Data was taken to measure the initialization overhead and
9 void loop(){ function execution time using ChArduino in the ChIDE and us-
10 digitalWrite(pinNumber, HIGH); ing the Arduino IDE. The initialization overhead for ChArduino
11 delay(500); was measured before and after initialization for the two primary
12 digitalWrite(pinNumber, LOW); use cases, the first being when the firmware needs to be uploaded
13 delay(500); and the second being when the correct firmware is already on the
14 } Arduino thus the firmware upload part is skipped. The initial-
15 ization overhead for the Arduino IDE was measured for the two
16 int main(){ primary use cases, the first being when a new firmware is up-
17 setup(); loaded to the Arduino and the second being when a previously
18 while(1){ uploaded firmware is re-uploaded after small changes. The sec-
19 loop(); ond case is the normal use case. All times were measured with
20 } the IDEs running the same program file and then measurements
21 return 0; were taken for each case. The function execution times were
22 } measured for both IDEs by using the difference in system time
before and after the function call.
Function execution times were measured for basic Arduino
FIGURE 4: Ch CODE FOR ARDUINO
functions: pinMode(), digitalRead(), digitalWrite(), analo-
gRead(), and analogWrite(). Fifty time measurements were
1 int pinNumber = 13; taken for each function call in each IDE. The mean, µ, and stan-
2 dard deviation, σ , of the time required for the program initializa-
3 void setup(){ tion and for the function execution are listed in Table 2. Measure-
4 pinMode(pinNumber, OUTPUT); ments were taken using Ch Professional 7.1 Beta and Arduino
5 } IDE 1.6.2 using a 64 bit Intel-Core i5-2410M CPU @ 2.30 GHz
6 running Windows 7.
7 void loop(){ Considering the two common use cases: ChArduino with
8 digitalWrite(pinNumber, HIGH); no firmware upload and Arduino IDE with small changes to the
9 delay(500); same file, the initialization of ChArduino is around 25 times
10 digitalWrite(pinNumber, LOW); faster than in the Arduino IDE because it requires only estab-
11 delay(500); lishing a connection over the serial port and not to compile and
12 } upload the firmware. Regarding the function execution time the
code compiled and uploaded through the Arduino IDE is approx-
FIGURE 5: EQUIVALENT ARDUINO IDE CODE imately 600 times faster than that run using ChArduino. The to-
tal program run time can be expressed as a linear function of the
number of functions executed, where the initial condition is the
initialization time and the slope is the function execution time,
The equivalent code for Figure 4 in the Arduino IDE is
both of which come from Table 2. This relation is plotted in Fig-
shown in Figure 5. The code can be easily ported between Ch
ure 6 for both ChArduino and the Arduino IDE. The run times of
and the Arduino IDE by including or not the ”arduino.h” header
the two intersect at 198.55 function, thus ChArduino is advanta-
file at the beginning of the program and the ”main()” function at
geous when the number of executed functions is more than 200.
the end of the program.
After this number of function calls, the ChArduino slower func-
While simple code like that shown in Figures 4 and 5 is very
tion execution will cancel out its faster initialization time. How-
compatible, incompatibilities may arise with complexity. The
ever, in educational applications the number of executed function
Arduino IDE cannot support Ch’s unique variable types or any
would typically be less than 200.
plotting or numerical analysis functions and Ch by default cannot
support lower-level or non-basic Arduino functions. However,

5 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


TABLE 2: AVERAGE (µ) AND STANDARD DEVIATION (σ ) straightforward especially for beginners.
TIMES FOR PROGRAM INITIALIZATION AND FUNCTION • Ch provides a line by line debugger that allows to step
EXECUTION through the execution of each individual function.
• Ch provides advanced mathematical and plotting features.
The ChArduino package can therefore be embedded in a
µ [ms] σ [ms] larger engineering application.
INITIALIZATION Considering the advantages just listed, executing a program
ChArduino Initialization Time 13256.9 492.6 in an interpreted way can prove to be a useful tool when develop-
(w/ upload) ing a microcontroller-based application, especially in classroom
environments where the concepts related to microcrontrollers
ChArduino Initialization Time 148.7 0.9 programming are first introduced.
(w/o upload) However, when using this method, some of the features of
Arduino IDE Initialization Time 11770 263.9 the normal operation of a microcontroller are lost. In particular,
(new program) the execution of the code is slower since every command needs
to be sent from the computer to the board instead of having the
Arduino IDE Initialization Time 3740 81.49 whole set of instructions running directly on the board. For the
(small changes to the same pro- current implementation of the ChArduino package, the require-
gram) ment for a constant connection to a computer limits its applica-
bility in real-time processing since interrupts and timer manipu-
FUNCTION EXECUTION
lations are not handled. However, the ChArduino package was
ChArduino Function Execution 18.118 0.145 developed principally as a tool to introduce K-12 students to the
Time use and programming of microcontrollers. Real-time applica-
tions involve more advanced features that can be initially ignored
Arduino Function Execution 0.0302 0.042
and are therefore considered not a concern for the current imple-
Time
mentation.
The time overhead related to running the same code through
the ChArduino package and directly uploading it to an Arduino
board was evaluated in different situations and result shave been
included.

APPLICATIONS
This section describes some of the current applications of
the ChArduino package.

Introduction to programming microcontrollers in K-12


education
The main purpose of the ChArduino package is to provide
a quick and easy to understand way to teach K-12 students the
basis of building electrical circuits and programming microcon-
trollers. Together with the software, the ChArduino package is
distributed with an example book. From the book students are
FIGURE 6: COMPARISON OF EXECUTION TIMES
first introduced to the basic components of electric circuits such
as resistors, capacitors and LEDs. Then, the structure of a mi-
crocontroller is introduced. A series of tutorials walks students
Advantages
through projects of increasing complexity where they build an
This section sums up the main advantages of using the
electric circuit and program the Arduino to interact with that cir-
ChArduino package for programming Arduino microcontrollers.
cuit.
• When the code is executed in an interpreted way, it doesn’t For example students learn how to write programs to control
need to be recompiled after every change. This makes the digital switches to turn on and off a sequence of LEDs. Other
process of developing and testing new applications more projects teach students the difference between digital and analog

6 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


signals while reading data from temperature or light sensors or 26 /* Display data */
running a small DC motor. 27
28 Serial.print("Sensor Value:");
29 Serial.print(light[index])
Data acquisition and processing 30 Serial.print("\t Time:");
Other than regular C/C++ functionalities, Ch provides ad- 31 Serial.println(time[index]);
vanced mathematical and plotting features that can be used to 32
perform data acquisition and processing from the same applica- 33 delay(interval);
tion program. In general, due to hardware limitations, this type of 34 }
processing is not possible when running a data acquisition pro- 35
gram on a microcontroller and a separate post-processing pro- 36 int main(){
gram is needed to analyze the data. 37 setup();
Figures 7 and 8 show an application program that uses the 38 while(index < size) {
functions in the ChArduino package to read analog data from 39 loop();
a sensor. Data is stored in arrays, displayed and plotted using 40 index++;
the Ch plotting capabilities. This example shows how the math- 41 }
ematical and plotting features available in Ch can be integrated 42 /* Plot data */
with the ChArduino package to acquire and process data in a sin- 43
gle application program. Figure 9 is a plot obtained running the 44 CPlot plot;
code in Figures 7 and 8 to acquire, display and plot data from a 45 plot.title("Light vs. Time");
light sensor. 46 plot.label(PLOT_AXIS_X, "Time(s)");
47 plot.label(PLOT_AXIS_Y, "Light intensity")
48 plot.data2DCurve(time, light, size);
1 /* plotData.ch: Test Program to acquire 49 plot.plotting();
2 and plot data from a sensor */ 50
3 51 return 0;
4 #include <arduino.h> 52 }
5 #include <chplot.h>
6
FIGURE 8: SAMPLE Ch CODE FOR DATA ACQUISITION
7 const int pin = A0;
AND PROCESSING. PART 2.
8
9 int index = 0,
10 interval = 100,
11 size = 100;
12
13 array double light[size], time[size];
14
15 void setup(){
16 Serial.begin(9600);
17 }
18
19 void loop(){
20
21 /* Acquire data */
22
23 light[index] = analogRead(pin);
24 time[index]=(index*interval)/1000.0;
25

FIGURE 7: SAMPLE Ch CODE FOR DATA ACQUISITION


AND PROCESSING. PART 1.

7 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


FIGURE 10: ROBOTIC PLATFORM

1 /* driveforward.ch: Test Program to control


2 a robot from Ch */
3 #include <arduino.h>
FIGURE 9: LIGHT INTENSITY PLOT
4
5 /* Global variables to store the information
Control of an Arduino-based robot 6 of each servo motor */
A simple library of functions was developed using the func- 7 Servo servoLeft;
tions in the ChArduino package to control a small robot. The 8 Servo servoRight;
library contains functions for driving and steering the robot. The 9
platform used for testing the functions is shown in Figure 10. It 10 /* Function to drive forward */
is composed of an Arduino board driving two continuous servo 11 void driveForward() {
motors. Two switches for collision avoidance are mounted on the 12 servoLeft.write(60);
front side of the robot and connected to the Arduino. The corre- 13 servoRight.write(120);
sponding I/O pins are programmed to change the direction of the 14 }
motion in case the robot hits an obstacle. A Bluetooth dongle 15 /* Function to turn right */
is also connected to the board to establish a wireless connection 16 void turnRight() {
with the host computer. 17 servoLeft.write(120);
Figures 11 and 12 show the demo code written in Ch to con- 18 servoRight.write(120);
trol the robot. First, the header file ”arduino.h” is included, then, 19 }
some functions are defined to drive the robot forward, make it 20 /* Function to stop the robot */
turn right and stop it. Once the functions have been defined, they 21 void stopRobot() {
are called and the motions are executed. This demo code shows 22 servoLeft.write(90);
just a subset of the functions. Other functions have been imple- 23 servoRight.write(90);
mented for driving the robot backwards, make it turn left and 24 }
respond to a collision detected by the bump sensors. 25

FIGURE 11: SAMPLE CODE TO CONTROL A ROBOT


FROM Ch USING THE ChArduino PACKAGE. PART 1.

8 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


26 /* Initialize the connection The ChArduino package addresses a major issue of pro-
27 to each servo motor */ gramming microcontrollers: the need to setup a toolchain for
28 void setup() { crosscompiling and the need for recompiling and uploading the
29 servoLeft.attach(9); code every time a change is made.
30 servoRight.attach(10); That described in this paper is the first version of the
31 } ChArduino package. To allow for broader applications, a new
32 version of the package is currently being developed that, other
33 void loop() { than Windows, provides Linux and Mac OS support. Lesson
34 /* Drive the robot forward */ plans and sample applications are also being developed to use
35 driveForward(); the ChArduino package in K-12 introduction to microcontrollers
36 /* Wait 2 seconds*/ applications. Future development of the package will also be car-
37 delay(2000); ried out to investigate the possibility of extending the application
38 /* Make the robot turn right */ of the package to other types of microcontrollers.
39 turnRight();
40 /* Wait 2 seconds */
41 delay(2000);
42 /* Stop the robot */ ACKNOWLEDGMENT
43 stopRobot(); This work was supported in part by the National Sci-
44 delay(2000); ence Foundation under Grant CNS-1132709, IIS-1208690, IIS-
45 } 1256780, and IIP-1152678.

FIGURE 12: SAMPLE CODE TO CONTROL A ROBOT


FROM Ch USING THE ChArduino PACKAGE. PART 2. REFERENCES
[1] Gridling, G., and Weiss, B., 2006. “Introduction to mi-
crocontrollers”. Course Material, Vienna University of
Feedback from schools Technology, Institute of Computer Engineering, Embedded
Lesson plans are currently being developed to use the Computing Systems Group, Version, 1.
ChArduino package as a teaching tool in K-12 STEM education. [2] Arduino, 2015. Arduino home page. On the WWW, Jan-
The package is currently under preliminary testing in two high uary. URL http://www.arduino.cc/.
schools associated with the UC Davis C-STEM center. At the [3] BeagleBone, 2015. Beaglebone black home
time of writing, no formal surveys have been conducted to eval- page. On the WWW, January. URL
uate the teaching effectiveness of the curriculum, however, they http://beagleboard.org/BLACK.
will be performed at the end of the school year (June 2015). The [4] Parallax, 2015. Parallax propeller home
schools are testing the tutorials book together with the software page. On the WWW, January. URL
package. Some preliminary feedback showed that both the stu- http://www.parallax.com/product/32900.
dents and the instructor, who already knows the basic usage of [5] Boonsawat, V., Ekchamanonta, J., Bumrungkhet, K., and
the Arduino IDE, found the software intuitive and easy to use. Kittipiyakul, S., 2010. “Xbee wireless sensor networks for
temperature monitoring”. In the Second Conference on Ap-
plication Research and Development (ECTI-CARD 2010),
CONCLUSION Chon Buri, Thailand.
This paper presents a software package, ChArduino, devel- [6] Bergmann, N. W., Wallace, M., and Calia, E., 2010. “Low
oped to program an Arduino board through the C/C++ interpreter cost prototyping system for sensor networks”. In Intelli-
Ch. The package was developed at the UC Davis C-STEM Cen- gent Sensors, Sensor Networks and Information Processing
ter with the main purpose of being applied in education to pro- (ISSNIP), 2010 Sixth International Conference on, IEEE,
vide beginners with a tool to learn the basics of programming Ar- pp. 19–24.
duino microcontrollers without having to deal with lower-lever [7] Mainwaring, A., Culler, D., Polastre, J., Szewczyk, R., and
technical issues such as cross-compilation. The package can Anderson, J., 2002. “Wireless sensor networks for habitat
also be used for more advanced applications since code writ- monitoring”. In Proceedings of the 1st ACM international
ten to control an Arduino board from Ch can be ported to the workshop on Wireless sensor networks and applications,
Arduino IDE with minimal chages or be embedded in a larger ACM, pp. 88–97.
C/C++ application that exploits the debugging, advanced mathe- [8] Piyare, R., and Tazil, M., 2011. “Bluetooth based home
matical features and plotting capabilities of Ch. automation system using cell phone”. In Consumer Elec-

9 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo


tronics (ISCE), 2011 IEEE 15th International Symposium Assembly Automation, 24(2), pp. 152–158.
on, IEEE, pp. 192–195. [24] Gucwa, K. J., and Cheng, H. H., 2014. “Robosim: A
[9] Skeledzija, N., Cesic, J., Koco, E., Bachler, V., Vucemilo, simulated environment for programming modular robots”.
H. N., and Dzapo, H. “Smart home automation system for In Mechatronic and Embedded Systems and Applications
energy efficient housing”. network, 3, p. 4. (MESA), 2014 IEEE/ASME 10th International Conference
[10] Araújo, A., Portugal, D., Couceiro, M. S., and Rocha, on, IEEE, pp. 1–7.
R. P., 2013. “Integrating arduino-based educational mobile [25] SoftIntegration. The Ch Language Environ-
robots in ros”. In Autonomous Robot Systems (Robotica), ment – SDK User’s Guide. SoftIntegration, Inc.
2013 13th International Conference on, IEEE, pp. 1–6. http://www.softintegration.com.
[11] Couceiro, M. S., Figueiredo, C. M., Luz, J. M. A., Fer-
reira, N. M., and Rocha, R. P., 2011. “A low-cost educa-
tional platform for swarm robotics”. International Journal
of Robots, Education and Art.
[12] Kato, Y., 2010. “Splish: a visual programming environ-
ment for arduino to accelerate physical computing experi-
ences”. In Creating Connecting and Collaborating through
Computing (C5), 2010 Eighth International Conference on,
IEEE, pp. 3–10.
[13] Zachariadou, K., Yiasemides, K., and Trougkakos, N.,
2012. “A low-cost computer-controlled arduino-based ed-
ucational laboratory system for teaching the fundamentals
of photovoltaic cells”. European Journal of Physics, 33(6),
p. 1599.
[14] Sarik, J., and Kymissis, I., 2010. “Lab kits using the ar-
duino prototyping platform”. In Frontiers in Education
Conference (FIE), 2010 IEEE, IEEE, pp. T3C–1.
[15] Ch an embeddable C/C++ interpreter. URL
http://www. softinte-gration, com.
[16] UC Davis C-STEM Center. URL
http://c-stem.ucdavis.edu/.
[17] Cheng, H. H., 1993. “Scientific computing in the Ch
programming language”. Scientific Programming, 2(3),
pp. 49–75.
[18] Campbell, M., and Cheng, H. H., 2007. “Teaching
computer-aided mechanism design and analysis using a
high-level mechanism toolkit”. Computer Applications in
Engineering Education, 15(4), pp. 277–288.
[19] Gucwa, K. J., and Cheng, H. H., 2014. “Robosim for inte-
grated computing and stem education”. In American Soci-
ety for Engineering Education (ASEE), 2014 ASEE 121st
Annual Conference on, ASEE.
[20] Cheng, H. H., 1995. “Extending C with arrays of variable
length”. Computer standards & interfaces, 17(4), pp. 375–
406.
[21] Cheng, H. H., 1993. “Handling of complex numbers in the
Ch programming language”. Scientific Programming, 2(3),
pp. 77–106.
[22] Chen, B., Cheng, H. H., and Palen, J., 2006. “Mobile-C: a
mobile agent platform for mobile C/C++ agents”. Software:
Practice and Experience, 36(15), pp. 1711–1733.
[23] Nestinger, S. S., and Cheng, H. H., 2004. “Interactive mo-
tion control using Ch–an embeddable C/C++ interpreter”.

10 Copyright © 2015 by ASME

Downloaded From: http://proceedings.asmedigitalcollection.asme.org/pdfaccess.ashx?url=/data/conferences/asmep/86624/ on 07/18/2017 Terms of Use: http://www.asme.org/abo

You might also like