Tuesday, October 26, 2010

iPhone serial port

A while back I found out that iPhones, iPods and the like have a serial port in the bottom. A company called RedPark announced one back in February but it never eventuated, and when I contacted them in August, the last the guy had heard was that Apple had said no. So, I set about seeing if I could make my own plug-in module.

After a bit of research and the wonderful pinouts.ru, I discovered that the iPhone serial port is in fact a TTL device - super low voltage. I looked at what I'd need for the dock connector too, and quickly realised that I'd have to be a LOT better at soldering than I am. Not wanting to spend time learning, instead I bought a breakout board. I'd been meaning to buy one of these for a long time for the purposes of building a line-in from a mixing desk, but eventually bought one for this project. Later I'm going to hook up some of the other pinouts on the thing, but that's for later - check them out.

Step 1: The breakout board



This particular dock connector breakout cost $35USD because it was fully labelled, but you can buy cheaper ones. They also get cheaper if you don't want them pre-soldered.

Step 2: Power


The voltages in regular RS232 serial would fry a TTL port quick smart, so I needed something to convert between the two.  Maxim makes a chip called a MAX3232 that will do the job.  You can buy one of these pre-soldered to a DB9 connector and PCB, or you can buy the raw chip and wire it up yourself.  The raw chip is cheaper but again, more work.  You'll need five 0.1uF capacitors and the knowledge of how to wire them up.  This information is pretty readily available, but the datasheet for the MAX3232 is confusing, so here's a schematic on what this raw wiring should look like.  There are plenty of prebuilt ones on eBay, but they all have female DB9s, so I had to make up a custom headshell.

The MAX3232 runs on 3.3v, which is convenient because the iPhone has a 3.3v power output in the dock connector.  It's really got everything in there.  Connect to Pin 18 for Vcc and Pin 1 for ground, and your chip should power up.

Kernel hackers be warned: the 3.3v isn't available until the phone is finished booting.  If you want to watch the boot process and interfere with it, you'll need to provide external 3.3v power.

Step 3. Wire it up


Now, this part got confusing because Cisco devices don't use standard RJ45 serial pins for communication, and all of these devices are labelled vaguely as to which direction the RX and TX are relative to. Pin 12 is the PHONE's TX. Pin 13 is the PHONE'S RX. Connect Pin 12 to the TX-IN on the TTL converter, and Pin 13 to the RX-IN. This saves you 30 minutes of pain right there. While you would assume that the converter labels its RX/TX relative to itself, this assumption is pain-in-the-ass-fully wrong.
You'll also need to connect a 470kohm resistor between pin 1 (GND) and 21 (Accessory detect) to enable the UART.

Now grab a male DB9 head, and a rollover cable. Cut the head off the rollover, then solder it to the DB9. Wire Pin 3 of the RJ45 to Pin 2 of the DB9, Pin 6 of the RJ45 to pin 3 of the DB9, and Pins 4 and 5 of the RJ45 to Pin 5 of the DB9. Of course, this isn't necessary if you bought the correct gender DB9 in the first place, and you should just wire them up normally straight off the chip, then plug your regular rollover cable into it.

It's also super easy to make this an RJ45 port as this was earlier in the prototype process by doing the same in reverse with an RJ45 socket instead of the DB9. Again, Cisco rollover console is Pin 3 TX, Pin 6 RX, and Pins 4 & 5 are Ground.

Again, the schematic is here.

Now that all this is wired up, you probably want to put it in a case to protect it. I got a basic project case for $5 from Jaycar.



Step 4: Success

  

Jailbreak your iPhone, Install Terminal, OpenSSH server and Minicom.  Change the root password using the passwd command (assuming your iOS is a version in which passwd works) before enabling the SSH server. The default password is alpine, and it's commonly known, so you really need to change it.

Once you've installed minicom, open up your terminal or SSH in, start minicom and change the settings - same as you would on a linux box.  The device is /dev/tty.iap, speed 9600 8N1, no hardware or software flow control.  Remove all the device initialisation, dialling and hangup strings, and save the new configuration as something, preferrably cisco.  Save and exit.

Restart minicom with your new config by typing 'minicom cisco' and you're done.  The real benefit in all of this is that there are so many console packages for iPhone in Cydia now that you can have a fully functional computer, as useful as a linux box, but without carrying around a laptop.  SSH into it from a windows machine on-site or via an iPad and you're set.  3G iPhones with smashed screens are cheap, you can just leave one in your bag with the serial port, and you never have to worry about being locked out of a device.

