DIY USB to Serial Cable For $3! February 21, 2010

Update
Several good, inexpensive, purpose-built USB to serial modules are now available on eBay for around five to six dollars. Just search for PL2303 or CP2102.

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 DealExtreme 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.

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 Prolific’s site.
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. To do this…

…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.

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 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-programed with a bootloader. Several places sell chips with a bootloader; Modern Device seems to give you the best deal.

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 bootloader 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.

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 enclosure. (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.

Quite sometime after I first wrote this guide I wired a 24L02 EEPROM to the PL2303HXA. I successfully wrote new device configuration registers settings to the EEPROM using this program. The device configuration registers allow you to change settings like the VID, PID, serial number, and maximum power required (i.e. max. current). I think only the PL2303HXA supports writing to an external EEPROM. Two hints that you have a PL2303HXA are the presence of a crystal and two 4.7k resistors.

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. If you have a chip with a 5V tolerant RxD pin you’ll get better performance if you leave out the voltage divider because of the inherent parasitics of the resistors.

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.

Came in through hackaday.
What a whining bunch they can be, huh?
Compliments from me aswell on a very good article.
Especially I’m glad to see such quality photos. Too often there are just a bunch of out of focus smears none of which demonstrate what is being shown.

Thanks. I took those with a Canon P&S, a Powershot A75. I’m always amazed at the good close up pictures it will take even with autofocus. I’ve found if I go to manual mode, use a small aperture, a longer exposure, and a small tripod, it’s easy to get nice in focus pictures of PCBs. Studying a picture on your computer beats the hell out of using the magnifer on a Helping Hands.

Hi,
I got here via hackaday too, although the comments say that this has been done before your article has introduced me (and doubtlessly others) to this technique and I think its a great tutorial.
Thanks,
Drew

How wonderful!
I picked up a RS232 IR receiver many years ago and used it to control my computer via virtually any remote. Since my DIY HTPC is lacking a RS232 Port my old Nokia cable is up for a little hack to (hopefully) revive the old IR-receiver… I just love using spare parts and constructing stuff for nearly no cash 🙂

Serial communication with RS232 is different from LVTTL. RS232 uses a negative voltage for a logical 1 and a positive voltage for a logical 0.
The Nokia cable uses 3.3 V for logical 1 and 0 V for a logical 0. The voltages are different and the logic is inverted.

IIRC, the web is covered with microcontroller IR receiver projects if you still want to use the Nokia cable.
I was planning on doing this for my mythbox, but didn’t have to when I got a nice remote from someone
with a Windows MCE PC that wasn’t using it.

These cables vary a good bit. Some people end up with 3 wire cables while others get 4 or 5 wire ones. There is really no way to tell what you’ll get. For serial TTL communication you really only need pins 6, 7 and 8. According to pinouts.ru pin 5 is USB Vbus, which I call VCC in the article. So it sounds like you already have 5V brought out to the end of your cable. Connect wires 5 and 8 to your multimeter and see if it shows 5V. Please post back with your results.

Looks like I get nothing through pin 5 and 8, so I left 5 unconnected and I tried bootloading Arduino with the tx rx and ground (I had to supply separate power to the arduino). It worked, but without auto-reset it is a little hard to press reset perfectly.

@ Victor March 14, 2010 at 7:22 pm
The newest bootloaders don’t listen very long for a program upload because they expect everyone has auto-reset. This means the chip runs the previously uploaded program faster but it also results in a bit of a headache for those that are doing a manual reset upload.

I think the manufactures buy these cable based on how cheap they are with little concern for how many wires they have. It’s funny that the red wire wasn’t even connected. It’s a bit of gift to you since you can use it for power or DTR.

My cable appears to have been constructed differently – see pics:
Outside of the blue layer (I had to use clippers to get it out), there was a black layer also. Both were physically moleded around the circuit board so I managed to break the wires.

The red wire was not connected to the PCB, only the other 3 were.

I can easily find out which of the 3 wires went to where, but how should I find the pinouts of the other pins?

According to the datasheet of the SSOP package, pin 1 is TX and pin 5 is RX, and those correspond to the pads on my board. So I guess the numberings is all the same.. and conveniently the DTR pad is on the bottom!

@ Victor March 15, 2010 at 2:23 am
The fact that the 3.3V via is connect to the pad labeled 10 confuses me a little, so I shouldn’t say for certain, but it looks like you have all the other serial lines brought out to nice big solder pads on the bottom of the board. Luck you! I think you can be fairly confident the pad labeled 2 is indeed DTR. Try it and see.

I have no idea how you can figure out if your RxD pin is 5V tolerant. You could try it and see, but you might smoke it.

Thanks for sharing your findings. It is absolutely crazy how varied these cables are.

Just an update on the pin 2 – it isn’t DTR, at least I don’t think it is. When attempting to program, the DTR pin does go low, but it stays low, keeping the Arduino in reset instead of actually resetting the Arduino. So looks like I will do manual resets for now!

Take another look at the schematic. Did you use a capacitor between the DTR line and the RESET pin? When DTR goes low the capacitor acts like a short circuit momentarily and therefore the RESET pin goes LOW. After a bit the capacitor charges bringing the RESET pin back up to HIGH.

It appears you put the (magical color changing) reset capacitor directly on the cable. Be aware that most setups put the reset capacitor on the board, so if you use your cable with one of these boards your total capacitance will be effectively halfed and it will hold the reset pin low half as long. This may or may not cause a timing problem when uploading.

To be absolutely correct it’s not an FTDI cable since it doesn’t have an FTDI chip. The PL2303 cables definitely get the job done though. I wish they could do bitbang.

Can you do me and all the future readers a favor and measure the maximum current you can draw? I explain how to do this in the article.

The $2.68 CA-42 I received on the 25th seems to be like Victor’s with four wires on pins 5 through 8. The red wire on pin 5 doesn’t seem to be connected to anything. The cable I received however seems to be defective (I get the “This device will not start. (Code 10)” message on both an XP-PRO SP3 laptop and on a Vista-Home laptop) so I guess I’m going to have to try again (argh!).

Serial communication with RS232 is different from LVTTL. RS232 uses a negative voltage for a logical 1 and a positive voltage for a logical 0.
The Nokia cable uses 3.3 V for logical 1 and 0 V for a logical 0. The voltages are different and the logic is inverted.

There is a eeprom attached to the PL-2303 that controls several things including VID, PID, Release No, Serial No, Flow Control, Shutdown / Wakeup and most importantly Current. Depending on the value in the eeprom, the chip will request either 100ma or 500ma.

Prolific used to have a PL-2303X EEPROM Writer program available as a download on their website that allowed you to change those values. A copy of it is available here:http://www.megaupload.com/?d=HMG9JNB9

I don’t have any CA-42’s at the moment to test this with (they are in the mail from Hong Kong) so if anyone else can try this, post your findings.

I looked into this, but my memory is a bit hazy on the details. IIRC you need a special USB board that puts out 6V to program the EEPROM in the rev. D, and it can only be programmed once. The rev. A has a 2-wire EEPROM interface though, and I think if you program an external EEPROM correctly you can tell the PL2303 to report itself as High Power device and therefore get 500 mA from the USB port. I keep meaning to try this but never have. If you get it to work, write back and let us know!

Stumbled upon this page while looking for info about updating the pl2303 (seems to be very little out there). Added a thread on edaboard – http://www.edaboard.com/thread186961.html explaining the problem and what I’ve tried, but seems you might know more.. Can you offer any help on this?

That does look like a good deal if you live in the UK. It appears to work out to around $19 after VAT but without shipping, which is a bit cheaper than the $20 most places charge. It’s even nicer if you consider that eletronics hobbists not residing in the US usually have to pay a premium for components.

I (un/re/un)installed probably 4-5 other drivers before I came across this one. Worked like a charm – the cable was instantly recognized as a serial port, and came up in device manager without the pesky yellow exclamation mark. (and the attendant “will not start” error)

I already have one of the modern device BUB programmers, and it works a charm. However, the extra serial cable (got my ca-42 off ebay for $3ish) is proving to be very handy while trying to diagnose getting a pair of wireless ‘duinos to talk to each other.

my ca-42 knockoff had:
and epoxy blob covering the chip
3 wires
the pads were actually *labelled* – rx, tx, gnd, vcc, and rst…so that made it easy.
A bunch of weird solder jumpering (tx and gnd were solder jumpered…rst and vcc were blobbed together I think…some other stuff)

Initially I followed the advice to swap the rx/tx with the connector’s ports…that didn’t work. Guess the pads were labelled intending to actually go to the mcu.

I had a 6 conductor wire (cat5 8 conductor would have worked too) that I used. Along with 2 superglued-together 3-conductor female connectors as I didn’t have a 6 handy.

interestingly, my reset/reprogram performance seems to be a bit dodgy so I’m guessing I need to add the reset capacitor someone mentioned in a post above.

Hey Aaron, I have the same Win 7 64bit driver problem, but it seems that the link to the driver you found doesn’t work anymore. Any chance you could send the driver to me or post it somewhere? I would really appreciate it.

Jethomson.. excellent tutorial and you are the man of YEAR… You saved me lot of bucks…. Unfortunately i have no good experience with cheap chinese DKU-5 but i have found CA-45 cable the best for me… It has only three wires.. The one i have RED=GND the BLACK=TX and the WHITE=RX…

Hi Jethomson,
I open the third party Hyperterminal in window7 and joined the Tx/Rx wires and typed in the window..whatever i typed written on terminal window so diagnostic test was right…
i got another problem..when i attached the Rx and Tx pins as per your scheme to my Arduino (DIY) ATMEGA 328P chip as you mentioned.. The device manager recognised the device, Hyperterminal recognised the device as COM1, Arduino IDE also recognised the device…
Hyperterminal window could not open the COM1, i changed the settings from COm1 to COM10 in device manager but hyperterminal recognised the port but can’t open the COMx…

What may be the wrong?…Again i posted all the pictures in above provided link..as i can’t upload here…

Hi thomson,
Thanks for the reply… Actually i have programmed the ATMEGA328P to get the serial data already.. for example typing M (sending to Arduino) will move the steppermotor 1step..The same way typing ‘S’ will start the laser scanning process and typing ‘T’ will off the laser, move the motor to original position and stop.

Currently the problem is i am getting garbage values in the serial communication as described above… sending 10xM to arduino, the result is few M display on LCD and other become garbage characters… why?

I read the thread and it appears you discovered the problem was caused by a USB extension cable. The 1k resistor on the Rx pin is for limiting the current through the input protection diode if the Tx line exceeds 5V. The 10k and 15k resistors on the Tx pin form a voltage divider to reduce the 5V output to 3.3V because the cable is 3.3V TTL. My cable works without the 15k resistor because the cable’s USB to serial TTL chip is 5V tolerant.

In your last post you said “This project abandoned till the cheap alternative available”. I’m not sure what you mean by that, but if you are quitting because you can’t get a DKU-5 cable from ebay, try dealextreme.com

Hi Thomson,
Thanks for the reply..i almost forgot your this thread and today i tried to check here…
Thanks for the informations… I will replace the ATMEGA328P with new one, i think its Tx or Rx pins are damaged as i found the problem in my original Arduino board too from which i programmed that chip..

My cable had ground txd and rxd cables only. And there another cable that was useless. My setup was Black = GND Green = TXD White = RXD. In my case my RXD line had less than a volt going to the multimeter (or a bad connection). Originally I thought the RXD line was a dud but the loopback test proved me wrong 🙂

[…] (EEPROM Writer link on that post is nolonger working however there is a copy at Megaupload via Jonathan Thomson’s Web Journal). I was however unable to get it to recognise the cable and looking on EDA Board appears a special […]

Thanks for the great guide. I have managed to get the info from my device (boot), but cannot seem to be able to write to it (terminals won’t allow me to type anything). I have tried flow control settings, but doesn’t seem to be the issue. Any ideas?

[…] signal levels (3.3V) and not RS-232 (somewhere around 15V). Just as I was considering cutting up a USB phone cable, I realised that I had a full-blown Linux system with a handily accessible serial port that runs at […]

[…] it in the uCHobby blog and decided to do my little take on it (I think the original post is from Jonathan Thomson's blog. Check out his blog too, he posts some cool stuff). The first thing you have to do is go to […]