Instructables

Android G1 Serial to USB Cable

Learn how to make an Android G1 2.8v serial to USB Serial device adapter (using a 3.3v ttl to usb serial adapter). This can be used for kernel debugging/etc with your computer. This project shouldn't cost you more than 40 bucks if you already have basic electronic tools such as a soldering iron.

Notice: The ability to use 3.3v ttl level serial is based off of google group discussions and a picture of a serial cable used by an alleged android dev. 2.8v level serial was determined via someone using a voltmeter. Build/use at your own risk and check the comments of this instructable too before beginning!

Information may be applied to build a 2.8v serial to RS232 converter to interact with RS232 devices, or a 2.8v serial to serial 5v level converter to interact with microcontroller such as an Arduino. I may post instructables on how to make these once I play around with the G1 kernel some more. :)

This tutorial assumes basic knowledge of soldering. If you don't have this skill you should find an instructable regarding it and practice a bit. The soldering required for this project isn't difficult, but needs to be done in a small amount of space which could be difficult for beginners.

This cable was created based off of information received from the Android-Platform Google Group.

... Specifically these two threads:
http://groups.google.com/group/android-platform/browse_thread/thread/f03730e25cc3fe55?fwc=1
http://groups.google.com/group/android-platform/browse_thread/thread/439d3f3af7a88a09/10a80eb835e8dbcc?lnk=gst&q=serial#10a80eb835e8dbcc

...This picture of a "mystical" g1 serial cable helped (and confused!) too:
https://www.noisebridge.net/wiki/Image:G1-two-usb-to-serial-cable.jpg

Please leave constructive criticism/comments if you find any steps wrong, confusing... or poorly written!
 
Remove these adsRemove these ads by Signing Up
1-40 of 58Next »

good

crowg1 year ago
I have a Droid Bionic - anyone want to build one of these for? (with instructions on how to install driver, etc)
mrzono2 years ago
Thanks for great instructable.
I tried that I connected G1 with Cisco console.

Android (T-Mobile G1) -> Serisl Port API -> TTL -> RS232C -> Cisco console

(my scene)
http://youtu.be/t4EuB8qhTvA
godamlaa3 years ago
Hi all,

I've connected mine G1 to the PC via FTDI Basic Breakout (http://www.dfrobot.com/index.php?route=product/product&path=45&product_id=147) and managed to get full output from 'ps. However, it seem that G1 could not received my input from the keyboard most of the times.

I need to repeatly hit the keyboard to get the terminal emulator to echo it back!

Did anyone experienced it? Any tips will be helpful. Thanks
Thanks very much for the tutorial! I would like to know whether I can use this from a program on my g1, say, if i were to develop a program that could say to a picchip "SEND ME" then it could write back the values of its inputs etc. then the program could do something with them. would I have to use NDK? or does the SDK have some kind of serial control command?
macpoddotnet (author)  jamescorbett4 years ago
  Yep, this allows 2-way communication via the serial protocol with a pic/avr/arduino, etc. That's actually my main reason for making this cable.

To do this you need to configure and rebuild the kernel to disable the serial debugger and htc handset detection drivers. Consequently after doing this, you probably won't be able to use your headset. This requires you to have a rooted phone too, preferably with the dev spi.

There's no android application level serial communication sdk stuff yet.. (Porting rxtx to android is on a todo list of mine) so you will need to compile a c app (search google for agcc.pl to learn how to compile c apps for android) in order to either use as a middle man between android apps and your uC.. or just to configure the serial port initially to whatever baud rate, stop bits, etc you need then interface with /dev/ttyMSM2 directly
Hey not sure you still interested but I just ported the RXTX library ( gnu.io.rxtx) to the android. More details here http://v-lad.org/projects/gnu.io.android/
Hmm, Cepr could you send me/post the code your using so that I can have a stab at it, and macpoddotnet are your steps nessery because I have a routed device so shouldn't I just be able to talk to /dev/ttyMSM2 using just command line (I will try this soon) because at the moment I'm testing using my actual phone I use on a day to day basis but I will buy a dedicated one I can break things like headsets and it doesn't matter.
Hi jamescorbett,<br /><br />I just created a Google Code project to host the code:<br />http://code.google.com/p/android-serialport-api/<br /><br />I will complete the wiki with compilation instructions soon.<br />
cepr cepr4 years ago
My application is now stable, I uploaded an apk in the download section.
SerialPort_0.7.apk features:
- detect all the serial ports of the phone (most are internal, do not use)
- select baudrate (4800, 9600, 115200)
- detect missing file permissions, and try to change it with "su" (does not work on all phones)
- terminal screen to receive and send text through the serial port
- "loopback test": the phone sends infinite 0x55555..., and display the count of received and sent bytes. If you connect RX and TX, you should have the same value.


