Tuesday, October 18, 2011

Permanent Brake and Fuel Line Replacement

“A wise man climbs Mt. Fuji once, only a fool does it twice.” (Japanese Proverb)

There are those days where you get up in the morning and you want to go to work. Then fate shows up and sticks the middle finger right in your face: Go F* yourself. As I was approaching my Mercedes 190D, I saw a nice little pond under the middle of the car. Upon investigation it turned out to be Diesel. Clearly one of the fuel lines was rusted through and needed to be replaced.

The nasty part about a fuel line is that shops usually only cut out a piece and replace that section with generic steel piece that will rust over the years as well. Worse by replacing just that section it is almost inevitable to scratch or inflict some damage on the adjacent fuel and brake-lines as well. Once the protective Zinc-Oxide coating is breached they will rust through in no time, especially in the Canadian winter. That is generally how shops in North America generate returning customers: “Oh my fuel system is leaking again, I just had this last year. This time it is the other line. Thank god that my 'caring' mechanic is around the corner.” In short if you want a quality car repair in this neighbourhood, get crafty and do it yourself (if you can) or enslave yourself in financing a new car every five years. In fact I was quite amazed when I first came here in Germany how often people have to visit mechanics because the quality of most repairs is far from optimal.

Unfortunately changing fuel and brake lines the right way is one of the shittiest jobs on the planet. There are not that many parts involved, but you have no idea how creative the engineers of your car were when they routed the lines through various engine and body parts. Usually brake lines come unbent, so you need to measure and route the replacement the exact same way. In addition, there is a lot of stuff that needs to be removed before you even get to the lines. Furthermore, we already established that just changing one line is not enough. It is a good idea to pre-emptively also do the brake lines and the “other” (reverse flow or forward flow) fuel line as well.

Since this is such a shitty job, you better do it in a way that you never have to do it again. You want to put something in there that will never rust. A friend in Germany referred me to Copper-Nickel Brake lines that are available at Korrosionsschutzdepot.de and I got them when I was on vacation there. They have almost the same specs as regular brake lines but are made from an alloy that cannot corrode. The fuel lines on my car were somewhat close to 1/4 in tubing. After shopping around in several places I found 20ft of soft-copper tubing for refrigerator repair in Canadian Tire and also had the fuel lines dealt with. The other parts and consumables you need are:

  • 2l of brake fluid
  • 5l of Diesel/Gas

Attachment parts for the fuel and brake lines (see the highlights below). Since mine is Diesel and the “exotic” European model, chances are high your Mercedes has different part numbers

  • Tunnel attachments: 5x (201 476 04 84 & 201 476 07 40 & 201 992 00 30)
  • Spacers: 4x 
  • 6 cone-shaped 10mm flaring nuts (brass)
  • 8 hose clamps, 3/16 in – 1/2 in
  • 2 Brake hoses for the rear of the car (chances are that they are rusted in, better get some spare ones)
  • 20 ft 1/4in or 5/16in soft-copper tubing
  • 15 ft 3/16in (4.76mm) brake line

