Giving the Nexus 4 a serial port

nexus

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.

27 thoughts on “Giving the Nexus 4 a serial port

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

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

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

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

  2. So could i make my android(assuming my android has this ability) a serial terminal? would be nice in the datacenter to do this…

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

  3. Cool, I have a nexus 4. This might come in handy when the screen cracks and I decide to get a new phone ;)

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

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

  4. Headphone UART is a requirement for any Google flagship Android Product.

    This means any Nexus has this feature.

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

    1. 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?

    1. By default it’s just debug output from the kernel, no real security implications that are immediately apparent.

  6. 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 :(

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s