macpoddotnet (author)  cepr4 years ago
Great work! When I get home I'll check it out then throw a link up in this instructable.

Hmm, the NDK has me really excited now.. it has made some other things I have wanted to do way easier now.
macpoddotnet (author)  jamescorbett4 years ago
 If you are satisfied with the default baud rate you set in your kernel config before building it, you don't need to route applications through a c serial program.. or even make one to set the baud rate.

All you have to do is get the right permissions and talk to /dev/ttyMSM2 just like you would with any other linux serial port.

The NDK stuff wasn't around when I played with this, but this might even offer a better solution provided you have privileges. If you can include serial libs, you could control the baud rate directly from an app which would be awesome. This would be really useful for porting the rx/tx java libs too... hmm


The config entries that should be disabled have changed since I first did this, but currently these should be it:
CONFIG_HTC_HEADSET
CONFIG_MSM_SERIAL_DEBUGGER
CONFIG_MSM_SERIAL_DEBUGGER_CONSOLE


... possibly this too:
CONFIG_MSM_FIQ_SUPPORT
Thank you!
I have now ttyMSM2 :D
(it works also with CONFIG_MSM_FIQ_SUPPORT=y)
I made an Android program to read/write to a Linux serial port.
It uses the SDK and a little the NDK.
Anyway, you need a rooted device because the /dev/tty* do not have the read/write permissions for Android applications.

Chowmix123 years ago
For the newer generations of android electronics (phones and tablets) They come with USB host already built in> Could i use the same programing cable for my arduino to connect to an android tablet? If i did, what app would i need to accomplish a serial port to the arduino?

Chow.
Thanks heaps for this instructable. After heaps of mucking around I managed to get the HTC Magic working with it using the stock headset (I cut it up).

Few pointers for those interested:
Headset cable already has the USB GND pin connected to what becomes the TX pin... obviously this won't work so I just hacked out all the normal usb pins (which solved the issue).

I've recompiled the 2.6.29-donut kernel and confirmed this works.

One issue though... when I use a custom kernel I cannot use it in normal USB mode :-(. Is this normal? Should you be able to use normal USB and this special serial mode at the same time?
garrows4 years ago
I have now confirmed that Pin 4 is the data high pin and I have achieved 2 way communication.

http://garr.me/?p=315

Instructable coming soon.
garrows4 years ago
Hey great work although I have noticed one thing that could be wrong.

Pin 4 is actually 2.8v or Data High which is required for some 2 way logic level converters.

Be warned, I haven't checked if it changes during data transmission. I will post my results when I get up to that stage.
mjveyette4 years ago
 Would this work?
www.ecrater.com/product.php
The best way for me to see the phone sending commands to the PC was to type the following:

$ su
# echo 'hello' > /dev/ttyMSM2

It is also helpful to type 'ash' in so that you can recall commands:

$ su
# ash
/ # echo 'hello' > /dev/ttyMSM2

Then you can use ALT+trackball-up to recall previous commands.
Dude,

  how to dump the data on PC side ? tks
 I had PuTTY open as a serial client on the PC. Other serial apps should work too but I've had issue with the built-in Hyperterminal so I prefer PuTTY.
thanks dude!!! any tip for linux (ubuntu) env ?
minicom or
screen /dev/ttyUSB0 (or whatever)
sparkyuiop4 years ago
Tried to upload but it won't work for me. What does 'Drag to Recorder' mean?
sparkyuiop4 years ago
Hi I am looking for some help with a USB to Serial device I bought from Maplin that I slightly damaged when breaking apart the sealed casing. I have damaged 2 resistors (I believe) and completely lost one.
Can any of you clever bods suggest a fix for me please? I have lots of spare components but no clue as to what they should be.
I have included some Pictures.
Thanks alot.
Sparkyuiop!
leshii4 years ago
Thanks for the great Guide. 
For those of us in the UK this seems to be the same board as the one used in the Guide 
www.coolcomponents.co.uk/catalog/product_info.php
:-)