Speciality tools

  • Pressure bleeder (Gunson Ezibleed works best for me)
  • Pipe bender for brake and fuel lines (i.e. 3/16” and at least up to 1/4 in)
  • Flare-nut-wrench 11mm
  • Pipe cutter
  • Flare nut wrench 5/8in (for brake hoses)
  • $$$ Mercedes flaring tool (if you don't buy cone-shaped flaring nuts)
  • A “normal” flaring tool (if you bought the cone-shaped flaring nuts)

The Anatomy of Brake Lines and How to Make them Permanent
Brake lines come in various sizes. They are usually made of steel pipe that is zinc-coated and painted. You will probably notice on older cars that the progression of line decay follows scratches on the paint, followed by white spots, followed by brown rust, followed by a leak. Usually at a first stage of destruction the paint layer is breached and the zinc-coating starts to oxidize. The white stuff that follows is zinc-oxide that becomes reasonably brittle over time. Once that layer is substantially breached the steel starts to rust because the adjacent zinc does not provide enough electrons anymore to inhibit the corrosion. In short the corrosion process is much slower than on regular body panels. The choice for the rather complicated layering is made in favour of economic reasons. Usually cars are meant to be replaced before the process of corrosion matures (say usually 8+ years). Since we nowadays live in a throw-away society, old arts of durable plumbing on cars have become extinct. In early models such hydraulic lines were predominantly formed from copper or nickel tubing. Copper compared to the steel alloy also has the nice property to be more easily flared.

Speaking of which, this is another property that makes the brake lines special compared to other hydraulic systems. Since the hydraulic pressure required to engage the brakes is substantial, these lines need a solid connection to withstand these pressures. Therefore, the fittings are tight dry press-in fittings that use flares. A selection of common flares is shown in the picture above. Most modern cars opt for using the double-E flare shown in the 2nd diagram. The flaring nut has two layers of material to press into the solid connector of the hydraulic system that has a cone-shape. On older cars you may find double-F flares on brake-lines that are mainly meant for connections that are only tightened once. This type of flare is also popular for diesel-injection lines on most cars. Mercedes however opted for double-F 180-degree flare. This flare combines the properties of the E- and F-flares. This flare can be bolted down as much to become flat as a pancake and offers therefore more tolerance to over-tightening than double-E flares. Unfortunately, the flaring tools available to hobbyists are mostly geared towards producing the top-3 flares. What becomes apparent is that the flare design depends on the solid connector as well as the pressure tightening nut. It is possible to use a double-E flare in-place of a double-E-180 flare if the flaring nuts are replaced by nuts that top three flares. The downside is, that these flares need to be much more carefully fitted and are more vulnerable to over-tightening. The complete attachment is described here.
Since flaring, fitting and connecting the lines is a rather painful process, it is best advised to look for a solution that avoids doing it all again in 10 years. To do so one should first select a brake alloy that cannot corrode and, second, use fittings that cannot corrode. You will notice that the attachments of brake-hoses and the master-brake cylinder are made of regular steel. So even when you choose to make the brake lines durable, the change of corroded adjacent parts may force you into doing the work again the next time. I opted to use a copper-nickel alloy that is sometimes found in brake-lines of high-performance cars.

The Anatomy of Fuel Lines
Fuel lines are made from a similar structure as brake lines; however they only have to sustain much lower pressures. Therefore, these lines are usually fitted using regular hose-clamp fittings. The lines in the Mercedes are 5/16 steel lines that have almost an identical coating than the brake lines. They also have a small flare at both ends to prevent a fitted hose from slipping of the pipe. Since the goal here is also make those lines permanent, I opted to use soft-copper tubing that is generally used to repair refrigerators. Unfortunately, 5/16in is a very rare size for this material, so I went a number smaller to 1/4 in and adapted the fitting to suit the existing fuel hoses with hose-clamps.

Diagnosing the Leak
The diagnosis depends on the hydraulic system that broke. It is usually faster to diagnose a brake line leak than it is to diagnose a fuel leak, mainly because the fuel reserve is much higher than the brake fluid. Usually severe brake line defects are noticed by a brake pedal that falls through when stepped on it. Step on the brake and if the “hard point” slowly shifts down, chances are high that your brake system has a leak.
Usually fuel leaks are detected by the smell. In many cases the line that is rusted or leaking is already pretty much covered in Diesel or gas before the substance slowly drips down. If the leak is in the engine bay this is harder to diagnose. In that case you usually have a strong gas smell after the car is parked that quickly goes as the gas evaporates from the warm engine bay. In my case the fuel leak was quite obvious by smell, drips on the floor, and a completely soaked fuel line as shown in the picture.

Removing the gas
In order to do any work on the fuel system the gas needs to go. First siphon most of the gas out of the tank. Although you may inhale some of the fumes, don't drink it! As you see the consumption of gas “heightens” the spirits :) (again DON'T DRINK!).


