Hardware Reference
In-Depth Information
supports a USB host class that enables you to plug a keyboard or mouse into
the Due's on-the-go USB port to control it. The Arduino Mega ADK uses the
Android Open Accessory Protocol (AOA) to facilitate communication between
the Arduino and an Android device. This is primarily used for controlling
Arduino I/O from an application running on the Android device.
Two Arduino boards that have USB-host capabilities are the Arduino Due
and the Arduino Mega ADK (based on Mega 2560).
ListeningtotheArduino
The most basic serial function that you can do with an Arduino is to print to
the computer's serial terminal. You've already done this in several of the previ-
ous chapters. In this section, you explore the functionality in more depth, and
later in the chapter you build some desktop apps that respond to the data you
send instead of just printing it to the terminal. This process is the same for all
Arduinos.
UsingprintStatements
To print data to the terminal, you only need to utilize three functions:
Serial.begin(baud_rate)
Serial.print("Message")
Serial.println("Message")
where baud_rate and "Message" are variables that you specify.
As you've already learned, Serial.begin() must be called once at the start
of the program in setup() to prepare the serial port for communication. After
you've done this, you can freely use Serial.print() and Serial.println()
functions to write data to the serial port. The only difference between the two
is that Serial.println() adds a carriage return at the end of the line (so that
the next thing printed will appear on the following line). To experiment with
this functionality, wire up a simple circuit with a potentiometer connected to
pin A0 on the Arduino, as shown in Figure 6-6.
 
Search WWH ::




Custom Search