Monday, November 5, 2012

Power: design and testing

I want the car computer to turn on and off with the key but I don't want to corrupt the sdcard by just pulling the rug out from under it. So soft shutdown, a bypass power switch and as it turns out I'm going to need a timed power up to help with the HDMI connection.
Here is the free hand wiring digram of the circuit I'm going to use.

Oh yeah, giving xkcd a run for his stick figure money. Honestly, I love xkcd.

So this might not be the best way to do what I want to do but here is my resoning for each part. (and by part I mean the 5 freaking relays)

The Main Relay is taking the key power to switch a relay and power the screen, the Timer Relay and the Detection Relay. This means the key only has to power that relay coil and it never has the chance of meeting up with the battery power. It is rare but a car can sometimes have a difference of voltage or sometimes impedance between those two power sources. I don't want to have to replace seemingly random parts at seemingly random intervals.

The Timer Relay is there because I've found that the HDMI connection does not start up correctly if the monitor isn't turned on a second or so be for the computer is powered. I bought this one for a illegal mod to a in dash DVD player that wouldn't show video without a ground meant for the E-brake. Well, that DVD player is gone so I might as well use the relay for an even more illegal distraction for my driving.

The Detection Relay isolates the car's 12v from the GPIO's 3.3v input. I'm using an external pull-up resistor just to be sure if I mess up the programing I won't hurt the board.

The last two relays are on a computer controlled relay board (this is the one I bought, I hope it works). One of the relays will keep the power on while the key is off and computer has not finish turning off. The other was an additional dollar so I'll figure something to do with it at some point. maybe I'll come across a cool 12v light I just can't live without, I don't know.

There are a few other odds and ends. I've already mentioned the pull-up resistor but you may have noticed a diode on the timer circuit. This is so the power running through the computer controlled relays don't keep the screen powered on and more importantly they don't keep the detection relay closed.

