Hardware Reference
In-Depth Information
program to connect to your serial ports is indispens-
able. There are several freeware and shareware terminal
programs available. CoolTerm is an excellent piece of
freeware by Roger Meier available from http://freeware.
the-meiers.org . It works on Mac OS X and Windows, and
it's my personal favorite these days. If you use it, do the
right thing and make a donation because it's developed in
the programmer's spare time. For Windows users, PuTTY
is a decent alternative because it can open both serial and
ssh terminals. PuTTY is also available for Linux. Alterna-
tively, you can keep it simple and stick with a classic: the
GNU screen program running in a terminal window. OS X
users can use screen as well, though it's less full-featured
than CoolTerm.
Who's Got the Port?
Serial ports aren't easily shared between applica-
tions. In fact, only one application can have control
of a serial port at a time. If PuTTY, CoolTerm, or the
screen program has the serial port open to an Arduino
module, for example, the Arduino IDE can't download
new code to the module. When an application tries to
open a serial port, it requests exclusive control of it
either by writing to a special file called a lock file , or by
asking the operating system to lock the file on its behalf.
When it closes the serial port, it releases the lock on
the serial port. Sometimes when an application crashes
while it's got a serial port open, it can forget to close
the serial port, with the result that no other application
can open the port. When this happens, the only thing
you can do to fix it is to restart the operating system,
which clears all the locks (alternatively, you could wait
for the operating system to figure out that the lock
should be released). To avoid this problem, make sure
that you close the serial port whenever you switch from
one application to another. Linux and Mac OS X users
should get in the habit of closing down screen with
Ctrl-A then Ctrl-\ every time, and Windows users should
disconnect the connection in PuTTY. Otherwise, you may
find yourself restarting your machine a lot.
Windows serial communication
To get started, you'll need to know the serial port name.
Click Start Run (use the Search box on Windows 7), type
devmgmt.msc , and press Enter to launch Device Manager.
If you've got a serial device such as a Wiring or Arduino
board attached, you'll see a listing for Ports (COM & LPT) .
Under that listing, you'll see all the available serial ports.
Each new Wiring or Arduino board you connect will get a
new name, such as COM5, COM6, COM7, and so forth.
Once you know the name of your serial port, open PuTTY.
In the Session category, set the Connection Type to Serial,
and enter the name of your port in the Serial Line box,
as shown in Figure 1-6. Then click the Serial category at
the end of the category list, and make sure that the serial
line matches your port name. Configure the serial line for
9600 baud, 8 data bits, 1 stop bit, no parity, and no flow
control. Then click the Open button, and a serial window
will open. Anything you type in this window will be sent out
the serial port, and any data that comes in the serial port
will be displayed here as ASCII text.
Adventurous Mac OS X users can take advantage of the
fact that it's Unix-based and follow the Linux instructions.
Linux serial communication
To get started with serial communication in Linux (or Mac
OS X), open a terminal window and type:
NOTE: Unless your Arduino is running a program that communi-
cates over the serial port (and you'll learn all about that shortly),
you won't get any response yet.
ls /dev/tty.* # Mac OS X
ls /dev/tty*
# Linux
Mac OS X serial communication
To get started, open CoolTerm and click the Options icon.
In the Options tab, you'll see a pulldown menu for the port.
In Mac OS X, the port names are similar to this: /dev/tty.
usbmodem241241 . To find your port for sure, check the
list when your Arduino is unplugged, then plug it in and
click Re-scan Serial Ports in the Options tab. The new
port listed is your Arduino's serial connection. To open the
serial port, click the Connect button in the main menu. To
disconnect, click Disconnect.
This command will give you a list of available serial ports.
The names of the serial ports in Mac OS X and Linux are
more unique, but they're more cryptic than the COM1,
COM2, and so on that Windows uses. Pick your serial port
and type:
screen portname datarate .
Search WWH ::




Custom Search