Skip to content


DIY USB to Serial Cable For $3!

breadboard Jonathan Thomson submitted this useful article about converting a low cost cell phone USB cable into and easy and cheap way to connect to an Arduino microcontroller setup. Jonathan found a cable for less then $3 which can be hacked to perform the same function as the typical $20 FTDI USB cable often used in Arduino projects.

Jonathan submitted as part of the uCHobby Giveaway project and has selected to receive a Plug-in Bread Board Power Supply Kit for this article. 

Introduction
The Arduino board is a great way for beginners to start learning about
developing software for microcontrollers; however it’s cost, while a steal when
compared to the initial investment required in the past, can be a little too
steep for a do-it-yourselfer who wants to do things cheaply. To be fair there
are Arduino clones that do lower the price a good bit, but the real cheapskates
that don’t mind doing a little extra work can’t help but think they could do it
for less.  For these penny pinching DIYers setting up an ATmega on a breadboard
seems like the way to go until they discover the FTDI USB cable is $20. What a
heart breaker! There are slightly cheaper alternatives, but a real scrooge
Googles on. Well look no further because this article has just what you’ve been
looking for.

The trick is to use a Nokia cell phone data cable based on Prolific’s PL-2303.
These cables have a USB to Serial TTL converter built right in. They’re
available on eBay and Deal Extreme and very inexpensive. I got mine for just
$2.69 shipped. Data cables DKU-5 or CA-42 will work. This article will focus on
the CA-42 containing a PL2303HX rev. A. The methods described here should work
in general for cables using different chips.

cable

 
breadboard 

Preparation

  • Tools:
    • Wire Stripper
    • Multimeter
    • Anti-static wrist strap

Driver
Recent versions of Linux have the driver pre-installed. Users of other operating systems may find drivers here
Install the driver.

So you don’t waste time with a dud cable or bad drivers, you should first check that it’s recognized and assigned a COM port…

In Linux, use the command ‘ls /dev/ttyUSB*’ before and after you plug in the cable. You should notice a new ttyUSB is added after you connect the cable.

In Windows, plug in the cable then open up the Device Manager by clicking Start–>Run and typing ‘devmgmt.msc’ followed by Enter. Now find the section named "Ports (COM & LPT)" and click it to expand. There should be a port named something like "Prolific USB-to-Serial Comm Port (COM#)" or perhaps "NOKIA… (COM#)". Unplug the cable; the cable’s entry in Device Manager should disappear.

Precautions
Never work on a live circuit! Always power off the breadboard and always unplug the cable before making adjustments to either; I’ve tried to remind you of this throughout the article but I may have missed a couple of places. There is a possibility you could damage your computer, some other property, injure or even kill yourself! I’ve tried to be very thorough in my instructions, this however is not an excuse for you to turn off your brain. In no way does this paragraph convey all of the various precautions one should take when working with electricity and electronics. Please read the entire article before you begin to modify the cable. Wear an anti-static wrist strap.

Probing
There are most likely several different manufacturers of these cables because the same model will have a different number and color of wires depending on who you buy it from. Therefore we will have to probe the pins of the phone connector to determine which wires are TxD, RxD, and GND. To do this cut the cable a couple of inches (5 cm) from the phone connector. NOTE: I said the phone connector not the USB connector. Most of the cable should remain attached to the USB connector, but you need to leave enough cable attached to the phone connector to be able to strip the wires and attach an alligator clip (or a terminal block if you like). Strip each wire. Set your multimeter to diode/
continuity, and attach the black probe to a stripped wire. Now probe each of the phone connectors pins with the red probe until your meter beeps. Write down the color of the wire and its corresponding pin number from the picture below.

Repeat until you’ve matched each color with a pin number. Not all pins will have a connection. You should double check your work because the wires are very thin and the pins are small and close together.

CA-42_DKU-5_pinout 

