Having a serial port on any Linux box is always useful, but with the tiny computers we’re carrying around in our pockets now, that isn’t always an option. Some of the more advanced phones out there break out a UART on their USB OTG port, but the designers of the Nexus 4 decided to do things differently. They chose to put the Nexus 4’s serial port on the mic and headphone input, and [Ryan] and [Josh] figured out how to access this port.
Basically, the Nexus 4 has a tiny bit of circuitry attached to the microphone input. If the Nexus detects more than 2.8 Volts on the mic, it switches over to a hardware UART, allowing everything from an Arduino to an old dumb terminal to access the port.
The guys used a USB to serial FTDI board wired up to a 3.5 mm jack with a few resistors to enable the hardware UART on their phone. With a small enclosure, they had a reasonably inexpensive way to enable a hardware serial port on a mobile device with GPS, cellular, a camera, and a whole bunch of other sensors that any portable project would love.
EDIT: An anonymous little bird told us this: “You should add a note to the Nexus 4 serial cable post that TX and RX need to be 1.8V. If you use 3.3V USB cables, you will likely eventually fry something. FTDI makes 1.8V IO cables that work – you just need to make the trigger voltage for the mic line.” Take that for what you will.
Double Plus Good!
But how did they “know” the earphone jack was also a UART?
The code helped, as did some circuit tracing. We didn’t document the steps very well along the way so they’re omitted in the blog. We learned our lesson for next time though.
Might want to take a look here:
http://blog.ruecker.fi/2013/04/29/there-is-an-uart-on-the-nexus-4/
Also note that the UART seems to use 3V reference voltage, not 3.3 and neither 1.8V.
I don’t understand why the 1K resistor on the MIC-IN line?
And is the trigger voltage 2.8V or 3.08V? They state 2.8V in the summary but derive 3.08V in their calculations.
The 1K resistor serves two purposes. The first is if you connect it to a device that shorts Vcc out to ground it prevents the FTDI chip from resetting. The second is if you plug it into the wrong device it makes it less likely that it will destroy the device. With the voltage calculation, 3.08V is the correct number.
i am curious if the nexus7 has a similar thing too ? (different manufacturer though, asus versus LG)
The Nexus 7 DOES have a similar feature, it is confirmed by both the schematic and the kernel, however I have not been able to get it to work.
So could i make my android(assuming my android has this ability) a serial terminal? would be nice in the datacenter to do this…
You might need a level converter like the MAX232 in order to shift the levels from 3.3V to the 12V serial standard, but it’s definitely doable.
Voltage levels are only required to be +- 3V, but are often driven with higher voltages like 15V as they were convenient in many cases from the times that 232 was in it’s heyday. It also potentially provides faster slew rates and increases noise margins.
http://www.radio-electronics.com/info/telecommunications_networks/rs232/signals-voltages-levels.php
or pickup a bluetooth module from dx.com . They are quite cheap and seems reliable
You can use an CP2102 or FT232 via usb host in most cases so you don’t need this for a terminal..
Cool, I have a nexus 4. This might come in handy when the screen cracks and I decide to get a new phone ;)
After reading this article and blog, I did a Google on Nexus 4 and a review complained about the screen and back plate (also glass) easily breaking, Your Mileage May Vary…
I’ve had my Nexus 4 since early December and I haven’t had any problems with either the screen nor the back cover.
There, you have two antidodal data points which mean nothing.
Headphone UART is a requirement for any Google flagship Android Product.
This means any Nexus has this feature.
I haven’t checked Nexus 4, but this is documented quite well in the Nexus 7 kernel code. No special circuitry there though – just standard SoC pinmuxing. Most of the time it’s pinmuxed to ‘nothing, and when it detects a special condition (if enabled), it pinmuxes the UART onto the pins and the audio off.
My Samsung Galaxy can tell when the headphones are plugged in or not, when you unplug them it quits the FM radio. So there’s some smarts in there. It might just be detecting a signal from the headphones’ other purpose, an FM radio antenna, or maybe it’s quite a sophisticated jack socket.
I wonder what you get from it? Boot debug data? A root shell?
my kindle fire hd does the same, if you unplug the headphones, it will pause, almost all apps do that
The vast majority of Android devices does this by default…
Dmesg log and a shell (that probably can’t sudo)
Can this be used to bypass security on the phone? What exactly is enabled on the stock nexus 4 end?
By default it’s just debug output from the kernel, no real security implications that are immediately apparent.
any idea what levels are on this kind of UART? Is this TTL or a real RS232 levels?
Well, according to the article, it uses 3V for HIGH and GND for LOW.
any body tested this?
well,… i created the circuit and no luck,…
my nexus restarted couple of times as soon as i plug the headphone jack , computer showed lot of clutter and finally nexus went in to continuous boot loop
i had to re-flash factory image,.. lost every thing :(
^^^ Note: Back up first next time.