Saturday, October 4, 2008

Zune Project: Part 2

Last time I went over how I mounted the zune in my car. This post I'll finish up with how I connected it to my steering wheel controls.

The first thing I did was find the signal from the steering wheel button in my pathfinder. To do this I just pulled out my stereo far enough so that I could reach the wiring while it was still all plugged in. Using an alligator clip, I connected one probe of my voltmeter to the case of the stereo, which is ground. Then I checked each wire going to the back of my stereo with the other probe, and pushed the button on my steering wheel. It didn't take long before I found a wire that would jump from 0 to 5 volts when I pushed the button. This was convenient because the PIC microcontroller I was using also runs on 0 to 5V, so I could plug the steering wheel button in to the PIC without any issues.

Next I spliced a wire in to the steering wheel button wire, and also two more wires to 0V and 12V from the cigarette lighter. I ran my own wires underneath the plastic of my center console, so that it came out at the ashtray. 

With my car ready, I started on the completely different problem of storing the signals from the remote control of the zune dock, so that I could program them on to a microcontroller.

First I took the remote for the dock apart...

...and soldered a wire to the negative side of the remote's IR LED.

So each time the remote's IR LED would light up, the signal on the wire soldered to it would be pulled down to ground. By adding a 10K "pull up" resistor between that wire and the 5V supply on the PIC, the signal will be 5V when the remotes IR LED is OFF, and 0V when it is ON.

I made a circuit on a breadboard, shown in the picture below (missing the microcontroller and IR LED) . What is also not shown is that I powered the remote control with a 3V supply and hooked the ground of the 3V supply to the ground of the PIC's 5V supply. Then I connected the wire soldered to the remote to pin RD0 of the PIC.

Here is a schematic that of the circuit:
There are two ICs in the circuit. One is the PIC microcontroller, which does almost everything. The other is a MAX232 chip which converts TTL level (5V) signals to RS232 levels (12V) so that you can talk between a computer's serial port and a TTL level UART (universal asynchronous receiver/transmitter) device, such as the PIC. 

I programmed the PIC so that as soon as the IR LED on the remote starts flashing, the PIC would save the state of that pin at regular time intervals. After a certain number of samples it will stop recording, and it will "play back" the data stream as a series of ASCII 1's and 0's through the UART of the PIC. I connected a serial cable between the output of the MAX232 chip and my laptop. Then I opened up a session of HyperTerminal (every PC has this), set up the com port to the same settings as the PIC, and saved incoming the string of 1's and 0's as a text file. Then using Excel, I plotted the signal.

When I finally got the code debugged, I did a little experimenting and found out that the zune remote's LED flashes on and off at a base line frequency of 37kHz (37,000 times per second). Below is an Excel plot of a "forward skip" signal, from the remote's LED.

Zooming in on that same signal (below), you can see that the baseline frequency of 37kHz is in the "background" of a much slower signal. 

I chose the sample rate of the PIC to be 8x faster than the remote - 37kHz*8=296 kHz. This was fast enough to capture the transitions, and slow enough so that 1) the PIC could keep up with the signal and 2) I wouldn't run out of memory. With this sample rate I needed 12000 samples to describe the whole signal, which took up 1500 bytes of memory (1200 samples / 8 samples per byte). The PIC I was using had 2048 bytes of variable memory in total.

Once the sample rate and number of samples were locked down, I captured and saved the "play/pause" and the "forward skip" signals in Excel. With a few excel tricks, I generated two vectors, one for each of the two signals, each 1500 elements long, and saved them each in their own file. 

I then changed the PIC program so that it would turn on and off an IR LED of its own, at the same frequency as the remote. If the button was pushed for less than half a second, it would skip tracks. Otherwise it would pause/play. I left most of the original code in case I wanted to record more signals later on - I would just have to "un-comment" a few lines to bring it back to its original functionality. Download the pic code here.

With the new code tested, it was finally time to get the thing in to my car. I soldered together a simpler, more compact version of the breadboard circuit that didn't have the MAX232 chip. It is powered from the cigarrete lighter's 12V supply. 

Top view...


bottom view...

The circuit tucks in nicely into the ashtray.

With the ashtray closed, the IR LED is the only thing that pokes out. The finished product is below:

And that's it! Now my steering wheel button skips tracks and can play/pause my zune. It was probably more trouble than it was worth, but I had fun doing it. I left out quite a lot of details, but I can add them if there is a lot of interest in this project. 

Tuesday, September 23, 2008

Zune Project: Part 1