Pin 6 is the cable’s TxD line, pin 7 is RxD line, and pin 8 is ground. For my cable pin 6 was white, pin 7 was blue, and pin 8 was black. I also had two additional wires, one green (pin 3), one red (pin 4). However, I can almost guarantee your colors will be different so you must perform the steps described above. To be positive we’ve identified the wires correctly we can perform a couple of tests.

Testing

We’re now finished with the phone connector, so now we’ll turn our attention to the remaining cable which has the USB connector. Strip the wires which correspond to pins 6, 7 and 8. Set your multimeter to measure voltage. Attach the black cable to the wire which corresponds pin 8 (GND). Attach the red cable to the pin 6 wire (TxD). Make sure none of the wires are touching one another! Plug in the USB connector. The multimeter should read ~3.3V (I measured 3.5V).
Unplug the USB cable. Repeat the previous steps for the pin 7 wire (RxD). The RxD line’s voltage should be less than the TxD line. The other wires are not needed for communicating with your ATmega; nonetheless the pin 3 wire measured
0V and the pin 4 wire measured 3.0V. Your cable may not have a pin 3 or pin 4 wire.

For our second test we’ll temporarily turn our cable into a loopback cable and use a serial communication program to see if we’ve identified the wires correctly. Make sure the cable is unplugged! Twist the RxD and TxD lines together. Make sure none of the other wires are touching one another! Plug the cable in.

In Debian
You must determine which device name Linux gives to the cable. For me, since I didn’t have any other USB devices plugged in, Linux gave it /dev/ttyUSB0. If you do ‘ls /dev/ttyUSB*’ before and after you plug in the cable you should be able to determine which device name the cable gets by comparing the outputs. I used screen as my serial communications program.

$ screen /dev/ttyUSB0

Press several keys on the keyboard. If they are displayed, then you have correctly identified the TxD and RxD line. If they are not displayed, you’ve done something wrong, reread and retrace your steps. To exit screen type Ctrl-A \.

In Windows XP
The Preparation section explains how to find your cable’s entry in the "Ports (COM & LPT)" of Device Manager. Repeat those steps and make a note of the cable’s COM#.

Then launch HyperTerminal:

Start–>All Programs–>Accessories–>Communications—>HyperTerminal

If you’ve never used HyperTerminal answer it’s questions about your location. When the "Connection Description" dialog comes up give it any name you like (e.g. loopback). In the "Connect To" dialog change the "Connect using:"  drop down to COM# where COM# is the COM number you made note of above. Click OK.

In "Port Settings" change:

  • "Bits per second:" to 115200
  • "Data bits:" to 8
  • “Parity:" to None
  • "Stop bits:" to 1
  • "Flow control:" to None

Click OK. Press several keys on the keyboard. If they are displayed, then you have correctly identified the TxD and RxD line. If they are not displayed, you’ve done something wrong, reread and retrace your steps.

Using with the Arduino
Once you’ve tested your cable you can make it more permanent by adding crimp-on wire connectors with a 1×6 housing. Look at the instructions for the BBB in the links section to see how to arrange your wires the same way as an FTDI USB
cable.

Set up your breadboard with the ATmega chip and it’s supporting components. The Auto-reset input can be ignored and capacitor C1 can be left off. Do not hook up your USB cable just yet. For more examples on how to setup your breadboard see the Links section. You can use any of the ATmega chips supported by Arduino, but it absolutely MUST be pre-programmed with a boot loader. Several places sell chips with a boot loader; Modern Device Company seems to give you the best deal.

schematic 

Apply power to the breadboard. The LED should blink a couple times. If not you should recheck your setup.

Once you’ve got a working setup, you can try out your cable. Make sure the power is off and the cable is not plugged into the USB port. Hookup the TxD and RxD wires as shown in the schematic. Connect the cable’s GND wire to the breadboard’s GND bus. Plug in the cable, power on the device, and start the Arduino IDE. Under Tools–>Serial Port make sure your USB cable is selected; also make sure you’ve chosen the correct ATmega chip. On the toolbar click the up arrow (Open), go to Digital, and choose Blink. Now we’re ready to try uploading.

