Thursday, November 5, 2015

AUX in Volvo HU-XXXX radio

This post is a description/tutorial on how I managed to hack the stereo (HU-650) in my Volvo V70 (2007) and successfully added my own AUX input. This hack should work with any HU-xxxx unit, "HU" meaning Head Unit (the stereo)



Background

Why, why, why isn't there an AUX input on my car stereo from 2007?
Yes 2007 was before the big era of smartphones, but everyone owned a couple of dirt cheap mp3 players and  iPod was a big thing.

The HU that my car is fitted with has two super retro 8-pin DIN-connections on the back. One of which is for connecting a CD-changer "CD-CHGR" that you could have installed in the boot of the car - but who uses CDs these days?

It didn't take allot of research to find out there is already a product out there that lets you add an AUX to you HU-xxxx. The only drawback is that it sets you back $80 and most of all: It doesn't come with the awesome feeling that you get when you have hacked the stereo yourself.

Research

It wasn't an easy thing finding information on how to hack the HU, but after allot of research I finally found some really good pages that made the hack easy peasy.

This is how it works:

  • The source knob on the HU lacks the ability to choose the CD-CHGR until you connect the CD-changer. 
  • To trick the HU that you have a connected a CD-CHGR is not as easy as to shorten two of the pins on the DIN-connector, but it has to be done in code via a protocol named MELBUS
  • MELBUS is a protocol that utilizes a clock pin and a single bi directional data line to transfer the data between the units and the HU.
  • MELBUS uses three lines: Clock, Data and Busy see blue lines on picture below: ("Run" is just 12V from battery)
Picture source
  • In the picture above you can also see the Left and Right Audio signals that I tapped into for the AUX-input (Red). 
  • Focus on the left DIN-Socket (female) on the picture, that's the back female socket on the HU. 

Hardware


Total cost: ~$3.5

Hacking together some code

Edit 2016-11-04
A guy named Sebastian has modified my code and his version is more stable, and it also works on Mitsubishi HU and supports displaying track numbers! -Here's a link to his code!

Finally some programming! 
I found this awesome write-up that contained almost everything I needed to fool the HU that the Arduino is a CD-CHGR. I will talk you through the process:
  1. Set BUSY to low for 1000 ms to make the HU run its initialization routine
    1. The HU init routine starts by sending three bytes: 0x07 0x1A 0xEE
    2. Then two bytes per optional connection device (~30 of them), the first byte being the predefined ID of the device (ex. CD-CHGR = 0x8E), followed by either an empty byte 0xFF, if the device is not connected, or the answering ID of the device (CD-CHGR = 0xEE)

      Example: External CD-CHGR: ID = 0x8E and its return ID is 0xEE
      Example: Internal CD-player: ID = 0x80 and its return ID is 0x86
      See list of predefined addresses and returns on bottom of this site. 
    3. I.e. to simulate a connected CD-CHGR we have to: 
      1. Trigger the HU init routine
      2. Wait until HU is sending out our ID (0x8E)
      3. Respond to that by sending back 0xEE 
  2. Now the HU has registered that we have a CD-CHGR and it is now available through the source-knob, and will listen to the Left and Right Audio pins on the DIN-plug. 
  3. Every time the car ignition is turned on, the HU will automatically run a secondary initialization routine:
    1. Starting by sending four bytes: 0x00 0x00 0x1C 0xED 
    2. Then two bytes per already registered connection devices from the first init routine, the two bytes follows the same pattern as in the first init routine, first ID, than expecting the same answering byte as before.
    3. If the HU won't get an answer from the CD-CHGR, the device will be removed, and we have to set BUSY low again to call the first init-routine.  
That's it for fooling the HU that the CD-CHGR is connected, now it's just a matter of connecting a device to the Left and Right Audio pins plus Ground. I soldered a network cable plus an 3.5 mm Audio cable to the pins of a DIN-plug.