Has anyone been able to read incoming serial data on the G1?

I've tried using "cat /dev/ttyMSM2" and it just hangs, as does doing file reads of that using Python from the Android Scripting Environment.
Step 5 mentions 115200bps but that wasn't working for the Sparkfun CP2102 device. I used 9600bps and it then worked like a charm.
I just found out accidentally that a normal miniUSB connector works just fine with the extUSB port on the G1 for normal data transfer from PC as well as charging from PC. Does this open up any new possibilities? As for me, I would like to have some way to have consistent serial I/O between the G1 and an arduino. At least, one way to output accelerometer/Gps/compass data from G1 to the arduino itself would be a great thing.
macpoddotnet (author)  thomasantony4 years ago
No, it doesn't. ExtUSB = extended USB, so the only thing using a miniUSB connector will do is restrict what pins are made acessible on the phone.<br /><br />
Hmm.. ok I did frequently corrupt my microSD card while trying to add files via the miniUSB cable.
macpoddotnet (author)  thomasantony4 years ago
Using a miniUSB cable as opposed to an ExtUSB cable does not increase your risk of corrupt files. I'm guessing you are forgetting to eject the the volume before pulling the cable. If you don't do this, especially under an awful OS like Windows, your files will become corrupted.
Hey I know I have to "Safely remove" it. :) .. And I like windows :) .. Samething would happen on *nix if you didn't "Eject" the drive and maybe some buffer wasn't flushed.

Anyway, its like, when I used the miniUSB, the "USB cable connected notification kept coming on and off. Sometimes it kept getting disconnected after I had mounted the card and all. I guess it must have been something wrong with the cable.
If you use a USB cable that has a ferrite RF choke on it you shouldn't have problems.

I think electrical interference could be at fault for the data corruption and the cable disconnect/connect notification toggling.
pioioip4 years ago
Thank you for this instructable and the api.  Following these instructions I cut up the the headset that came with my g1 and connected it a usb->ttl and it seems to be half working.  I made a modified cyanogen kernel and installed the SerialPort.apk but when I run the app I receive data on the g1 nothing seems to be going out.  I wonder if you have come across this.  I have noticed that the little headset icon is always present whereas before I disabled it in the kernel it only appeared when something was plugged into the usb port.  Could this be related?
pioioip pioioip4 years ago
The first time around I had installed the kernel from the google code page but it had the headset detection enabled in the config and I wasn't getting any serial communication.  I used the instructions on the site for compiling the kernel and that gave me the serial reception.  The wiring seems to be solid.  I am wondering if headset vs serial state is somehow persistent?  I'll try installing your kernel again later.  Thanks for the responses.
macpoddotnet (author)  pioioip4 years ago
 No, it shouldn't be persistent. I am also 100% confident that the two kernels I uploaded sofar let you do serial communications with cyanogenMod 4.1.999 because they were tested and confirmed to work by myself and two others. The firsk kernel did have the camera functionality related problem however.. That is why the second one was uploaded (and tested).

Have you tried outputting /dev/urandom to /dev/ttyMSM2 then attaching a buzzer between the G1's TX0 and ground?

Oh yea, cepr's comment earlier holds a good point. Headsets short a pin to ground on the g1 to allow the phone to identify that they are attached. If that pin happened to be the TX0 pin, that could cause problems. Off the top of my head I am not sure that it is though... I think grounding the audio ground to the chassis ground does the trick. 
Hi again.  I tried your kernel again as well the two in the cyanogen repo to no avail.  The cm kernels with the headset detection disabled allowed me to receive serial but nothing went out.  I think that connector is grounding a pin and I destroyed it looking for it.  Does the headset detection matter?  If I get one of those little connectors they have on sparfun I should be fine with your kernel right?  Thanks again.
macpoddotnet (author)  pioioip4 years ago
A recent cyanogen kernel commit which contained some code that messed with the camera and possibly more might be the culprit. At the very least I know it constantly displayed the headset icon. That code has since been pulled from the repo.

I built and tested a new kernel for cyanogen mod which you can grab from the downloads section of the google code serial api website. Try that!
 
I definitly think you need to install the new kernel, but I also think you have a second problem, and that is likely wiring (double check that everything is connected fine)
1-40 of 58Next »