A downside of using this type of cable is that auto-reset is not available, so you’ll have to do a manual reset to upload. To do this press down and hold the reset button, click Upload, count off X seconds then release the reset button. If you’ve gotten the timing right, Arduino will say "Done uploading" and the LED will blink continuously. If you release the button too soon the boot loader will timeout before the program gets a chance to be uploaded and you will get an error. If you hold the button too long Arduino will eventually give up and report that the programmer is unavailable. I said "X seconds" above because the timing depends on how fast Arduino runs on your computer. Using a dual boot machine, in Debian I had to count off approximately 5 seconds and in Windows XP I counted only 3. You’ll have to use trial and error and a bit of patience to figure out the right X for you. Getting the timing right can be tricky because the bootloader only listens for a brief period of time.

Once you’ve got the correct timing for a manual reset, that’s it, you’re done. Congratulations, you’ve got a basic USB to Serial TTL cable. The next section explains how to make it a lot nicer.

Further Modifications (Optional)
Since these modifications depend heavily on the version of the PL-2303 used and the layout of it’s PCB, this section should not be considered a guide on how to modify your board but as a demonstration of how I modified my board.

Earlier in the article I mentioned that my cable had too extraneous wires. I hope you were so lucky as well, because one can be soldered to the USB VCC 5V pad which will allow you to provide USB power to your breadboard, and the other
can be soldered (indirectly) to the PL-2303HX’s DTR pin giving you auto-reset! The picture below shows the location of the USB VCC pad and a via that connects to pin 2 of the PL-2303HX (pin name DTR_N). Please note that the section showing the bottom of the board was vertically flipped in GIMP to give a sort of X-ray vision effect. That is, if the top section was overlaid on the bottom all the vias would line up. In reality, when I look at the bottom of the board it does not appear as such.

CA-42_board 

The casing around the USB connector is not a solid piece but a two part shell. It is easily removed by wedging a spudger (I used a guitar pick) into the seam and gently working the two pieces apart. The shell can also be put back together with little effort. The extraneous wires are colored red and green. I did not unsolder them for fear of breaking some unknown connection, rather I simply clipped them at their pads. There was not enough slack in the wires to reach the new solder points so I removed a section of the cable’s insulation below the strain relief and gently pulled a little slack into the case. (The cable’s foil had to be torn to pull the slack. This is not a big deal since the foil has no connections. You may want to look into connecting the foil to the USB connector’s shield; I didn’t bother.)

Then I soldered the red wire to the square pad to get USB 5V; followed by a quick test providing power to an LED from the cable. Et voila, it works! Unfortunately the cable reports itself as a low power device. This means the maximum current your circuits should draw is 100 mA minus the current required by your cables circuitry. The typical/max operating current required by the PL-2303HX is 20/25 mA. If you try to exceed 100 mA, bad things can happen. My computer limits the current and will not supply more than 100 mA to a normal circuit, though I did blow my meter’s 250 mA fuse when I shorted power and ground. Your computer may beep, reset or even smoke. A (resettable) fuse is highly recommended. See this page for a quick guide on how to check your USB device’s "Power Required" in Windows. In Linux, use "lsusb -v" and search for the "MaxPower" entry associated with your cable to get the same information. If you’ve found a cable that has a "Power Required" of 500 mA, please leave a comment on where you bought it.

Auto-reset works by connecting the DTR line to RESET through a capacitor and pulling it low thereby temporarily lowering RESET too. In the picture above you can see that the via just below the silk screened "C6" probably leads to the DTR pin. I did a quick probe to confirms this, then attempted to solder the green wire to the via. It was a bit of a headache. The picture is deceptive; things are much smaller than they appear! What ultimately worked for me was to fill the via with solder, tin the wire, then place the wire over the via and the iron directly on the wire. It’s not a great or even good joint, but auto-reset works nonetheless.

