Top

AVR, Raspberry Pi, VW Beta: VAG CDC Faker

AVR, Raspberry Pi, VW Beta: VAG CDC Faker

(5 votes, average: 5.00 out of 5)
Loading...

I was tired connecting my cellphone with an old cassette adapter to my VW Golf with an Beta 5 in it. I needed something new, something cool. And here it is, a fully functional interface between the Beta 5 and any device you want to play the music with.

This project raised out of an ebay search: I just wanted to know if there is a solution to get an AUX input on the car radio. Yes there is, even complete mp3 players are available. But that’s not what I wanted – at first!

Then I started digging the web for more info about the protocol the radio talks to cd changers.
The idea was to build a tiny thingy that fakes a cd changer and simply enables the AUX input (as it is available in several online stores). But during the development my ambition became greater and I wanted to read the keys pressed on the radio to remote control my RPi.

1. Understanding the Protocol

First of all this is the pinout of the radio: rkieslinger.de/steckerbelegungen/vag-stecker.htm
The interesting cell is no. 3, the blue one.
DATA IN simply is MOSI of an 8bit SPI interface with special timings between the bytes
CLOCK is SCK of the SPI
DATA OUT is the key code of the pressed key on the radio itself

The radio needs a sequence of bytes to enable the AUX input and display CD# and TR#. It looks likes this:

frame cd#   tr#   time  time  mode  frame frame
0x34, 0xBE, 0xFF, 0xFF, 0xFF, 0xFF, 0xCF, 0x3C

cd# and tr# are sent inverted. So this sequence will display: CD1 TR00
mode sets the playmode (PLAY|SHFFL|SCAN)
As the beta doesn’t support time display, I will ignore these bytes.

If cd mode is switched on/off or keys are pressed, 4 byte messages will be sent from the radio. They are coded like RC5 messages.
Each message has a startsequence. A low byte has a short low phase, a high byte a longer low phase. Everything you need to know can be found in the pictures here: martinsuniverse.de/projekte/cdc_protokoll/cdc_protokoll.html

2. Remote commands from the radio

As you know 4 byte messages are sent. The following pattern describes the control codes:

head head cmd  !cmd
0x53 0x2C 0xAA 0x55

Here is the complete list of all bytes from all keys:

switch on in cd mode/radio to cd (play)
0x53 0x2C 0xE4 0x1B
0x53 0x2C 0x14 0xEB

switch off in cd mode/cd to radio (pause)
0x53 0x2C 0x10 0xEF
0x53 0x2C 0x14 0xEB

next
0x53 0x2C 0xF8 0x7

prev
0x53 0x2C 0x78 0x87

seek next
0x53 0x2C 0xD8 0x27 hold down
0x53 0x2C 0xE4 0x1B release
0x53 0x2C 0x14 0xEB

seek prev
0x53 0x2C 0x58 0xA7 hold down
0x53 0x2C 0xE4 0x1B release
0x53 0x2C 0x14 0xEB

cd 1
0x53 0x2C 0x0C 0xF3
0x53 0x2C 0x14 0xEB
0x53 0x2C 0x38 0xC7
send new cd no. to confirm change, else:
0x53 0x2C 0xE4 0x1B beep, no cd (same as play)
0x53 0x2C 0x14 0xEB

cd 2
0x53 0x2C 0x8C 0x73
0x53 0x2C 0x14 0xEB
0x53 0x2C 0x38 0xC7
send new cd no. to confirm change, else:
0x53 0x2C 0xE4 0x1B beep, no cd (same as play)
0x53 0x2C 0x14 0xEB

cd 3
0x53 0x2C 0x4C 0xB3
0x53 0x2C 0x14 0xEB
0x53 0x2C 0x38 0xC7
send new cd no. to confirm change, else:
0x53 0x2C 0xE4 0x1B beep, no cd (same as play)
0x53 0x2C 0x14 0xEB

cd 4
0x53 0x2C 0xCC 0x33
0x53 0x2C 0x14 0xEB
0x53 0x2C 0x38 0xC7
send new cd no. to confirm change, else:
0x53 0x2C 0xE4 0x1B beep, no cd (same as play)
0x53 0x2C 0x14 0xEB

cd 5
0x53 0x2C 0x2C 0xD3
0x53 0x2C 0x14 0xEB
0x53 0x2C 0x38 0xC7
send new cd no. to confirm change, else:
0x53 0x2C 0xE4 0x1B beep, no cd (same as play)
0x53 0x2C 0x14 0xEB

cd 6
0x53 0x2C 0xAC 0x53
0x53 0x2C 0x14 0xEB
0x53 0x2C 0x38 0xC7
send new cd no. to confirm change, else:
0x53 0x2C 0xE4 0x1B beep, no cd (same as play)
0x53 0x2C 0x14 0xEB

scan (in 'play', 'shffl' or 'scan' mode)
0x53 0x2C 0xA0 0x5F

shuffle in 'play' mode
0x53 0x2C 0x60 0x9F

shuffle in 'shffl' mode
0x53 0x2C 0x08 0xF7
0x53 0x2C 0x14 0xEB

The micro controller will only send the 3rd byte after error check over uart. See below.

3. The Hardware I picked

  • Atmel ATmega32A
  • 1117 Regulator (maybe not the best, it’s heating up at >50mA due to the high drop voltage)
  • FTDI FT230X as uart usb bridge
  • ISO connector to fit into the radio

4. Programming the AVR

First thing about the uart communication. I use the library of Peter Fleury: jump.to/fleury
To be independent from clockrates I utilized delay loops instead of timers to create correct timings. Hopefully my comments in the code explains everything very well.

Additional info can be found here: www.mikrocontroller.net/topic/28549 (in German)

5. The Circuit

Nothing special here, just an ISP header for programming the AVR, USB connector, voltage regulator, LED,…
For feature circuits in the glovebox I provided 12V, 5V and GND through further pins. I was thinking of powering the RPi directly from my faker. But I don’t know if the radio is able to provide around 400mAmps. Even the regulator would heat up like hell at these currents.
vag_cdc_eagle
The FT230X is programmed as selfpowered and CBUS1 as output for the #POWER_ON singnal.

6. Bringing all together: MPD and RPi

Now we need a wrapper for mpc to let mpd act as our cd changer. I’ve written a python script to evaluate the radio commands and send cd and track numbers back periodically. The script starts at startup by the rc.local and checks for the connected faker.
The last listened cd no. will be stored in a file to send it to the faker if something is restarted or reconnected. I let the script stop mpd to save power and make sure the current settings are synced with the filesystem, because a powerfail will cause a corrupted playlist.
The music is stored in /var/vag_cdc/cdX where X is the cd no. 1 to 6. You can put up to 99 tracks in each folder due to radio display limitations.

7. Some further ideas

The project is mostly complete – for now. But there are some things I have in mind that could be quite nice to have. It would be awesome if it had bluetooth to remote control my android phone. Or mute the radio at incoming calls and act as a hands free set.
But what I’ve done lately is preparing the RPi with Wifi, so it connects automatically to my Wifi, when parking in the garage to sync the music folders with rsync.