Then there is a Bypass switch I plan on mounting in the glove box with the radio (I'm using something just like this). It will let me keep the computer on if I want to go inside my loft and update stuff over the wifi connection. This will let me add music and update software. I placed it in the circuit where I did so it would keep the detection relay on. I would like the screen to still turn off but the switch I have is not dpdt and I'm not adding another relay.

So I have a script that I tested with some jumper wire and an LED instead of the relay. I am not a programmer. I'm hardly a script kitty. So I got some help from a friend who is a programmer. Many props to Martin! He helped me sort out a few things that I did horribly wrong. Here is what I'm using.

#! /bin/bash
#This part turns on the relay to hold power on during shutdown
echo "17" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio17/direction
echo "1" > /sys/class/gpio/gpio17/value

#this sets up the input pin for the shutdown signal
echo "22" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio22/direction

#this part look at the power signal relay for shutdown
while [ true ]; do
sleep 1s
CONTENTS=`cat /sys/class/gpio/gpio22/value`
if [ "$CONTENTS" = "1" ]; then
shutdown -h 0


This is in a file I have named So far I have only started it manually. I plan on using rc.local to start it on boot up. This was all done with Raspbian. The dependacys and hooks will have to be figured out for the Raspbmc and I plan on doing that as part of the figuring out the touch screen in stuff on Raspbmc.

I plan on updating this tomorrow night with a link to something for Martin and after my wife weeds out all my stupid in the writing.

Sunday, November 4, 2012

Lillput Touchscreen Calibration

So the Lilliput touch screen I got from's Amazon store has great resolution and dot pitch. It is as good as the CRT monitor I had in high school and about the same resolution! Unfortunately the touch part didn't work out of the box. I was running Raspbmc and after playing with it for a few minutes I found a problem - if I touched one little area in the corner it would move the cursor randomly.

After much Internet hunting and many posts saying things like "why wouldn't you just buy a cheap Chinese touchscreen that fits" I figured it out. The drivers were getting some input just not the right one. If this was a Windows machine, it would mean that the wrong drivers were installed. Of course this is Linux so everything is going through Xserver. Luckily I found a calibration program for touch screens that works on the Xserver side and should work on any touch screen that uses Xserver.

First I had to take care of some prerequisites. So I booted Raspbian (easier to work with than Raspbmc) and downloaded the calibrator program (I believe this was made by Tias Guns but couldn't find a definite link).

Next I made sure everything I needed was installed.

sudo apt-get update
sudo apt-get install libx11-dev
sudo apt-get install libxext-dev 

sudo apt-get install x11proto-input-dev 

When I tried to install libxi-dev, it didn't work... Then I noticed it was installed with one of the other packages.

Next I unpacked and installed the calibration program.

tar xvzf (file, in this case "xinput_calibrator-0.7.5.tar.gz)
cd xinput_calibrator-0.7.5
sudo make install

Then I launched it >Preferences/Calibration and it ran. Each time it was happy with my touches it spat out the newly set calibration settings (It took three run-throughs for me).

Note: It replaces the setting each time this way.

Next I needed it to apply these settings each time it booted. The program kindly tells you where to drop the settings... only it was wrong. I ended up changing the file /usr/[lib/share]/X11/xorg.conf.d/99-calibration.conf to the settings spit out at the end of the program. Except there's a catch. The setting changes for flipping the axis are not reset every time you calibrate. So if it was changed and you don't have that in the conf file when you reboot, it will not be there. I had to calibrate and change the file, then reboot and check it a few times. I ended up with this:

Section "InputClass"
        Identifier     "calibration"
        MatchProduct   "eGalax Inc. USB TouchController"
        Option "Calibration"   "4000 140 435 3600"
        Option "SwapAxes"      "1"

It's not perfect. I think the right side could be better, but it works!

My next goal is to get Raspbmc to play nice.

Tuesday, October 23, 2012

Car Computer - Modification in Stereo

When our stereo was stolen, the thief also took the cage for holding the stereo leaving a hole in our dash. There was just the back brace and front bezel (sigh).

Luckily my sister left a stereo in my parents' garage after upgrading her car.

It's a nice little unit.

I plan on mounting the radio in the glove box a long with a power override switch and a USB connection for the computer. This means the wires for the radio have to be extended. My sister left the radio's main connector on the back of the unit. In order to connect it to my car, I bought a Mazda connector and 25 ft of 18 gauge black speaker wire (also called rip cord because you can rip the two wires apart).

Now, I'm a crazy person. I like soldering, so I decided to solder all the connections. That's 13 wires and 26 solder points. I also heat shrink wrapped each of them using a lighter.  I've heard people complain about this, but keep in mind I just soldered 13 wires.

When my bagillion connections were made, I needed to keep the wires together. A few zip ties will do the trick for now because I have to take the radio power wires apart for the computer power later. There are way too many wires to let them be all willy nilly.

Once I had the harness completed, I needed to focus on the radio. The only major issue with it is the rear auxiliary input is Sony's proprietary BUS AUX IN. This only turns on when the head unit gets the correct signal from another Sony product through the BUS control connection. I wasn't about to shell out $100 for Sony's BUSlink adapter, which meant I either had to plug into the front of the head unit or make my own adaptations. I chose to adapt. This way I could remove the faceplate or use the front auxiliary input.

So I opened the head unit and took apart the faceplate. This was useless.

I lost a spring. I spent 15 minutes looking on the carpet (which is the exact goddamned gray as the spring). Incidentally, I have some great tricks for finding things in such situations (like taking off your shoes and walking around, a.k.a. finding by feel).

Next I took out the CD mechanism and pulled the main board. The amplifier MOSFETs use the rear metal chunk as a heat sink, so watch out for thermal paste. Looking at the bottom of the main board I found Sony was kind enough to label all their pins (Hooray Sony!).

In the picture to the left you can see pins labeled Aux G, Aux L, and Aux R. These pins attach to the cable for the front faceplate.

The pins going to the BUS AUX input at the rear of the stereo are fairly obvious. LCH is the left channel. RCH is the right channel. Ground is the big blob in the center.

NOTE: If you don't know what you're looking at in the picture on the right, then you shouldn't try to solder to it... unless you're making abstract art or unique paperweights.

Trusting in Sony engineering, I soldered in some jumper wires and prayed it wouldn't fry something. I reassembled the radio and ran out to the car to plug it in. With my cellphone for sound I tested it and voilĂ ! It worked!

Monday, October 22, 2012

Car Computer - Overview

So our car got broken into not long after we moved back to the Bay. Yet again our stereo was stolen.

It sucked.


But this afforded me the opportunity to build my dream stereo - a dream I've had since I was but a tender high school junior - a car computer.

The time was ripe. Finally the price of components was reasonable. Plus I'd built up the skills necessary to actually complete the damn thing. In the interest in sharing information (FOSS!), I'm chronicling my project on this blog.

The car computer will be able to do the following things:
  • GPS navigation
  • Play music from hard drive/USB, Pandora, and CDs
  • Connect to devices through Bluetooth (i.e. phone)
  • Connect to home network for updates/sync
  • Read OBD II codes
I started with a stereo head unit that was originally in my sister's car.  It's a CDX-GT520 which has pretty good sound and can play MP3s, AACs, and regular CDs. Of course this was the only freebie I got. Everything else I needed to purchase.

The biggest purchase was a screen. After some research I decided on a Lilliput Touchscreen for the high definition picture and USB touch interface. Though it will yield many rewards, it's been a giant pain in my ass and will continue to be so. This is because of software and mounting issues (which I'll discuss in detail in my upcoming screen posts).

My next acquisition was a Raspberry Pi. I bought an RPI Model B Rev 1. It has HDMI, USB, network and GPIO pins. This particular model revision is no longer available for purchase, however you'd be able to use the newer models the same way in this project.

So far I purchased the following additional components:
  • 7 port 12 volt USB hub
  • HDMI cable
  • USB to micro USB cable
  • 2 12 volt relays
  • Mazda stereo connector
  • 25 ft 18 gauge black speaker wire
  • 3 ft USB extension
  • Automotive switch
  • 160 GB USB external hard drive
  • USB wireless network adaptor with external antennae
I know I'll purchase additional pieces, however because I'm still in the middle of my build I'm not certain what those components will be.

If I don't get this thing to work, my wife said I'll have to sleep with one eye open because of all the stuff I've purchased. So pray for me and wish me luck.