#20
Serial
Communications:
Part 3
Follow along with this series!
Joe’s book & kits are available in our
webstore at www.nutsvolts.com
by Joe Pardue
Recap
This will be the last part of our mini series on serial
communications between a PC and the Arduino. We will
do two things this month. First, we will use what we
learned in the last two articles about C# .NET
programming to build an Arduino voltmeter that displays
ADC data on the PC. Second, we will introduce the
FT232R device that the Arduino board uses to mediate
serial communications. For this device, we will learn how
to use some of the extra FT232R pins, and we’ll look at
how the Arduino uses this device to automatically reset
the board.
Arduino Voltmeter
Using the Arduino Voltmeter
A word of warning for those who think running with
■ FIGURE 1. Arduino voltmeter.
54
March 2010
scissors is a good idea. The Arduino voltmeter hooks
directly to the Arduino analog input pin 0 which can
measure up to five volts. THIS CIRCUIT IS NOT
PROTECTED IN ANY WAY. It will not forgive you doing
something stupid like trying to measure the voltage in the
wall socket. If you survive such a Darwinian experiment,
your hardware won’t and that could include the PC you’ve
got your Arduino hooked up to (most USB ports are
protected, but you can never be absolutely certain).
The Arduino Software
The Arduino voltmeter running on the PC (shown in
Figure 1) is communicating with the following AVR_Test
program running on the Arduino:
// AVM_Test
// Joe Pardue December 17, 2009
// based on Tom Igoe’s example in the
// Arduino Serial.print(data) documentation
void setup()
{
// begin the serial communication
Serial.begin(19200);
}
// variable to hold the analog input value
int analogValue = 0;
void loop()
{
// read the analog input on pin 0
analogValue = analogRead(0);
// print as an ASCII-encoded decimal
Serial.print(analogValue, DEC);
// print a terminal newline character so the
AVR Voltmeter
// will know that it has received the full
string
Serial.print(‘\n’);
// delay 1 second before the next reading:
delay(1000);
}
The PC Software
The Arduino voltmeter (AVM) source code in C# is
provided in Workshop20Source.zip and requires Visual