USB and Serial Communication
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.
- Arduino Uno
- Arduino Leonardo
- USB A-B Cable
- USB A-Micro B Cable
- Red LED
- Common Cathode RGB LED
- 150Ω Resistor
- 220Ω Resistor (x3)
- 10kΩ Resistors (x2)
- TMP36 Temperature Sensor
- Two-Axis Joystick
- Jumper Wires
- FTDI Driver Downloads
- Arduino Serial Library Reference
- PuTTY Serial Terminal Download
- Arduino parseInt() Function Reference
- Processing Download Page
- SudoGlove Processing Debugger Application
- Installing Leonardo Drivers
- Arduino millis() Function Reference
- Arduino Modulo Operator Reference
- Arduino Leonardo Mouse and Keyboard Library References
- List of Arduino Special Keys (for the Keyboard Library)
- TMP36 Datasheet (PDF)
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
Follow along with this video for a visual tutorial on 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:
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.