There you have it!  iPhone serial port for consoling into switches/routers/allthingsnetworkrelated.  All parts were acquired from eBayRidax and Jaycar.  By the time I bought everything it probably cost around $80, but you can probably build it cheaper.

FAQ:
1. No, I won't build you one.  I was going to set up a manufacturing run but it turns out I'm a network engineer not a phone salesman and have little interest in such things.

2. You DO need to jailbreak your phone to do this.  You can't access the iPhone serial port without jailbreaking.

3. That crap all over the screen is actually dead pixels.  The glass itself is undamaged but the phone took a particularly hard beating, rattling around inside the pouch on my bike after it escaped its pocket and bounced around with screwdrivers and tools for 10km.

4. I'm not an electrical engineer, so I probably can't help you if you're having problems with your own attempt.  I'll give it a shot though.

5. I am however a network engineer, so I can fix your network or set you up with a commercial out-of-band management solution if you want to be able to remote serial console into your equipment.  Book it in through www.ionetworks.com.au/contact-us and I'll get back to you as soon as possible.

28 comments:

  1. You can use a MAX233 which needs only 1 external capacitor.

    ReplyDelete
  2. Do all iPhones have the serial port there? Or only the original?

    ReplyDelete
  3. m2pc: does that still run on 3.3v? Sounds like a good idea to simplify.

    cullen: all iPhones, iPads and iPod touches! Plus older iPod models but they're obviously less useful for this application.

    Ashnod: ok! Will let you know.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. The MAX233 is +5V only. You can do a parametric search (voltage, # ext. caps, # drivers etc..) here: http://para.maxim-ic.com/en/search.mvp?fam=rs232&tree=master

    However, finding stock of your selected part in small volumes can be a problem sometimes.

    ReplyDelete
  6. I am interested in one of these.

    ReplyDelete
  7. I will definatly take one of these!

    ReplyDelete
  8. I'm interested as well. For ham radio applications.

    ReplyDelete
  9. Hi, i'm interested in one of these, i'd like to connect my arduino to an ipod touch. :)

    ReplyDelete
  10. Thanks for the many clues! It answers many questions. Unfortunately, I don't want to jailbreak my ipad, but I hold out hope that one of the legitimate (App Store) terminal/ssh apps will one day be able to access the serial port (or finally use data devices via BlueTooth!). By the time that happens, I'll be ready! :-)

    Two for me, please. :-)

    http://www.conserver.com/consoles/
    http://www.conserver.com/consoles/BlueConsole/

    ReplyDelete
  11. I would very much like to get one of these as well. Brilliant work sir.

    ReplyDelete
  12. check out https://www.kickstarter.com they offer a very clever way to go about starting up a product by soliciting for backers online. I jut backed an ipad project called PadPivot and would gladly sign on for this as well.

    cheers

    ReplyDelete
  13. Good job in making that. :)
    But for the lamens, I bought the Flex Serial Cable.

    Refer to this post
    http://routing-bits.com/2011/01/03/console-to-routers-using-the-ipad/

    Keep up the good posts.

    ReplyDelete
  14. So you basically connect the rx and tx of both devices and convert the female DB9 to a RJ45?

    I see high potential in this project!

    Maybe its possible to mod the Sync-Cable so that you dont have to use this bulky breakout card...

    I think Im going to make my own version of this and post results ^^

    ReplyDelete
  15. I made mine by soldering directly to an SOIC MAX3232 chip. Not fun! At least I got it all to fit inside a 9 pin backshell (eventually). Some photos here

    ReplyDelete
  16. Better than a MAX3232 would be a 3.3v FTDI cable

    ReplyDelete
  17. This is very cool. Would it be possible to rewire the usb charger cable to transfer photos from a DSLR Camera like the Canon 60D, via USB (PTP) directly to the iPhone? Eliminating the unnecessary steps of transferring the photos to my Macbook first and then from my mac to the iPhone?

    Thanks!!

    ReplyDelete
  18. @Matt Hobbs: There's standard kits for that, and they're dirt-cheap on eBay!

    ReplyDelete
  19. What are they called? Do you have any links?

    Thanks!!!

    ReplyDelete
  20. I'm sorry, I misread your message... The Apple iPad Camera Connection Kit is for the iPad, and I don't think it works with an iPhone.
    I will test it later tonight and let you know!

    ReplyDelete
  21. Didn't work on my 3GS... Maybe with iOS5, but I'm not putting *that* on there until the kinks are ironed out...

    ReplyDelete
  22. I haven't had any luck getting the iPad accessories working on the iPhone unfortunately.

    ReplyDelete
  23. Do you think I need to provide some protection from static? Or just a voltage divider i enough to connect it to an avr?

    ReplyDelete