Over a year ago the in-dash 6 cd changer started having problems in my 2001 Nissan Pathfinder. Cds would get stuck, couldn't be read, until finally "ERR2" stayed on the screen and wouldn't go away. I went to some forums and learned that it was a common but expensive problem. I decided I didn't like CDs anyway and I wanted to rely on my Zune (microsoft's mp3 player) for my music. 

I had tried using one of those radio transmitters before without much luck (I've since soldered a wire to the the antenna to increase it's range, see instructions here), and the tape player on the head unit was screwed up so I couldn't use one of those tape things.

Luckily, the head unit has an auxiliary input in the back. I bought the harness for $49 at ActiveTuning (link), tore out my cd player, installed a little in-dash shelf ($20 at best buy), and hooked up the harness. The harness comes with a switch to go back and forth between Aux and regular modes, and I just popped out one of the square hole covers to put the switch and audio cord through. The pics of that setup are below:

It sounded great, and I liked almost everything about my big switch from cds to digital - except one tiny detail. I had gotten used to skipping tracks, and play/pause functions on the Nissan steering wheel. These worked with the cd player but obviously not with the zune. Conveniently, there was one steering wheel button for skipping tracks that did nothing while the stereo was in AUX mode, so I decided to find a way to at LEAST skip tracks but hopefully also to play/pause the zune using the one available button (two of the remaining buttons were +/- volume, which did work with the zune).

I started by looking in to the pinout of the zune to see if I could work out something that could directly control the zune through the connector. I found out that 1) there are a lot of freakin pins (24 of them) that are really close together and 2) people hadn't figured out what half of them are for (link). I wasn't about to try and tackle that can of worms.

The solution I finally came up with was to mount a zune dock somewhere in my car, and program my own customized remote control that would be triggered by the buttons on my steering wheel. Luckily, after Apple came out with the iPod Touch all the zune stuff was dirt cheap. The docks were down to $10 from $40, and the remote controls that went with the docks were only $8. I bought two docks, 1 remote, and got to work. 

The first step was mounting the dock in my car. I eventually settled on mounting it to the ash tray, since it had a nice area to stash whatever electronics would be needed. To mount it, I popped the cover off with a small screwdriver and took out two of the screws that hold down an internal weight. I drilled through with a 1/8"  drill bit, all the way through the other side, so that I could put long screws through. The red arrows in the picture below show where I drilled through:

I drilled the same two holes in my ash tray so that I could put long 4-40 screws through, and fastened it down with nuts. Ignore the LED in the pic below (that came later):

The complete setup is shown below:

At this point, nothing was really any different from before the dock, but it did give me a place to put the Zune while I was listening to music. I was able to plug the 1/8" plug into the back of the dock, and the dock plugs in to the cigarette lighter. Overall it was an improvement from just sticking the zune in to the shelf.

Next post I will show how I got the steering wheel interface to work.

Monday, September 15, 2008

Hello world

Well I've been meaning to make some kind of website about my projects for quite some time now... my last attempt did not get much further than a nice template. You can see it here. It's been about a year since I did anything with it.

I have a problem with finishing things... once I learn enough to do it, a lot of the challenge is gone and I lose interest. That is why I stopped working on that website (it took a few hours) but it is also why I started this one.

This blog is all about documenting the few projects that I have actually spent the time to finish without losing interest. I hope that it serves two purposes. First, it provides a place for me to share my projects with others. Second and more importantly, I'm hoping that it will help me follow through with other projects that I might not otherwise.

To start this thing off, let me just list off some of the projects I might write about that I've finished over the past few years.
  • Control Zune mp3 player with steering wheel button using a dsPIC (just finished, September '08)
  • Folding basket opener/closer made from acrylic (finished March '08)
  • Automated solver for minesweeper-like game using AutoHotKey and Matlab (finished April '08)
  • Automated game playing program for a fun little web game called cyrkam airtos (finished October '07)
  • One legged balancing robot, master's thesis at UCSD (finished June '07)
Timeout, I really don't want to write anything else about my thesis. I already spent countless hours building and controlling the thing, and wrote 140 pages on it. A link to my thesis is here, and a youtube video is here:

Moving on...
  • Puzzle solver for an obscure online game using Matlab (finished around Jan '07)
  • Magnet hovering apparatus (finished in late '06 I think...)
  • "Worms" simulation using VBA in Excel (finished summer of '06)
  • Puzzle solver for a sudoku-looking-but-far-from-sudoku game called Picross, using VBA in Excel (finished sometime in '05 I think)
Well I've probably gone back far enough with this list. Of course there is more, but my memory is bad and I'll probably only elaborate on half of the list as it is.

Let me finish this off by saying that this blog is not about me, it is about my projects. Although I'm sure that writing about the things that interest me will inevitably paint some kind of picture about me, I'll try not to fill in the blanks myself.