Chapter 6

USB and Serial Communication

Chapter Summary

This chapter covered the following concepts:

  • Arduinos connect to your computer via a USB-to-serial converter.
  • Different Arduinos facilitate a USB-to-serial conversion using either dedicated ICs or built-in USB functionality.
  • Your Arduino can print data to your computer via your USB serial connection.
  • You can use special serial characters to format your serial printing with newlines and tabs.
  • All serial data is transmitted as character that can be converted to integers in a variety of ways.
  • You can send comma-separated integer lists and use integrated functions to parse them into commands for your sketch.
  • You can send data from your Arduino to a Processing desktop application.
  • You can receive data from a Processing application on your desktop to control peripherals connected to your Arduino.
  • An Arduino Leonardo can be used to emulate a keyboard or mouse.

Parts List

Useful Links

Errata

Code errata listed below are corrected in the code downloads available from this page, and from github.

  • In code listing 6-9, the pinMode comment in setup() incorrectly stated that the LED was blue when it should actually be red.

Color Wiring Diagrams

Videos

Follow along with this video for a visual tutorial on serial communication and processing:
Source: http://www.jeremyblum.com/2011/02/07/arduino-tutorial-6-serial-communication-and-processing/

Watch a demo of the live temperature and light logger created in the chapter:

Watch a demo of the light-activated computer lock created in the chapter:

Watch a demo of the joystick mouse created in the chapter:

Code

Chapter 6 Code Download

All code is licensed via the GNU GPL v3. Code is maintained and updated on GitHub. The download zip linked above always contains the most recent version of the code examples that have been pushed to the GitHub Code Repository.

Taking it Further

Use the new skills you learned in this chapter to build exciting new projects! Here are some suggestions:

  • Write a Processing sketch that connects to Twitter and tweets out an announcement every time your Arduino detects movement in your room.
  • Use a Leonardo to make a gamepad that enables you to quickly execute key combinations for your favorite video game.
  • Use a Leonardo to make a physical lock button for your computer that sends a screen lock key combination when a physical button is pressed.
  • Hook up a dozen LEDs to your Arduino and create a Processing GUI to control each of them or to activate different flashing patterns.
  • Use Processing to create a graphical display of analog values changing on ADC inputs to your Arduino.

References & Credits

  • Figure 6-1: Serial Port Image Credit: Public Domain from Wikipedia. (source)
  • Figure 6-3: FTDI Cable Image Credit: Adafruit Industries, www.adafruit.com (source)
  • Figure 6-9: ASCII Table Credit: Ben Borowiec, www.benborowiec.com (source)