- •Acknowledgments
- •Preface
- •Who Should Read This Book
- •What’s in This Book
- •Arduino Uno and the Arduino Platform
- •Code Examples and Conventions
- •Online Resources
- •The Parts You Need
- •Starter Packs
- •Complete Parts List
- •1. Welcome to the Arduino
- •What You Need
- •What Exactly Is an Arduino?
- •Exploring the Arduino Board
- •Installing the Arduino IDE
- •Meeting the Arduino IDE
- •Hello, World!
- •Compiling and Uploading Programs
- •What If It Doesn’t Work?
- •Exercises
- •2. Creating Bigger Projects with the Arduino
- •What You Need
- •Managing Projects and Sketches
- •Changing Preferences
- •Using Serial Ports
- •What If It Doesn’t Work?
- •Exercises
- •3. Building Binary Dice
- •What You Need
- •Working with Breadboards
- •Using an LED on a Breadboard
- •First Version of a Binary Die
- •Working with Buttons
- •Adding Your Own Button
- •Building a Dice Game
- •What If It Doesn’t Work?
- •Exercises
- •4. Building a Morse Code Generator Library
- •What You Need
- •Learning the Basics of Morse Code
- •Building a Morse Code Generator
- •Fleshing Out the Morse Code Generator’s Interface
- •Outputting Morse Code Symbols
- •Installing and Using the Telegraph Class
- •Publishing Your Own Library
- •What If It Doesn’t Work?
- •Exercises
- •5. Sensing the World Around Us
- •What You Need
- •Measuring Distances with an Ultrasonic Sensor
- •Increasing Precision Using Floating-Point Numbers
- •Increasing Precision Using a Temperature Sensor
- •Creating Your Own Dashboard
- •What If It Doesn’t Work?
- •Exercises
- •What You Need
- •Wiring Up the Accelerometer
- •Bringing Your Accelerometer to Life
- •Finding and Polishing Edge Values
- •Building Your Own Game Controller
- •More Projects
- •What If It Doesn’t Work?
- •Exercises
- •7. Writing a Game for the Motion-Sensing Game Controller
- •Writing a GameController Class
- •Creating the Game
- •What If It Doesn’t Work?
- •Exercises
- •8. Generating Video Signals with an Arduino
- •What You Need
- •How Analog Video Works
- •Building a Digital-to-Analog Converter (DAC)
- •Connecting the Arduino to Your TV Set
- •Using the TVout Library
- •Building a TV Thermometer
- •Working with Graphics in TVout
- •What If It Doesn’t Work?
- •Exercises
- •9. Tinkering with the Wii Nunchuk
- •What You Need
- •Wiring a Wii Nunchuk
- •Talking to a Nunchuk
- •Building a Nunchuk Class
- •Using Our Nunchuk Class
- •Creating Your Own Video Game Console
- •Creating Your Own Video Game
- •What If It Doesn’t Work?
- •Exercises
- •10. Networking with Arduino
- •What You Need
- •Using Your PC to Transfer Sensor Data to the Internet
- •Registering an Application with Twitter
- •Tweeting Messages with Processing
- •Communicating Over Networks Using an Ethernet Shield
- •Using DHCP and DNS
- •What If It Doesn’t Work?
- •Exercises
- •11. Creating a Burglar Alarm with Email Notification
- •What You Need
- •Emailing from the Command Line
- •Emailing Directly from an Arduino
- •Detecting Motion Using a Passive Infrared Sensor
- •Bringing It All Together
- •What If It Doesn’t Work?
- •Exercises
- •What You Need
- •Understanding Infrared Remote Controls
- •Grabbing Remote Control Codes
- •Cloning a Remote
- •Controlling Infrared Devices Remotely with Your Browser
- •Building an Infrared Proxy
- •What If It Doesn’t Work?
- •Exercises
- •13. Controlling Motors with Arduino
- •What You Need
- •Introducing Motors
- •First Steps with a Servo Motor
- •Building a Blaminatr
- •What If It Doesn’t Work?
- •Exercises
- •Current, Voltage, and Resistance
- •Electrical Circuits
- •Learning How to Use a Wire Cutter
- •Learning How to Solder
- •Learning How to Desolder
- •The Arduino Programming Language
- •Bit Operations
- •Learning More About Serial Communication
- •Serial Communication Using Various Languages
- •What Are Google Chrome Apps?
- •Creating a Minimal Chrome App
- •Starting the Chrome App
- •Exploring the Chrome Serial API
- •Writing a SerialDevice Class
- •Index
CHAPTER 8
Generating Video Signals with an Arduino
So far we’ve used several different technologies to communicate with the outside world. We’ve used LEDs to represent our binary die’s results, for example, and we’ve used the serial port to send more elaborate messages. We’ve also turned data received on the serial port into shiny applications running in our browser.
For many projects this way of displaying information is sufficient, but in some cases you want a real display. You could use an LCD display, for example, and you’ll find multicolor TFT touch displays you can attach to the Arduino, too. Another option is surprisingly cheap: you can connect the Arduino to your TV set and display information right on the screen.
In this chapter, not only will you learn how analog TV works in principle, you’ll also learn how to generate a stable monochrome video signal using your Arduino. At the end of the chapter, you’ll have a graphical thermometer that will run on the TV set in your living room.
report erratum • discuss
Chapter 8. Generating Video Signals with an Arduino • 128
What You Need
1.An RCA cable
2.A 470Ω resistor
3.A 1kΩ resistor
4.Some wires
5.A TMP36 temperature sensor from Analog Devices
6.An Arduino board, such as the Uno, Duemilanove, or Diecimila
7.A USB cable to connect the Arduino to your computer
How Analog Video Works
Before you create your own video signals, it helps to understand how analog TV systems work in general. If you’re impatient, you can skip the theory and jump straight to Connecting the Arduino to Your TV Set, on page 131.
First of all, you should note that analog video is completely different from digital video in most regards. In this chapter, we’ll only talk about analog video signals that you can feed to your TV set’s composite input.
You might remember the good old days when TV sets were huge, heavy boxes with ridiculously tiny screens. These boxes had to be so big because they contained a small electron cannon that produced images by firing electrons to the screen. The cannon drew an image line by line—that is, it started at the top-left corner of the screen and drew the first line of the image. At the end of the line, it moved back to the left side and drew the second line. This technique is called raster scan. Figure 23, How raster scan works, on page 129 shows how it worked.
After the last line was drawn, the electron beam moved back to the top and drew the next image. Depending on the TV standard, this process happened
report erratum • discuss
How Analog Video Works • 129
Figure 23—How raster scan works
(Image created by Ian Harvey)
50 to 60 times per second, and it was fast enough to create the illusion of motion. (Actually, most TV sets needed two passes to draw a single image using a mechanism called interlacing, but for our purposes that’s irrelevant.)
Moving the electron beam across the screen isn’t sufficient. You have to somehow encode the information you’d like to draw. Therefore, you have to change the electron beam’s intensity while it traverses the screen. Due to a chemical reaction, the TV screen will glow in different colors when the electron cannon hits it with different intensities. For a monochrome signal, you need to generate the voltages explained in the following table.
Voltage: 0.0V 0.3V 0.6V 1.0V
Color: SYNC Black Gray White
A voltage of 0V represents the SYNC signal. It tells the TV set that a new line of the image begins. All the other voltages represent different colors. To draw a white dot, you have to set the voltage to 1V.
All we have to do is create a couple of different voltage levels. That doesn’t sound too difficult, but unfortunately, the Arduino has only analog input pins. It cannot emit analog output signals. At least not directly, but in the next section you’ll learn how to do it.
report erratum • discuss
Chapter 8. Generating Video Signals with an Arduino • 130
Building a Digital-to-Analog Converter (DAC)
The Arduino doesn’t natively support analog output signals, so we need to find a way around this limitation. The solution is a digital-to-analog converter (DAC).1 As the name suggests, such a circuit turns a digital input into an analog output. You can find DACs in a lot of consumer devices—for example, in your MP3 player. It turns your digitally encoded music into an analog sound wave.
One of the most important characteristics of a DAC is its resolution. In our case we need to generate four different voltage levels to create a video signal. To encode four voltage levels, we need two bits—that is, our DAC has a 2-bit resolution. The following table shows how we could map the four binary input values to their voltage levels.
Binary input: |
00 |
01 |
10 |
11 |
Output voltage: 0.0V 0.3V 0.6V 1.0V
We can use two of the Arduino’s digital pins to control the DAC’s input value, but we still have to find a way to generate different voltages depending on the pins’ values.
There are several ways to achieve this, but one of the easiest is by using a binary-weighted DAC. It has the following characteristics:
•You need a resistor for every input bit.
•All resistors have to be in parallel.
•Resistor value for bit #0 is R. For bit #1 it’s 2R, for bit #3 it’s 4R, and so on.
Let’s say we use the Arduino’s digital pins D7 and D9 to control the DAC’s input value. In the following figure, you can see our DAC’s circuit. You have to add the 470Ω and 1kΩ resistors yourself, but you get the 75Ω resistor for free, because it’s part of your TV set’s input connector.
In principle, the binary-weighted DAC is a voltage divider2—that is, it turns an input voltage into a smaller voltage. The output voltage depends on the
1.http://en.wikipedia.org/wiki/Digital-to-analog_converter
2.http://en.wikipedia.org/wiki/Voltage_divider
report erratum • discuss