Disassembly: Fuel Lines
The next step is to remove all the attachment parts around the lines. First off remove the fuel hoses in the engine bay. Since there will still be significant gas in those hoses it is best advised to find a way to seal them.



Cover up the bay with old blankets as some of the lines may still contain some gas. Then remove the cowl covers and jack up the car. As you see the spot on the driveway where the gas leaked is quite obvious.


There are several attachment parts in tight spots, like close to the power steering that need to be removed.
Then remove the clamps at the bottom.



 

Some people argue that the removal of attachments of the fuel and brake lines demand the sub-frame to be removed; however, as you see there is a hole in the sub-frame that allows you to unscrew the attachment parts. As you approach to the tank, get a gas tank ready to catch the last drips of fuel that you could not siphon out.




Now the first thing to do is to remove the lines. Be sure to keep them as much as possible in the original shape. This picture shows the culprit that caused the leak. The line actually cracked on the rusty spot on removal.



The next think is to cut and align the new pieces of tubing in the exact same shape as the original lines. Duck tape helps to keep the old and the new line aligned. Then carefully cut the ends with a pipe cutter.




Now since the copper pipe has a smaller diameter than the original line, we will flare the copper pipe to a double-F flare as shown in the pictures. Please follow the directions of your flaring tool, as the alignment and overhang differs for different flaring tools.



Day one lunch break: Pizza, home-brew, apple-strop and coffee.



Disassembly: Brake lines
The first thing again is to remove the fluids from the system.
Since the brake system is very critical and sensitive any contamination of the system can have catastrophic effects; therefore, clean the connectors of the brake cylinder as much as possible before removing them. Since the brake cylinder may still contain brake fluid, seal it creatively. Here I used a sub brake line and a flare nut to seal the cylinder.


Now remove the brake hoses and the calliper. In my case one brake hose was sitting so tight on the body that it needed to be removed by brute force.


What follows is the exact same game as with the fuel lines. In my case the brass fittings that I had were made for D, E, and F flares. With these flares it was possible to use double F-flare instead of an F-180 flare that is normally used for Mercedes brake lines. When flaring the brake lines, always remember to put the flaring nut first!!!


The 3-way distributor needed to be adapted as well to fit in-place of the one.

Since the callipers are already removed, one can also change the bleeding screws to some that will not rust. When using a one-man bleeder or vacuum bleeding devices, make sure to grease the thread of the bleeding screw. That will prevent air from getting into the system via the bleeding screw threads.



What follows is the assembly of the lines. The clamps to hold the lines on the Mercedes are a quite remarkable design. The rubber piece is clamped with a metal piece and then connected with a plastic-screw. That plastic screw goes on a pin that is on the bottom of the car. It is best to attach these fittings first to align the lines as shown below.



Here we see the newly fit 3-way distributor.



The new brake hoses.



After close inspection the lines also look somewhat uneven, but at least they are tight.



After putting everything together make sure that nothing really touches the body so that the lines do not break due to vibration. In certain tight spots, you can use electrical tape instead of the rubber spacers to dampen vibration a bit.


After everything is put together make sure to bleed your brake system. There are several tools on the web. My tool is the Ezibleed from Gunson that kind of mimics the behaviour of a shop pressure bleeder. Any air left in the system will become a substantial hazard. On the Mercedes the fuel system is self venting. Since we sealed the hoses to the engine, there is enough gas in the fuel filter to get the engine started and let the system vent on its own, no additional bleeding is needed there.
Also after the job there is considerable cleanup to be done. The secret to cleaning up oil and gas spills is to use cat litter and scrubbing it in. Cat litter will quickly soak up all the residuals.

