6. Communicating via the USB-to-TTL-Serial Adapter

6.a. Communicating via the Serial Control Lines

One bonus feature of the Pololu USB AVR programmer is the USB-to-TTL-serial adapter, which can be used for connecting microcontroller projects to a personal computer. The programmer’s drivers make the USB-to-TTL-serial adapter look like a standard serial port to the operating system, allowing you to use existing terminal programs and software that are designed to use serial ports. This feature is similar to the Pololu USB-to-serial adapter product, except the programmer has fewer control lines available and transmits at 5 V.

The TX and RX lines of the programmer are used to send asynchronous serial communication. When the programmer receives a byte from the computer via USB, it will transmit that byte on the TX line. When the programmer receives a byte on the RX input line, it will send that byte back to the computer via USB.

The bytes are sent and received eight bits at a time, with no parity and one stop bit. This coding is sometimes abbreviated 8N1. The bits must be non-inverted, meaning that a zero is sent as low voltage, and a one is sent as high voltage. All devices involved in asynchronous serial communication need to agree ahead of time on the duration of one bit (the baud rate), so all devices must be independently configured to run at the same baud rate before they will be able to communicate with each other. The USB AVR programmer supports all integer baud rates from 110 to 115200 bits per second. The following figure is an example of an 8N1 TTL serial byte:

To use the USB-to-TTL-serial adapter, you must first determine what port name the operating system has assigned it.

To determine the port name in Microsoft Windows, open the Device Manager, expand the “Ports (COM & LPT)” list, and look for the “Pololu USB AVR Programmer TTL Serial Port” entry. The port name will be at the end of this line in parentheses (e.g. “COM4”). In Windows, a given device will always be associated with the same port unless you manually change its port assignment (see Section 3.a).

In Windows, the Device Manager shows which port name is assigned to the Pololu USB AVR Programmer’s USB-to-TTL-serial adapter.

To determine the port name in Linux, type ls /dev/ttyACM*. The port name will be one of the devices listed there. If there are only two ports, then the USB-to-TTL-serial adapter will be /dev/ttyACM1 (and the programming port will be /dev/ttyACM0). If you see more than two ports, then you should look at the output from dmesg when you plug in the USB AVR programmer to see which two ports are created; the second port is the USB-to-TTL-serial adapter. In Linux, the port name depends on how many other devices are using the USB CDC ACM driver to create virtual serial ports at the time the USB AVR Programmer is plugged in.

The USB AVR Programmer’s two serial ports in Linux.

After determining the port name, you can use any serial port software to communicate on that port.

There are many free terminal programs available, including PuTTY (Windows or Linux), Tera Term (Windows), and Br@y Terminal (Windows). Advanced users developing scripted applications may prefer the free terminal program kermit. To use any of these terminal programs with the USB-to-TTL-serial adapter, you must specify the port name determined above and your desired baud rate. The characters you type will be transmitted on the programmer’s TX line. Bytes received by the programmer on the RX line will be displayed on the screen by the terminal program.

PuTTY is a free Windows terminal program that can send and receive bytes on a serial port.

If you need to send and receive non-ASCII bytes, you can use the Pololu Serial Transmitter Utility for Windows.

You can also write a computer program to use the serial port. The freely available Microsoft .NET framework contains a SerialPort class that makes it easy to read and write bytes from a serial port. Here is some example C# .NET code that uses a serial port:

// Choose the port name and the baud rate.
System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort("COM4", 115200);

// Connect to the port.
port.Open();

// Transmit two bytes on the TX line: 1, 2
port.Write(new byte[]{1, 2}, 0, 2);

// Wait for a byte to be received on the RX line.
int response = port.ReadByte();

// Show the user what byte was received.
MessageBox.Show("Received byte: " + response);

// Disconnect from the port so that other programs can use it.
port.Close();