Professional Documents
Culture Documents
DETC2015-47837
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-
APPLICATIONS
This section describes some of the current applications of
the ChArduino package.