Final remarks
Any work on critical hydraulic systems on a car is hazardous. Do not attempt this job as novice car repair enthusiasts. Furthermore the hazards of working on regular gas fuel systems are much higher than on a Diesel car. Regular gas has a very flame point and can be easily ignited. When attempting this job there will be instances where you are at least a little drenched in gas or diesel.
Another potential risk arises from the flaring of the lines. If you have never flared any lines stay away from the job. Getting the flare in shape the first time takes a large amount of practice. It is advised to practice at least 10 consistent flares before moving to the actual line that is to be put back in the car. Poor flares can cause leaks or even cracks in the lines.
Since flaring and wedging the lines in place is so painful, choose a material that avoids you from making it all over again in a few years. In my case I chose Cu-Ni-Fer tubing for the brake lines and regular soft-copper pipe for the fuel lines. In certain countries, especially Germany, brake lines materials need special approval from the motor registry. Make sure your material is approved before putting it in. In some cases covering the installation in asphalt under-body coating “by accident” is also a way to “pacify” the registry (psst, but I didn't tell you that).

Since I used a Japanese proverb to motivate the approach to a permanent repair, here is the original Japanese ad for my car from a long time ago.

Tuesday, September 13, 2011

Baby Steps in Nindendo DS “Homebrew” Hacking

(It is interesting to see how a company evolved from selling playing cards and tiny electronic gimmicks to a major market player in video games, when the video gaming industry actually flat-lined. Video Credit: http://blog.beforemario.com/)


While travelling to and from conferences or being in transit, I always missed some sort of entertainment device. I received a Kindle a while back but reading e-books all the time was not that rewarding. After doing some research, I settled on the Nintendo 3DS. The Nintendo DS and DSi its predecessors have a large base of 3rd party software apps, usually referred to as “homebrew”. Furthermore a fully customized GNU tool chain already exists for the device. Although there are no dedicated free development tools for the 3DS out there, it can run in compatibility mode with its predecessors. Hoping I may be able to program the 3D display and the camera I actually settled for the newer device. In addition this box also runs “Brainage 2”, several language trainers and, most importantly, “GTA Chinatown Wars” .... but this article is about hacking this thing.

Having taught operating systems in Waterloo, I deeply regret that I did discover this neat little toy and the growing developer community earlier. I probably might have adapted the term project for the students to be coded on this device instead of a boring Coldfire board. Unfortunately, I cannot change the past but only the future.



Nintendo DS Architecture
The Nintendo Architecture is actually a neat one. This toy is a little powerhouse. All DS models have two displays, one being a touch-screen, a WiFi adapter, a microphone and a synthesizer. Newer models come with an SD-card adapter, cameras and a 3D display. It has a dual-processor architecture, consisting of an ARM9 processor running at 66 MHz and an ARM7 processor running at 33 MHz. In general the ARM7 is usually used to take care of the peripherals, while the ARM9 runs the computationally intensive tasks, mainly graphics processing for the top-display. The initial Nintendo DS has about 4 MB of RAM and 656 KB of VRAM that is shared among the processors. Here you can find some neat pictures and explanation of the memory layout. If any of you remembers the layout of your ECE354 Coldfire project, trust me this is like Kindergarten compared to the NDS. I might port some of the OS project code to it for the heck of it, but figuring out a context-switch on two-processor system with shared memory architecture will take some time: P.



Development Environment
Using Linux the obvious choice was to install the modified ARM9 tool chain for the NDS, which can be found here. Follow their directions on installing it. As an emulator I chose Desmume.

Although you can use an emulator to run and test your code once you developed it, it is almost imperative to be able to run your code on the real device; and that is where free NDS development stops. Nintendo is and has historically been very obsessed with battling piracy. I think it goes without saying that since program this toy to the bare metal, you can easily pirate game roms as well. Therefore, Nindendo made substantial efforts to curb any sort of hacking with the device by implementing a sophisticated boot-loader for the roms. Although the firmware of the NDS is flashable, you probably do not want to risk turning your investment into a brick. A relatively cost-effective way to circumvent the boot loader is to buy a 3rd party adapter that spoofs the boot-loader and allows you to run your code in the device. In my case I ordered a R4i 3DS card that came with the “wood firmware” from OZ3DS. Although the shipper claimed to be in Australia, the package actually arrived last Saturday with Hong Kong Post.


The adapter came with an 8GB Micro-SD card that contained the firmware among other things. After piecing everything together and putting the card into my 3DS, the card was detected as “Sponge Bob Square Head”, this is the game that the engineers probably reverse engineered to circumvent the boot-loader. After starting it one looks at the main screen of the “wood” kernel. The kernel loads the file-system from the Micro-SD card. 
The “wood” firmware and your programs are saved as “NDS” files on the card. Whenever you select an NDS file the kernel will invoke the boot-loader and run the application. For those who have been around with computers for a while, this will feel an awful lot like MS-DOS or Amiga KickStart ... a single process operating system. Worse; when you exit the application you will be automatically thrown back into the 3DS GUI and not the “wood” kernel, which can be frustrating.



The First Tiny Steps
The first thing people program is usually an application that displays “Hello World” on the main screen of the box. Unfortunately, the NDS being a gaming device does not come with a nice firmware that allows you to invoke a BIOS/firmware routine to simply display an individual character on screen. Instead, characters would have to be rendered as sprites in the memory of the device and then copied to the screen. Worse initializing the two displays and processors may also not be that easy. To cut the explanation short, if you want to build something simple as hello world for starters, you need increase the level of abstraction and consider a 3rd party library that does this for you. Fortunately, such a library exists and comes with devkitPro. For our initial example, we will be borrowing the following functions: iprintf, consoleDemoInit and touchRead. “iprintf” is an integer-only version of printf that comes with the devkit.
  • Using iprintf instead of printf will potentially reduce the code size but otherwise makes little difference in our example.
  • consoleDemoInit performs several initializations, such as loading font sprites and initializing the bottom display for console output.
  • touchRead takes the last touch position and loads it into the given pointer.

Piecing everything together the finished looks like this
#include 
#include 
int main(void)
{
  consoleDemoInit();
  iprintf("Hello World!\n");
  while(1) {
    swiWaitForVBlank(); /* ?! */
    touchPosition touchXY;
    touchRead(&touchXY);
    iprintf("\x1b[1;0H");  /* ?! */
    iprintf("Touch x = %d   \n", touchXY.px);
    iprintf("Touch y = %d   \n", touchXY.py);
  }
  return 0;
}


If you read the code carefully, you will notice two potholes.
  1. What is that swiWaitForVBlank used for?
  2. What are those cryptic chars in the prinft?

Since this program continuously monitors the input from the touch-screen and displays the results on screen, we do not want to overrun the display routine. That is achieved by waiting for the VBLANK interrupt. The name stems from older systems that still had a CRT display. The interrupt was raised whenever the ray is turned off and the pointer returned to the upper left corner of the video screen. On the NDS the interrupt is raised whenever the display redraws.
The cryptic characters in the printf are an ANSI escape sequence that allows repositioning of the cursor. In fact our application will draw “Hello World” at the first line, then reposition the cursor at character position (1,0) and then print the coordinates. Because of the continuous while-loop the display would automatically scroll, if we do not reposition the cursor for each iteration. Running my first “homebrew” on the 3DS looks like this.



You can download the code from here (to come). The Makefile has only been slightly from the examples that came with devkitpro.



Summary
There is not much to summarize so far. The NDS is a really affordable toy that can, with some hacks, be easily programmed down to the bare hardware. There are numerous 3rd party emulators and developer tools for the NDS. In addition libNDS provides a very convenient high-level access to the hardware features of the device. The example shown here is very basic but shows how easy it is to program the box.
It actually took longer to take the pictures and write this article rather than coding the example. I will soon open some much more sophisticated open source projects.