Thursday, September 8, 2011

Using a CP2102 on Arduino

I recently bought a cheap USB to TTL adapter from Hong Kong on eBay. USB to TTL is needed to program Arduinos without an on-board usb chip like the LilyPad or clones like the Diavolino (my favorite).
Sadly, it doesn't work out-of-the-box on OS X and most likely on other systems too.

Connections

Most connections are straightforward:
  • GND to GND
  • RXD to RX
  • TXD to TX
  • 3.3V or 5V to VCC.

The Problem with the Reset Pin

The autoreset feature which resets the Arduino right before the program gets uploaded from the IDE doesn't work. In order to upload a program, you have to press the reset button on the Arduino right when the upload starts.
The more widespread USB TTL cable from FTDI Chip does this automatically.

The Solution

The dongle from eBay features a reset pin, but connecting it to the reset pin on Arduino doesn't do anything. It turned out that this pin resets the CP2102 and doesn't carries the reset signal from the Arduino IDE.
The CP2102 exports the signal on the DTR line. There is no male pin for it, just a soldering pad on the board. Simply solder a male pin to the DTR line and connect it to the reset pin of the Arduino.
You can find pictures of it after this post.

Driver

Don't forget to install the Driver

Pictures

17 comments:

Anonymous said...

It doesn't works form me on a breadboard "Arduino". :(
The error message is:
"avrdude: stk500_getsync(): not in sync resp=0x00"
The same error with the following boards selected int program:
UNO, Nano, Mini Pro, LilyPad etc.

Cat the reason be the optiboot bootloader (for UNO)?

Anonymous said...

I might be wrong on this, but I don't think that the UNO use the same serial interface as this one is replacing (FT232).

As far as I understand, it would work with the other bootloaders.

But might just I say it one more time... This is just my understanding of it.

DW

Anonymous said...

Uno does have a new interface but it doesnt make any difference, it should work just the same at the MCU side.

I grabbed 3 of these as they were cheap on eBay and had a hard time finding a driver for Windows. I got them to work with a generic driver in the end but never got them to communicate with an AVR.

Ironically they worked perfectly in Ubuntu and Mint, but wouldnt program a chip, just communicate right up to 115200baud.

Soldering on the DTR fix solved the problem and it now happily programs Atmels and PICs as well. I cut the RST track and ran a small bit of wire from the DTR pad to the pin to preserve the interface for a breadboard.

Cheers!
Hexhammer

Anonymous said...

Update

It appears to be a bit of a lottery, this does not work on all my machines.

It may be something to do with Hardware Flow Control and depend upon the port hardware - it doesnt work on 2 laptops and does on one desktop but none of the others. I do know that laptops in particular do not adhere to the original RS232 protocol for COM ports and it might be that DTR isnt handled the same for virtual COM ports too.

The laptops only send the DTR after the Arduino software has failed, where the desktop that works sends the DTR immediately, resets the Arduino and uploads the code correctly.

I hope this helps someone, it took me a while to figure out what was going on.

Hexhammer

soynerdito soynerdito said...

Currently I am having the same situation. Tried to manually push the cable on the DTR signal without success. However did one more test (because i did not wanted to solder if not totally required). I wired the reset pin from my Arduino uno board into the Atmega328 on a breadboard (the one i want to actually program). Also connected the ground from the Arduino UNO boar into my breadboard. And connected RX,TX, GND, VCC as described here. Then when clicked on the download from my arduino IDE I manually push the reset button on the board and all went smootly. I was able to program my chip without problem.
Now I will go on and find a pin to solder and hopefully get a nicer solution.
Thanks for the post!!! I will try to post again results.

soynerdito soynerdito said...

Update:
Solder pin and no bacon. Did not worked for me. Else where somebody mention about a capacitor in between, but I have not tried. With manual reset works but not automatically (in my case). I use ubuntu 11. something. With Arduino 1.0 and avr 5. something compiled in laptop.

Anonymous said...

Yes, you need cap inbetween DTR line - 100nF should do, w/o cap my arduino stays at RESET state and doesnt work... with cap works great! :)

Deskwizard said...

I confirm the cap method works great ! :) Soldering one on my CP2102's as we speak!!

Anonymous said...

I get it to work randomly maybe one out of 5 times, with the cap; resistor to VCC seems to help (order of kiloohm).
I am interested in transfer rates higher than 115200 Baud, but I am only getting garbage. Two CP2102's connected as USB>Serial>USB work just fine up to 921600. Atmega328 serial to CP2102 works only up to 115200.

Anonymous said...

Solution for higher data rates: use 14.74MHz crystal instead of 16MHz.

Ben (Lenny) Wells said...

The 100nf cap method worked a treat. Thank you to those who suggested it and confirmed it.

Marco said...

Great post!

I repeatedly got the avrdude not in sync error. Turned out on my Arduino Pro Mini the rx and tx were reversed! So instead of crossing them (rx->tx and tx->rx), I had to connect them strait (rx->rx, tx->tx). Not sure if my programmer or the Arduino has them reversed, but you might give it a try.

raver2046 said...

damn, for me it doesn't work with or without the cap (104).
Soldered the DTR pin to the cap and the cap connected to reset arduino uno pin.

Any clue ?

Renoir said...

Nice work. I set the programmer to 'AVR ISP' (not the mkII) ond got this working with the manual reset button method. Getting my soldering kit tomorrow to try the DTR line

Anonymous said...

thanks a lot guys. installed drivers, used capacitor and magic! everything works just fine.

dalmir da silva said...

For those who are having problems with baud rate higher than 115200: http://bb.osmocom.org/trac/wiki/Hardware/CP210xTutorial

dalmir da silva said...

BTW: worth mentioning I haven't tested this reprogramming approach.

Post a Comment