Tuesday, February 24, 2009

Serial Port on the iPhone with Minicom

This will be a little tutorial on how to set up Minicom on your iPhone or iPod Touch to view incoming serial data. I hope to continue this with Python or maybe even Obj-C. Click on (some) pictures to enlarge.

Materials:
Jailbroken iPhone or iPod Touch
Charge Connector (MJS or Sparkfun)
Serial Data Source (Arduino in my case)
Computer/Wifi network
Putty

1.Install Minicom, Terminal OpenSSH, and Toggle SSH from Cydia

This step should be pretty self-explanitory, If you can't do this and can't google, then you probably shouldn't continue on.

2.SSH into your iPhone

Obtain your IP Address from Settings or the SBSettings App.



Start up the SSH Server




Go into Putty, enter the IP, and create a new SSH Session



On the "Potential Security Breach," click Yes

And Login as Root with Password "Alpine"






And Your In!

3.Make a Directory

Do a "CD .." twice, which whould put you in the root of the filesystem at /



Now do "CD usr"

And "MkDir etc"



4.Start up Minicom in configuration mode

Simple: "Minicom -s"



5.Setup iPhone Port

Arrow down 2, to Serial port setup and press enter



First, press A and change "/dev/ttyS1" to "/dev/tty.iap" and press Enter



Then press E and adjust to whatever serial source you are using. I used 19200 8N1 for my Arduino.



6.Save and Exit

Press Enter until you return to the main screen, arrow down to "Save setup as dfl," and press enter.







And press "Exit from Minicom"

You can now close the Putty Session.

7.Hardware Setup

This will vary depending on your Serial input and iPod connector, but here's mine:





In this case, I have the Serial TX from the Arduino connected to the RX of the iPod through a 1K resistor, for 5v to 3.3v. I also have the common ground connected. The Arduino is reading data from a Wii nunchuck through a Wiichuck Board
and sending it out at 19200 Bps. Remember level changing for 5v and 12v sources!!

8.Read the Data

Power on your serial source.

Open up the Terminal on the iPhone, type in "Minicom," and press enter.

You should see serial data streaming in.



And your done!

PS. If anyone has experience with graphical Python on the iPhone, I would love to collaborate on an app. I have tested and the Python serial library will run on the iPhone. Contact Me.

14 comments:

ryan said...
This post has been removed by the author.
Anonymous said...

Hey, this is great! can it be used for two way comms. I am trying to access the rs232 port on a CCTV camera to access the engineering functions. Usually done on a laptop with hyperteminal but would be so much easy to use my iphone.

Kerry Snyder said...

If you would like to try it, I'd recommend the Minicom Man page (http://linux.die.net/man/1/minicom) and the mobileterminal Wiki on Google Code (http://code.google.com/p/mobileterminal/w/list). Good Luck!

Anonymous said...

I am trying to do two way comms as well.
For my cable I used a 3.3V TTL-to-RS-232 cable part# MCU-026-172 from superdroidrobots.com and wired this into an iPod breakout board as follows.

Pin 1, Ground, White/Yellow wire of cable
Pin 12, Serial TX, Black
Pin 13, RX, Green
Pin 18, 3.3v power, Red

No luck with this as of yet receiving or transmitting using minicom to the serial device on /dev/tty.iap Hopefully the cable is good.

Kerry Snyder said...

I think you're going to want to switch your TX and RX Lines. You want the TX from the iPod (12) to go to the RX on your cable and the RX from the iPod (13) to go to the TX from your cable. Other than that, your setup looks good!

Anonymous said...

My minicom stays offline, any ideas how to fix this?

Anonymous said...

Ok, it was a different problem, minicom wouldn't run on the iphone via the Terminal app because it couldn't set the lock file. Logging in through SSH as mobile and changing the lock file location to /Temporary\ Items solved the issue. It now runs fine under user mobile on the iphone.

BTW: above CD sequence could be written just as CD /usr
BTW2: command is minicom without a caps.

Matthew said...

I am trying to control a servo controller with the iPhone (3.2.1). I have writeen a program to send data using the tty.iap without any luck...
When i send data i get a spike from the tx pin (12) on the iphone but it's not the data i sent it, just junk.
Has anyone had any success sending data from the iphone yet?

Jason Kotzin said...

This is great. Really good work. But this is actually rather important. If I'm not mistaken on what you've done, you have taken a 1K resistor and put it in series for the 5V to 3.3V conversion.

This actually wont drop 5V down to 3.3V. The uart will be traveling too fast for you to accurately measure with a voltmeter, but the voltage on both sides of the resistor will still be around 5V. It will still work, but at the cost of a slow degradation to the input pins of your iPhone. You'll eventually damage your phone.

You need a voltage translator to properly do what you are trying to do. However, since this isn't a bidirectional bus, you can drop the 5V down to 3.3V with a voltage divider using resistors. Take the 5V (arduino) TX hook it up to a 1K resistor, take the other end of the 1K, and hook it up to a 2K resistor. Take the other end of the 2k resistor, and hook it up to ground. Then take the node where both the 1K and 2K join, and hook it up to the RX of the iPhone.

http://en.wikipedia.org/wiki/Voltage_divider

You don't need to do it for the other direction since you are meeting the minimum Voh of the atmel. (And 3.3V can't damage 5V)

Little EE Background:
For just the series 1K to work, you need current to flow through the wire and resistor to give you a voltage drop across the resistor. The voltage drop across the resistor, minus the original voltage, will equal your output voltage. But there isn't enough nearly current. Not only is the phone high impedance, but that's just generally how digital logic works.

Ryan said...

Very nice!
I have an Arduino talking to my iPhone. To ensure level shifting from/to
3.3V/5V I use the level shifter and a boost power supply from Sparkfun.
http://www.sparkfun.com/commerce/product_info.php?products_id=8745
http://www.sparkfun.com/commerce/product_info.php?products_id=8999

John said...

Looking great, Im looking to do this very soon to control an Arduino from my PC/Laptop for controlling roaming robots. Have you got any info on what pin/cable colours of standard iphone cable does what? eg: RX, TX, GND etc. The other option is to buy one of the prebuilt iPhone to Serial Adapter's for aorund $30, but id still need to know what pin does what

John

donovan said...

Has anyone heard of a prebuilt cable for the iphone or ipad? I would like to use an ipad or iphone at the data center or wherever I need to connect to cisco gear rather then carrying a laptop around.

Anonymous said...

Hello all,
I too am doing cisco programming from my ipad. I use the pin 12/13 data lines to a TTL to RS232 converter. It works marvelous. :-)

Sajiv said...

How to start writing code for iphone, basically i am working on microcontrollers?

Post a Comment