Take care when reading the schematics above, it is the left socket on the picture you are interested in, that's the socket on the back of the HU-unit (female) and will be equal to the back of the DIN-plug.  (as you can see, I put the red cable on the "RUN" to use the 12V to power the arduino, White and yellow are Audio Left and Right)
As a bonus the 12V is only active when the ignition is turned on => no extra load on battery caused by the arduino when car is not used)



The code I wrote (below) is well documented and fairly easy to understand...

I had a hard time getting the function "SendByteToMelbus(uint8_t byteToSend)" to work.
It turned out that the Arduino functions: digitalWrite(MELBUS_DATA, HIGH); and LOW are too slow for this code, (MELBUS runs at 10-12MHz) and CLK had returned to high state before Databit was changed.

To solve this, I had to go back to the old AVR-GCC technique and use
PORTD |= (1<<MELBUS_DATA); and
PORTD &= ~(1<<MELBUS_DATA);
in place of the Arduino functions.

I tried this setup without any form of ground-loop isolation and it works like a charm! Even when the engine is running and my smartphone is charging through the cigaret-socket the sound is crisp and no disturbing noise (alternator suppose to cause ground noise)

I guess one could buy an external Ground Loop Isolator ($5) to be on the safe side....










88 comments:

  1. Nice, where was this 5 years ago when I had a 2000 S80 and a sad cassette deck to aux converter?

    ReplyDelete
  2. Great job!!!!
    Really nice

    ReplyDelete
  3. You really helped me out there with some things I was struggling to do with my emulator (doing IO the AVR way + a typo in my CD-Changer address).
    Issues with your code are mostly the mixed use of Arduino and AVR pin numbers: For your Nano these seem to match, but on my Sparkfun Pro Micro (Clone), the numbers are off (i.e. Digital Pin 2 is PD0/INT0).

    One question though: You are supplying your Arduino via the MELBUS 12V run line - is that really safe?

    In case you're interested, my code is on github (https://github.com/archi/melbus). But it's way more bloated than yours, and probably still more broken ;-)

    ReplyDelete
    Replies
    1. Nice!
      Why should the 12V not be safe? (im not an arduino expert)
      Make sure you notify me if you succede in sending text to the HU (and get rid of the CD ERROR...)
      /Karl

      Delete
  4. Hello
    I want to apply this to my car's HU (Citroen Xsara witch a VDO RD3 Head Unit)
    the difference is that my HU doesn't contain a 8-pin DIN connector, but instead, it has a different one as shown in this picture: http://img.mysoocuu.com/photo/ycarlink/uploaded/month_1305/201305101331562588.jpg
    My questions are:
    - is it possible to do the same work on my HU ?
    - if yes can you please help figure it out ?
    thank you

    ReplyDelete
  5. Hi I was wondering if you could post a few more pictures of how you hid this and wired it? Thanks

    ReplyDelete
  6. Hello,
    nice job! Tried to use your hack on another melbus device which is mitsu's product called w142 (PH3000). It has a 13-pin cd changer socket like those used in Volvo Nav units. Pinout is the same for melbus (pins 11-13) data and audio (pins 1-4) signals. Strange things happen though: the unit not only does not want to switch to cd changer, but also the display disappears and the switches on front panel of the unit do not work. Otherwise, the unit plays normally - with no cd it plays the radio and when i give it a cd it starts playback with no problems. I'll try to investigate further, there has to be a way to make your hack work on mistu's also! :)

    ReplyDelete
    Replies
    1. Hi,

      any progress with the w142? I have a similar mitsu radio which doesn't work with this hack either.

      Delete
    2. Did you manage to get it working?

      Delete
  7. where the RUN connection should be on arduino pinouts?Pin D3 - CLK
    Pin D4 - Data Pin D5 - Busy and RUN?

    ReplyDelete
  8. Excellent write-up! Btw. the ground loop isolator is not needed, because the line input of the HU is a so called "quasi-differential" input, i.e. it senses any noise on the ground line (pin 2) and subtracts it from the L/R signal via an operational amplifier.

    ReplyDelete
  9. I am using your code to sniff the melbus communication between a mistubishi HU and its seperate display unit, which is also the board computer of the car. Initially, I got very unstable data. As it turned out, this was due to a race condition between data and clock. The problem was resolved by changing the edge where the clock interrupt is triggered from the rising to the falling edge, because this allows the data line to settle after it changes at the rising edge.

    ReplyDelete
  10. Tried this but cannot seem to get it to work. It doesnt add CD CHGR as a switchable input any idea why? It does however prevent the CD player built in to work

    ReplyDelete
  11. There is a bug in SendByteToMelbus(). This function needs to release the data line between two transmissions. Take a look at the waveforms at volvo.wot.lv . If the data line remains low during two transmissions, the HU assumes that a slave requests to become bus master and stops the clock. That's the reason, why you can't respond to the track info request. Btw. there should be also a timeout while waiting for the clock edges.

    ReplyDelete
    Replies
    1. Hi! Could you please share your code with the modifications? Much appreciated! Thanks!
      How stable is your solution? What type of arduino do you use?
      Greetings

      Delete
  12. Im not very good when it comes to coding but would this explain for mine not connecting 25% of the time i turn the radio on?

    ReplyDelete
  13. Hello. I have tried to get this solution to work for a few days now on my arduino uno. Is there any obvious reason why this code shouldn't work straight on UNO?

    ReplyDelete
    Replies
    1. I am running this code on UNO. I had to do a number of changes to the code to get it running. However, none of these changes was due to the different Arduino platform, but due to a different HU (Mitsubishi, not Volvo) and due to enhancements such as displaying track number and run time. Some changes also might have been necessary due to bugs in the original code, but I am not sure about this, because I do not have a Volvo HU to test it. so it might be that the melbus protocol is just implemented slightly different on those HUs. For example, I had to change the interrupt edge mode from RISING to FALLING. And for text display I had to change SendByteToMelbus() such that it releases the data line between two consecutive transmissions. After all my implementation is still not perfectly reliable, because from time to time the bus gets reset by the HU for no obvious reason.

      Delete
    2. I was able to improve stability by adding "EIFR |= (1 << INTF1);" at the end of the interrupt service routine to avoid spurious interrupts triggered by noise. But stability is still not perfect. Might need some RC-Filtering or at least 100 series resistance in clock, data and busy lines. Also important is that all melbus lines are open collector lines with pull-up resistors (found this info in service manual for mitsu car radio). You can simulate open collector output by clearing the relevant DDRD bit during high level output. This is important because HU will detect bus conflict otherwise.

      Delete
    3. is there a chance you would be wiling to upload the updated code to Github or email it to me? i would be willing to test it on my HU-611 (volvo) because with the supplied code it actually works 1/20 i start the car.

      Delete
    4. sure, just post your email address.

      Delete
    5. Hi guys! I love how you guys help each other out to get the code to work on different modes - good job!
      I would appreciate if you posted a link to your code on github or any other source instead of emailing each other, so that all of us can learn from your upgraded code!
      Keep up the good job!
      /Kalle

      Delete
    6. Hi Kalle, I don't know how to setup Github. So, would you be willing to put the modified code in this blog instead? Atm I don't have much time to work on it, but my long term goal is to control a FS Verona DAB+ module and a BT APTX A2DP/handsfree module from my Mitsu HU via this interface. So if someone else is interested in this as well or wants to adapt it for Volvo HUs, it could be worth to setup a Github in the long term.

      Delete
    7. sure, email me (kalle.lofgren(at)gmail.com) the code and i'll put it on my Github next to this code!

      Delete
    8. Oooh, so the modified code by Sebastian (linked in the post) can actually send data?
      I can't wait until I have some free time to take a proper look at it and add it to my github project :)

      Delete
  14. Karl,
    Great job!!! I've just made fast try and everything works perfect!

    Does anyone think about bluetooth and how to use "previous" and "next" buttons on radio?

    ReplyDelete
  15. Thank you for posting this great information Karl!

    I plan to use this on an Alpine TDM 7544 head unit. I wondered though, is the MELBUS you mentioned the same protocol as the Alpine M Bus?

    Thanks again!

    ReplyDelete
    Replies
    1. No, it's not the same.

      Delete
    2. This was my suspicion, thank you!

      Delete
  16. Have you recieved the code through email? I would still like to test it.

    ReplyDelete
    Replies
    1. Can confirm 100% that this works on a hu-611 with an iphone 6. Thanks a bunch. It may help others to also embed this as an alternative on your post

      Delete
    2. Awesome! Thank you so much Karl, the modified code worked no problem on my Volvo V40 HU-655. I was a little confused by the lack of a free DIN socket in the back of my HU until I realised that one of the DIN cables is an unused factory installed loom that runs to the back of the car ready for an aftermarket CD changer to be installed. I was also wondering if I would still be able to use the radio, tape, CD as there is no on/off for the Arduino.. but not to worry, all of these still worked and the CD button on the HU cycles between the Arduino Aux-In and the HU CD player. Many thanks again.

      Delete
  17. Maybe someone found out how to improve code, that the radio would show song name?

    ReplyDelete
    Replies
    1. It is possible to do that, but you need to emulate a MD changer instead of a CD changer.

      Delete
  18. Maybe somebody knows the song name the download procedure in MD mode?

    ReplyDelete
    Replies
    1. Ask this guy: http://www.motor-talk.de/forum/mein-car-pc-im-volvo-v70ii-ein-erfahrungsbericht-t3753505.html

      He has assembler source code for a PIC-based USB-melbus interface that is able to emulate a MD changer and display song names on Volvo HUs.

      Delete
    2. Thanks for the link, but the man does not answer.
      I need for the project(http://www.forum.volvo-club.by/viewtopic.php?f=35&t=24857), and the opportunity to explore, for example imiv no.

      Delete
    3. post your email address, maybe I can help you...

      Delete
    4. First of all, Huge thank you Kalle for sharing your code!! This is working flawless with my HU 555 and UNO.
      Working track ID's would be a great addition. Here is the code for MD modus:
      Unit ID Main Response Master Mode ID HU
      MDC(External) D8 DE DF D8 or D9
      CDC(External) E8 EE EF E8 or E9
      more info here: http://volvo.wot.lv/wiki/doku.php?id=melbus
      If anyone has made any progress, please share.

      Delete
  19. I tried the modified code on a Mitsubishi W142 HU but I can´t get it to work.
    Has anyone else tried it on a Mitsubishi W142 HU?

    ReplyDelete
  20. Hi guys,

    I have same setup (2007 volvo with HU-650), but using UNO. Unfortunately I can't get pass connection phase. Tried both and Karl's and Sebastian's codes, but still can't receive any data from HU. Any hints where to look for a problem would be much appreciated

    ReplyDelete
  21. Hi Darius
    I myself also use a UNO with a HU-555, Karl's code should work without issues.
    Check your connections with a multimeter, make sure that's not the problem.
    Maybe this helps (see link) the PIN layout is identical as shown above.
    https://farm1.staticflickr.com/623/23426340929_9ee095dbef_z.jpg

    ReplyDelete
    Replies
    1. Thanks a lot for the reply. I will recheck the connections again. I really would like to have it working, it is at the moment breaking the whole project.

      Delete
    2. Thanks Chip again, because of you I was able to identify my two rookie mistakes - (1) mixed wires, (2) didn't bother to connect ground and hot from HU to arduino, just powered it from USB.

      And thanks Karl and Sebastian for codes. Works good, now the aim is to find how to manipulate all the buttons

      Delete
    3. Hello ,Chip_trauma can you help me about my Hu-555 how to make auxiliar please ? Alexandru332@gmail.com
      tnx!

      Delete
  22. Hi!

    Code provided by Sebastian works like a charm on the first try.
    But I have now another problem, when I try to simulate, that UNO is MD-Changer (not cd-changer), then code just doesn't work.
    What I have changed is that all E8s I changed to D8, EE to DE, EF to DF and all E9 to D9.
    Does anybody know what current issue is?

    ReplyDelete
    Replies
    1. post your email address, I send you Arduino file ...

      Delete
  23. hello does any had picture of wires with color from DIN 8P to arduino or how conect the wires from DIN to arudino. Thanks for all :)

    ReplyDelete
  24. Hey can you make same video how to connect all bicose i not understed how connet cable to adrino

    ReplyDelete
  25. If you read the code and refer to the picture of the plug you can figure out the correct way to connect it plus read a few comments

    ReplyDelete
  26. Hey, awesome project! I have been looking for something like this for a very long time.
    Problem is, I keep on getting inconsistent data readings. I am starting to believe that it is something regarding the wiring, or something with the logic levels (mismatch voltage between HU and my arduino). Currently I'm connected to the DATA, CLK and BUSY lines directly. Should I be using a resistor or capacitor and if so, what would the wiring look like?
    Thank you so much!

    ReplyDelete
  27. Can also confirm modded code works on a HU-655

    ReplyDelete
  28. Hi! I ported this code to SMT32 which works much better than Arduino. Check my video, link bellow. I speak czech there, but you get the idea. If you are interested, let me know in comments under video. :)

    Link: https://www.youtube.com/watch?v=zPV9rGAQs34

    ReplyDelete
  29. This comment has been removed by the author.

    ReplyDelete
  30. I'll be very happy if you send me latest version of code for Volvo HU into rokas@mail.com Thank you very much

    ReplyDelete
  31. does anyone run this project on HU405? thx for anwser

    ReplyDelete
  32. Great project, if anyone has any insight on how to send the ID3 tags in MD changer mode that would be great. I'm working on a project that will take the text info from a bluetooth connection and send it over to the HU.

    ReplyDelete
    Replies
    1. hello, I'm interesed of you project. I want to learn how to write simple "AUX IN" on the HU803 LCD
      nenkostefanov@gmail.com

      Delete
  33. I'm having some trouble. I have the HU working well (HU-801 Volvo S80) in CD CHGR mode but it will always fail after a short while. The CD and Track numbers will start to change sporadically and eventually I get a "CD LOAD CARTRIDGE" message that stays in place. When this is here, I cannot adjust volume (but the music still plays from AUX). After cycling the key, the CD CHGR mode will disappear until eventually it will pop back up (could take many key cycles and days later). Any thoughts? Code problem? Connection issue?

    ReplyDelete
  34. Someone with MD changer source code that can change text on HU display? Please share!

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Hello , for volvo S40 2002 Hu-555 to make aux is possible? SOME DIAGRAM ?

    ReplyDelete
  37. Hi Karl
    I have a Volvo HU803 and want to make AUX input like you.
    I am using Arduino nano 328P with Arduino 1.6.13.
    I copied your code into a new file.
    When I try verifying the code and I get mistakes. (ex redefintion 'void setup()' and so on.
    Any advice?

    Kind Regards

    Over and out

    ReplyDelete
  38. Hi Karl,
    I have been meaning to build one of these for ages. All the bits arrived some time ago, but no time to do anything about it. I stole some time away from the family over our Christmas holidays, programmed up the Arduino and built up the connectors. Actually, I built an extension lead from the back of the HU 803 to just behind the removable panel at the side of the footwell, to enable easy connection without having to remove all the climate control and radio system. After a little bit of fiddling, lo and behold, IT WORKS!!! I am so grateful to you for sharing all this info. Hope you and yours have an excellent 2017 and beyond.
    Regards
    Doc BJ

    ReplyDelete
  39. Hi, thanks for the guide. I have a small problem. I have done everything , but when I connect my phone to the aux, sound only comes out of the front speakers, and the back speakers stay silent. Any idea how to fix this ? B.T.W My head unit is a HU-555

    ReplyDelete
  40. Hi, I posted here the other day, but either it failed, or it was removed. Let's try again -
    I just wanted to give thanks to everybody that shared their knowledge about MELBUS and made the AUX input possible. I built one myself and used Karl's code and modified it a bit. I put it on github if anyone is interested. It supports showing the cd# and track# and you can change track by pressing the buttons on the steering wheel/radio. It can also trigger MASTER mode, but I didn't know what to do with that. There is also a simple schematics of how to connect it to the arduino.
    Hope that you don't mind using parts of your code Karl!
    Here is the link: https://github.com/visualapproach/Volvo-melbus.git
    /Thomas

    ReplyDelete
    Replies
    1. By "changing the track" I mean changing what's displayed on the HU. I hope to get it to really change songs when I get my bluetooth module. Also, I made some (small) progress on the MELBUS protocol and it's in the code comments.

      Delete
    2. Hey!
      Thanks for awesome instructions!

      What is the type of the transtistor you used in the connections?
      How can the voltage drop 3v from 5v if you use blue leds, i mean doesnt blue leds take about 3 volts.

      Delete
  41. Hello! Maybe someone knows how to send a text to the HU in SAT mode?

    ReplyDelete
  42. Maybe someone has a log's Imiv SAT?

    ReplyDelete
  43. Thanks for this great build..
    I used an Pro Micro instead.

    i only had to change the line
    const uint8_t MELBUS_CLOCKBIT_INT = 1; //interrupt numer (INT1) on DDR3
    to
    const uint8_t MELBUS_CLOCKBIT_INT = 0;
    as the pro micro does not adress interupt 1 to pin 3


    ReplyDelete
  44. So it is safe to connect the arduino device correctly?
    On which voltage level does MELBUS work?

    ReplyDelete
  45. Data, clock and busy lines are 5v which is safe on an arduino (5v versions, there is 3.3v versions also). The run line is 12v which can be fed into vin on the arduino. See my note on github though about avoiding back powering your arduino through the 5v lines. /Thomas

    ReplyDelete
  46. Hi, thanks for the post!

    I have a problem with project, i can trick HU and get that message on the radio screen "cd error", but i have no sound!

    Any suggestion?

    ReplyDelete
  47. thank you all for information!
    your code Works great with head units with serial numbers 8xxxxx.
    However, it does not work with older head units. Internal CD player and arduino somehow interfere and then nothing works.
    This code https://gist.github.com/klalle/1ae1bfec5e2506918a3f89492180565e Works with older head units with serial numbers 9xxxxxx.
    Tested on HU-601

    ReplyDelete
  48. I see where the run 12v would connect to the vin on the arduino, but where does the gnd from the arduino go?

    ReplyDelete
  49. Does latest code work with Mitsubishi w142 hu?

    ReplyDelete
  50. hello karl,

    i want asking for where we soldier aux R/L/Ground from mp3 speaker unit
    and where is i must soldier for Dacr/Lacr/Ground from mp3 speaker unit

    My HU is HU-601

    ReplyDelete
  51. Hi!

    First, thanks for the great introduction!

    Unfortunately i dont know how i connect the gnd from the Din Socket to my Arduino.
    Which pin at the Din socket should i use?
    Can anyone help me?

    Thank you!

    ReplyDelete
    Replies
    1. Ground pin no 2 on cd changer socket

      Delete
  52. Thanks For Sharing information... For the best prices & service in New Zealand. Car audio Sales, repairs & mobile car audio installation of all car. Contact Us:- 33384653


    ReplyDelete
  53. Any info on MD-changer/text info or arduino files, email me at pfloyd36069@gmail.com

    ReplyDelete