CarPi - Raspberry Pi with VW RNS2 DVD (MFD2)

It started with three beeps of my car, when I started the engine. They told my that I have to stop the engine immediately and should call a service station. The Volkswagen service station that I used at that time told me, that it is a well know problem. The battery has to be replaced and the ground connections of the engine have to be cleaned.
Unfortunately the problem did not disappear after the work was done. At that time the Volkswagen service station told me that the last option is a replacement of the complete dashboard. It's price will be around 1000,- €. Because it can't be sent back, I have to pay for it anyway. But it could be, that the problem will not be solved.
Round about that time the idea arose to scan the CAN bus with a Raspberry Pi to analyse what's going on.
For a better understanding I devide the project in several pieces:
  1. The MFD2 as a display for the Raspberry Pi
  2. Connecting the car
  3. Mounting the Pi

The MFD2 as a display for the Raspberry Pi

Obviously the Raspberry Pi should have a display. Using the MFD2 would be cool. At the rear side of the MFD2, there was an appropriate connector so it should be no problem. Ok, beside the fact that there was a composit sync input only. But a RGB input offering audio input too is a start.
More difficult was the task to create the right VGA signals. To save money, my first try was the Gert VGA 666 adapter. (https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=94424)
It took some time to realize that the Gert VGA 666 adapter is using an LCD output, which supports progressiv only. But the MFD2 supports interlaced only. This will never match!
For the second try I used an HDMI VGA adaptor by manhattan. (http://manhattan-products.com/hdmi-to-vga-converter3) which I bought at a local store K&M COMPUTER. There was no audio ouput and the power supply by the HDMI plug of the Raspberry Pi was sufficient to run the adaptor. In general I was able to create an interlaced VGA signal. A first timing I found here: (http://www.mp3car.com/forum/general/show-off-your-project/158651-oem-mfd2-vw-and-a-pc-my-next-ivi-to-replace-my-nexus-7-custom-hu)
Now the tough part began. Which timing and pixels would the MFD2 accept? Well to make the long story short, the display has 400x230 pixel but the timing has to offer 800x460 pixel. Additionally the borders have to match the physical dots of the display.
How does this work?
Well, it helped to use this picture as the background.
At first the information of the adaptor has to be ignored. That thing knows only a few settings that do not match the MFD2. To recognise this, took some time either. Therefore the special mode has to be choosen, to set a proper timing. The Raspberry Pi will zoom the given pixel and lines appropriate.
sudo nano /boot/config.txt
# MFD2 at HDMI-VGA adapter
hdmi_ignore_edid=0xa5000080
hdmi_group=2
hdmi_mode=87
hdmi_timings 800 0 51 44 121 460 0 10 9 14 0 0 0 32 1 16000000 3
framebuffer_width=400
framebuffer_height=230
disable_overscan=1
... here it goes!
Because the Raspberry Pi will be mounted behind the dashboard I switched off all LEDs.
sudo nano /boot/config.txt
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off
Now the display should be always on. For that, some settings had to be changed too.
At first the screensaver had to be disabled at several locations. sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
#@xscreensaver -no-splash
Next the mouse cursor should be invisable. sudo apt install unclutter sudo nano /etc/xdg/lxsession/LXDE/autostart
#@xscreensaver -no-splash
@unclutter -idle 0.1 -root
And the power management had to be disabled. nano ~/.config/lxsession/LXDE-pi/autostart
#@xscreensaver -no-splash
@xset s noblank
@xset s off
@xset -dpms
The VSWITCH at the MFD2 should be switched by a infrared remote control. For that i installed the normal lircd and configured the receiver. That I will describe at another webpage.
For this description only the additional settings for the output are of interest. At first, the GPIO pins have to be initialized. That's happening at the startup of the desktop: nano ~/.config/autostart/poweron.desktop
[Desktop Entry]
Name=PowerOn
Comment=Set GPIO
Exec=sh -c "sudo /home/pi/poweron.py"
Icon=/usr/share/pixmaps/python.xpm
Terminal=false
Type=Application
Categories=Application;
StartupNotify=true
Within the python script the GPIOs are configured. nano ~/poweron.py
#!/usr/bin/python
# RPi.GPIO Official Documentation
# http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/

import RPi.GPIO as GPIO              # import RPi.GPIO module

# Define Pins
AUX_ON_PIN=16
LIGHT_IN_PIN=20
MOTOR_IN_PIN=21

# choose BOARD or BCM
GPIO.setmode(GPIO.BCM)             # BOARD for P1 pin numbering

# Set up In- and Outputs
GPIO.setup(AUX_ON_PIN, GPIO.OUT) # output
GPIO.setup(LIGHT_IN_PIN, GPIO.IN,  pull_up_down=GPIO.PUD_UP) # input with pull-up
GPIO.setup(MOTOR_IN_PIN, GPIO.IN,  pull_up_down=GPIO.PUD_UP) # input with pull-up
chmod +x ~/poweron.py
The reaction of the KEY_POWER is defined in lircrc: sudo nano /etc/lirc/lircrc
begin
    button = KEY_POWER
    prog = irexec
    config = toggle_gpio 27
end
The program toggle_gpio switches the given output: sudo nano /usr/bin/toggle_gpio
#!/bin/bash
if [ `gpio read $1` == 0 ]
	then gpio write $1 1
	else gpio write $1 0
fi
sudo chmod +x /usr/bin/toggle_gpio
With this the configuration of the Raspberry Pi is finished and it may be mounted in the car.

Connecting the car

To run the Raspberry Pi in a car, some things ar important. First you need a DC/DC converter to create the 5V for the Raspberry Pi. I toke an integrated low drop one.
I like to use the video input while I'm driving. In a thread in the USA I found details for the inputs of the MFD2. (http://forums.vwvortex.com/showthread.php?2601216) The VSWITCH input has to be connected to 12V via a 5k6 resistor to enable the video input.
It was quite easy to find a circuit to combine H sync and V sync to C sync. Because the circuit don't need a power supply, I attached it to the VGA plug.
To connect the signals I use three optocouplers. This solves several problems at once. The connection is potential-free and I'm able to switch +12V and 0V independently.
As the circuit is a simple one, I put it together with the DC/DC converter on a breadboard.

Mounting the Pi

To get a save mounting, I put the Raspberry Pi and the breadboard together on a 2mm alluminium sheet. With double bending on the left side, I was able to mount it behind the dashboard. The free area above the Raspberry Pi will be used by the HDMI plug and audio plug. Even the connection to the car is using a plug. It's visible on the upper right corner. With these plugs the Raspberry Pi can be removed easily.
The area behind the light switch was perfect to mount the Raspberry Pi. There is enough room and two drill holes for M3 (3mm metric) were there either. I only had to thread each hole.
Notice: Don't forget the oil!
In detail, it was'nt that easy. To have room to work, I had to remove some parts and I had o bend the dashboard at the red arrow.
The side cover is fixed by clips only and can be removed easily. That is the way to get to the Raspberry Pi when it is working.
First you remove the cover at the foot padels. It is mounted with one srew, one nose and three clips. Only this single srew has to be removed.
Then you grab the cover on the left side at the door und pull it down with a certain force. The clips will release the cover from left to right and it will fall down in the end.
Please be aware, to position the nose at first at the opening. Otherwise the clips will not be in position or the cover can not be fixed.
You have to know, how to remove the light switch. You can not detect it from the out side. When the light switch is in off position, push the knob slightly a few milimeters into the switch and then turn it to switch the sidelight on. With this the two catches will slide into the switch to release it. Now the light switch can be pulled out easily. The plug ist clamped at both ends. When you release these you can remove it easily.
With this picture you can see the openings for the catches. Beside that you see the two screws that have to be removed to remove the cover from the dashboard.
These three screws at the lower edge have to be removed. They are laid open when the cover at the foot padels is removed.
Together with the two screws at the light switch five screws are removed in total. After that you pull the cover from buttom to the top (four clips).
Notice: Because of the guiding the upper clips have to be removed towards the driver!
From my experience at minimum one clip will stick to the dachboard.
To bend the dashboard to thread the holes, some more screws have to be removed. Unfortunately I did'nt take a picture of that.
This picture shows the finaly mounted Raspberry Pi.
The plugs will stay clear.
I had to remove the cover from the VGA plug, to connect it to the jack. The pinout of the VGA jack I got from the internet. The yellow wire with heat shrink tube combines the C sync circuit. The cable strap fixes the video kabels from the radio at the dashboard. The adaptor is fixed either. If someone is wondering why there is no gig picture here, the picture is'nt sharp-cut.
Here you can see how the plugs need the free space beside the breadboard.
This plug attaches the power supply and the signals from the car to the Raspberry Pi.
This standard ductwork covers the kabels from the plug at the MFD2. It lies loose above the metall at the stearing wheel.
With this special tool you can release the MFD2 to pull it out of the dashboard.
Now the other end of the ductwork can be seen. It lies below the retainer of the MFD2. I use a rest of about 1m.
I connected the coaxial wire to the pre-assembled wires with the clamp for the plug.
To use the plug, I bought the pre-assembled wires from VW (000 979 009 E) and cut them to an appropriate length. To have a shakeproof connection, I used end sleeve for strands to connect the wires. I isolated and fixed them with heat shrink tubes.
I bought the plug, combining two pieces, from VW too. I guess there is a cheaper way for this.
Here you see the inner part of the plug. To offer orientation:
From left to right the signals are:
  1. Red
  2. Green
  3. Blue
  4. <NC>
  5. CSYNC
  6. <NC>
  7. Audio right
  8. Audio left
  9. <NC>
VSWITCH and the ground connectors at put to the other row.
After some tests I decided to use an IR receiver temporarily. It will not work at bright sun light but it is an easy way to control the Raspberry Pi. I use the events from the lircd.
With the power button of the remote control (KEY_POWER), I activate / deactivate the VSWITCH input of the MFD2. This offers two advantages:
  1. Even if the car is moving, the display can be used
  2. The audio input will stay connected. You can listen to the radio or the AUX-IN while the Raspberry Pi uses the display
In case you need audio from the Raspberry Pi, just select AUX-IN with video and audio and you have both signals at the MFD2 as long as the car don't move.
So far this is the first part of the work.
Reading the CAN buses is about to follow ...