CA-42_mod

Level Translation Note
You may have noticed that the cable’s output level isn’t 5V; it’s 3.3V. So how does it work when the ATmega expects 5V? Well if you’ll look at the ATmega datasheet you’ll see that the minimum input high VIH is 0.6*VCC, which is 3V when VCC is 5V. So even though the cable puts out only 3.3V the ATmega still recognizes it as a high. Going the other way, the ATmega TxD pin puts out 5V which is possibly too high for the PL-2303 chip to receive without being damaged. This is why a voltage divider was put on the cables RxD line; 5V*(15/(10+15)) = 3V. For the PL-2303HX rev. A the voltage divider is not necessary because it’s RxD pin is 5V tolerant. Other chip versions may not be; Check their datasheets.

Request for Comments
Odds are that not all of you will get exactly the same cable that I did, so please share your unique experiences and insights in the comments section. They might help someone else out. Thanks for reading. Good luck!

Acknowledgements
I wish I could say the idea for this project was all my own but most of my inspiration came from Tim Small’s page

Tim Small also provided the picture with the phone connector’s pinout.

Links

Posted in Arduino, Development Tools, Discovering, Electronics Links, Hacks, Ideas, Microcontroller, Parts, Projects, Scrounging, Scrounging Parts, Workshop Tips.


7 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. daniel andrade says

    Another good deal is that you can buy one of this on DealExtreme for U$3. Good post anyway :D

  2. Jonathan Thomson says

    Daniel, I assume you’re talking about a USB to Serial RS-232 cable. RS-232 uses different levels than TTL so you can’t use one of those directly with a microcontroller. They can be used if you use inverters or a MAX232, but that is a more complicated setup. This article is about making a cheap replacement for the more expensive USB to Serial TTL cables. I try not to refer to it as a TTL cable in the article because it doesn’t put out true TTL levels, but it gets the job done with the added benefit that it can be used with systems that use 3.3V.

  3. Hmm says

    So what’s the minimum total cost for an Arduino setup based on this?

    What’s the cheapest someone can get started with them?

  4. Jonathan Thomson says

    It depends on what you already have and what you can beg from fellow hobbyists. I bought the CA-42 and the ATmega328, so my minimum was about $10. Here’s a BOM:

    Resistors $0.15
    22 pF capactiors $0.22
    0.1 uF capacitor $0.08
    16 MHz crystal $0.81
    6×6 mm pushbutton $0.15
    Red LED $0.05
    Crimp on wire connectors $0.10
    Crimp housing $0.10
    Resettable fuse $0.35
    ATmega328 (Modern Device) $5.50
    CA-42 $3.00
    Breadboard $4.00
    Hook up wire (3 colors) $3.00
    5V reg. power supply $5.00
    =====
    Total ~$21.00 (excludes shipping)

    This is only if you have absolutely nothing and have to buy everything. For someone that has none of this stuff, the Arduino board is not a bad deal. An electronics hobbyist will have most of these things already, so buying the Arduino board is much less appealing. Also consider the fact that hook up wire and a breadboard are still necessary even if you have the Arduino board. Don’t forget, microcontrollers are for interacting with the physical world. To do anything more interesting than blinking an LED you’ll need more components.

Continuing the Discussion

  1. DIY USB to Serial Cable For $3! | Gadget Look linked to this post on October 4, 2009

    […] Jonathan submitted as part of the uCHobby Giveaway project and has selected tRead more at http://www.uchobby.com/index.php/2009/10/04/diy-usb-to-serial-cable-for-3/ […]

  2. Tweets that mention DIY USB to Serial Cable For $3! | uC Hobby -- Topsy.com linked to this post on October 5, 2009

    […] This post was mentioned on Twitter by Wendell Evens. Wendell Evens said: DIY USB to Serial Cable For $3!: Jonathan Thomson submitted this useful article about converting a low cost cel.. http://bit.ly/3jz9p6 […]