Testing The Living Headlights app in a car

While choosing the hardware for our setup in a car, we must consider two questions:

A Raspberry Pi draws power via its micro USB port. It needs a 5V, 700mA power source. We can satisfy this power requirement by plugging a USB adapter into the car's cigarette lighter receptacle and then connecting it to the Raspberry Pi via a USB to micro USB cable, as seen in the following image:

Testing The Living Headlights app in a car

Standard USB peripherals, such as a webcam, mouse, and keyboard, can draw enough power from Raspberry Pi's USB ports. Although Raspberry Pi only has two USB ports, we can use a USB splitter to power a webcam, mouse, and keyboard simultaneously. Alternatively, some keyboards have a built-in touchpad that we can use as a mouse. Another option is to simply make do with only using two peripherals at a time and swapping one of them for the third peripheral as needed. In any case, once the app is started and calibrated (and once we are driving!), we do not want to use the keyboard or mouse input anymore.

The webcam should sit against the inside of the car's rear window. The webcam's lens should be as close to the window as possible to reduce the visibility of grime, moisture, and reflections (for example, the reflection of the webcam's "on" light). If the Raspberry Pi lies just behind the car's front seats, the webcam cable should be able to reach the back window while the power cable should still reach the USB adapter in the cigarette lighter receptacle. If not, use a longer USB to micro USB cable for the power and, if necessary, position the Pi farther back in the car. Alternatively, use a webcam with a longer cable. The following image shows the suggested positioning of the Pi:

Testing The Living Headlights app in a car

Similarly, the next image shows the suggested positioning of the camera:

Testing The Living Headlights app in a car

Now we have come to the hard part: the display. For video output, Raspberry Pi supports HDMI (as found in new TVs and many new monitors) and composite RCA (as found in old TVs). For other common connectors, we can use an adapter, such as HDMI to DVI or HDMI to VGA. Raspberry Pi also has limited support (via third-party kernel extensions) for video output via DSI or SPI (as found in cellphone displays and prototyping kits).

A small display is desirable because it can be more conveniently mounted on the dashboard and it consumes less power. A few displays might be able to draw enough power from the cigarette lighter receptacle via a 5V or 12V adapter. For example, HDMIPi (a 9 inch, 1280 x 800 display, in beta at the time of writing this book) will work with a 12V, 1A power source or perhaps even a power source with lesser specifications, according to beta testers' reports. HDMIPi also promises to include a 5V outlet, making it possible for Raspberry Pi to draw power from the display. For more information, refer to the HDMIPi product site (http://hdmipi.com/) and Kickstarter page (https://www.kickstarter.com/projects/697708033/hdmipi-affordable-9-high-def-screen-for-the-raspbe).

Typically, though, a display needs a much higher voltage and wattage than the cigarette lighter receptacle can supply. Conveniently, some cars have an electrical outlet that resembles a wall socket, with the standard voltage for the type of socket but a lower maximum wattage. My car has a 110V, 150W outlet for two-pronged North American plugs (NEMA 1-15P). As seen in the following image, I use an extension cord to convert the two-pronged connection to a three-pronged connection (NEMA 5-15P) that my monitor cables use:

Testing The Living Headlights app in a car

I tried plugging in three different monitors (one at a time, of course), with the following results:

The XP22WD's ports are seen in the following image. To connect from Raspberry Pi, I am using an HDMI to DVI cable because the monitor does not have an HDMI port:

Testing The Living Headlights app in a car

I admit that all my monitors are too big to mount on a dashboard! However, for testing the system in my driveway, I am content to have a monitor that sits on the front passenger seat, as seen in the following image:

Testing The Living Headlights app in a car

VoilĂ ! A car can power Raspberry Pi, peripherals, and a desktop monitor! As soon as the car is turned on, our system boots and then it runs exactly as we would expect of a Linux desktop. We can launch The Living Headlights app from the command line or from an IDE such as Geany. Our app's behavior on Raspberry Pi should be identical to its behavior on a conventional desktop system, except that on Pi we will experience a lower frame rate and greater lag.

Now that the app is running in a car, do not forget to recalibrate it so that it estimates distances based on the size of real headlights and not the size of our flashlight rig!