iphone serial communication

Apple has not made it easy to let the iphone communicate with external devices. Basically, you need a jailbroken phone to do anything. This post covers the current state of serial communication on the iphone.

A succesful example of making an application that uses the serialport on the iphone is xGPS, which let you connect to an external GPS.

There are two sites that kept showing up when I looked at solutions for accessing the serial port.
One solution described on ohscope, uses the mobile terminal app available from Cydia, in combination with a serial comunication program called minicom. Basically it lets you open a serial connection and you can send and receive data using the terminal window.
For simple monitoring of input this might be all you will ever need, and it is relatively simple to get working.

The other solution on devdot, dating back to 2007, is a serial communication application written in C, which is still the example that shows up in different forums. There has been a few changes since 2007, when Iphone was on OS 1.x.

My main interest in getting serial communication working is that it would be very helpful for some of my mobile installations like the Wind-up birds, a network of mechanical woodpeckers, where a lot of the work is setting up a network between several xbee radio modems. It also involves climbing in trees, and it would be very convenient to have small controller/monitor app on my iphone, instead of using my laptop.
I also think it would work well with my dimsun dimmers, being able to control the lights remotely.

Other options
When searching for solutions, some projects show up which claim that “the iphone controls my RC car/my garagedoor” etc, but actually the iphone is communicating with a pc which then again communicates with an arduino. This is ok for protyping, but I want to get rid of the PC part (Actually there was a project in 2008 which uses iphone-xbee to control a rc-car. The instructions are in Japanese, and it was made using python I believe).

There are some promising work being done on making the built in bluetooth work as a bluetooth modem (something that Apple has blocked). Currently the BTstack is only able to read serial data. There is a demo app showing how a wii controller controls a model of the wii on the iphone. There is also the HumanAPI project which has made an interface for a pulserate sensor, based on the BTstack and a programming environment called PhoneGap.

Maybe sometime soon it will be possible to access the serialport on the iphone without jailbreaking it. In the openframeworks forum a new serial adapter for the iphone was mentioned.

The physical connection
To get access to the serialport you need some sort of adapter from the iphone connector. I got mine here, and sparkfun stocks a few different models. You can find an overview of the pinout at pinouts.ru.

The physical connection is the easiest part. You only need three connections from the Iphone: rx,tx and gnd. Optionally you could also use the +3.3v connector, making it possible to power up your device from the iphone. I do this with my xbee connector, but you need to be careful with this, as you might break the iphone if your device draws too much current. I haven´t found a reliable source for how much  current you can draw, but have seen 80-100mA mentioned a few places. This works fine with the standard xbee, as it draws around 40mA. It would also work fine with a 3.3v based arduino, and also probably with the FIO (not sure how much current the combination of the xbee and atmega chip draws).

Using the xbee which runs on 3.3v I  connect tx_iphone to rx_xbee, rx_iphone to tx_xbee, and gnd_iphone to gnd_xbee.

If you connect the iphone directly to an arduino running on 5v, you need to have a 1 k resistor between tx_arduino and rx_iphone.

approach 1: Serial communication using mobile terminal and minicom

Before getting started I recommend installing a very useful addition to the iphone software called sbsettings, available on Cydia, which basically is like a control panel for “hidden” features on the iphone. You can also install addons like syslog, which is very useful when debugging. The mobile terminal app is also very useful.

The instructions from ohscope are pretty clear.
You need to know how to SSH to the iphone from your computer. I use a combination of fugu and terminal on OSX, Putty should do the job on Windows.  There is a good explanation on how to do this on a mac (and many other useful things) at hackthatphone.

It is much easier to configure minicom from a terminal on a computer than from the iphone terminal program. So I open terminal on my mac,
and enter ssh -l root 10.0.1.9 (ip of my iphone). The default password is alpine.

After I had updated my iphone to 3.1.2 I got an error message when trying to open minicom: “minicom cannot create lockfile. Sorry” This turned out to be a permission problem, so I navigated to   /var and changed the permission so anybody could write to lock: chmod a+w lock.

Some useful links related to mobile terminal and minicom.

mobile terminal wiki

I found some of the gestures not to be working, so I ended up mainly using the keyboard for navigation.
basic minicom commands

approach 2: make an app that can read and write to the serial port

Preparing for development on the iphone

Last saturday NYCresistor hosted an introductory openframeworks workshop with Zach Lieberman, one the creators.
Basically openframeworks makes it much easier to do interesting audiovisual programming than if you would have to write the code in C++, by wrapping low-level code in easier to use methods and functions.
I was new to both xcode, openframeworks and C, so there was a lot of new things to dive into, but it definetly helps having a background from programming with Processing.

The neat thing with openframeworks is that it is crossplatform: It runs on osX, linux, windows and iphone.  This was a perfect opportunity for me to move to step two: make my own serial communication program.

The drawback with writing code for the iphone is that you are supposed to pay $99 to be a developer. Since I am mainly interested in developing programs for using the serialport on my own phone I wasn´t so interested in paying for it. Fortunately there are ways around this, but it is rather complicated.
One way is to use the free toolchain.

I felt more comfortable using Xcode combined with openframeworks, so I searched for ways of making Xcode compile, install and debug to the iphone.
First of all, you need to register as a developer at apple and download the Iphone SDK.
Then you have to do some modifications to get around signing process. There are several ways of doing this, some of them extremely complicated. I think I found a good solution that is not too hard, and which works on iphone os 3.12 and xcode 3.21.
The basic instructions are found at the networkpx project blog. First you need to create a code signing certificate, and update your xcode target accordingly. If you only want to compile in xcode, it is very simple, you only need to change a few lines in a file (I found three places that should be changed, the instructions only mentions two).
To be able to install and debug it gets more complicated.
I used a combination of Appsync 3.1, available from hackulo.us repository on Cydia, and some of the instructions from the networkpx project blog. Basically Appsync makes steps 5-10 in the install-debug section unnecessary.
It is important to set the -gta flag in the options for your xcode project (found in the code signing section, other code signing flags).

Now I am able to use the iphone with xcode like a normal developer: I can run and debug on the iphone simulator, or install, run and debug on the iphone, which is very convenient when developing. Sometimes debugging from the iphone doesn´t work, then I activate syslog which creates a log on the iphone that I can read on my computer later.

Setting up the serial port

The port name is the first thing to know: /dev/tty/iap

The serial code itself is quite standard, so the example from devdot would probably still work, basically doing
fd = open(“/dev/tty.iap”, O_RDWR | O_NOCTTY | O_NDELAY);
to open the port.

Using openframeworks, I modified the oFserial example found in the mac distribution (this example is not in the iphone distribution).

the only thing I need to open the serial port using openframeworks is to specify portname and baudrate: serial.setup(“/dev/tty.iap”,9600);

In v0.60 of openframeworks for iphone, the iphone is not included in the serial library, so you need to manually add “|| defined(TARGET_OF_IPHONE” to each #if section in ofSerial.cpp which refers to osx and linux, so it would look like this:
#if defined( TARGET_OSX ) || defined( TARGET_LINUX ) || defined(TARGET_OF_IPHONE)
This will most likely be included in newer versions of openframeworks.

So, by modifying an existing serial code example I was able to compile and run the program but got an error saying that it was unable to open serial port.
After a hint on the GPSserial forum, I understood that my problem was related to permissions of the application. The application needs to be run as root.
I spent about two days learning about permissions and trying with setting different permissions, without any luck.
Why was I able to open the serial port via minicom and terminal and not from my application?
After some more research I discovered that in the early Iphone OS days, applications were installed as root, this was later changed as it could be a security risk. Maybe this is why the example from 2007 worked back then, because it was automatically installed as root?
Appstore apps are installed in a different location (/private/var/mobile/Applications) than Cydia apps like Terminal (/private/var/stash/Applications), and these places have different permissions. Xcode automatically installs programs in the appstore appsection, inside a folder with a long number as name, such as 03A7764B-DDE0-4A60-A56B-CF2ADBB0213F. So what would happen if I moved my app to the the other applications folder?
I was able to connect to the serialport!

There might be an easier way to move the application, but this is how I did it:  The easiest way to find the folder installed by xcode is to find the last created folder in the /var/mobile/Applications folder. Open this folder, and just copy the yourapp.app to the desktop. Then delete the folder using ssh from a terminal program. If you are in the Applications directory the command would be: rm -r 03A7764B-DDE0-4A60-A56B-CF2ADBB0213F (replace with your own folder name). Copy your.app into the /var/stash/Applications, respring the springboard (using sbsettings) on your iphone and you should be set. If you need to install a new version of the app from xcode you need to first delete yourapp.app and respring the springboard or else you will receive an error when trying to install the app.

Two demos
To show that it actually works I have made two simple demo videos showing serial input and output.


The serial output example was my first attempt at integrating Interfacebuilder with openframeworks. There is one example of how to combine openframeworks and InterfaceBuilder from ITP.

The ITP example doesn´t include any interaction between the GUI elements and the code. I found the tutorial from switchonthecode to be quite helpful for this part.
I struggled with passing data from the interface part of the code to the serial communication part of the code, but solved this the dirty way by declaring some variables as extern, as described here. The supposedly more correct way is described here.

I was not able to find a good way of updating the interface elements based on incoming serialdata, so I decided to do that in openframeworks by making a simple line that moves vertically based on data read from a photocell attached to the arduino.

If I could have written this in Processing it would have taken me a few hours. Instead it took me two days, mainly because it was a new programming language and IDE for me, but also because Openframeworks/obj C is a lot more strict on how to write the code.
It would be great if iProcessing, a javascript version of Processing that runs on the iphone, would work with the serial port. But I assume since it is a web application I wouldn´t be able to run it as root.

Ideally, it would be nice to have a way of customizing the interface according to the need of the application. mrmr (not being developed anymore I think), one of the first OSC applications for the iphone, has a nice way of letting the user create a interface template and then upload it to the iphone. It could be interesting to integrate this with serial communication, especially when working with a microcontroller like the arduino. You could then have different templates depending on the functionality of the current setup, without having to create a new program each time.

It could also be interesting to incorporate firmata, which is already supported in the desktop versions of openframeworks. This has now been done by another openframeworks user, check the openframeworks forum thread.

Here is my openframeworks code.

About these ads

130 Responses to “iphone serial communication”

  1. Developing for iPhone serial communications - Hack a Day Says:

    [...] threw together a tutorial on using serial communications in iPhone applications. It builds upon the DevDot tutorial which was [...]

  2. kersny Says:

    Thanks for the mention! I’ve been interested in setting up a GUI program for serial but I haven’t ever taken the time to look into it. Good work!

  3. dustin Says:

    i have been trying to get this thing figured out all night to no avail…. all i’m wanting to do is use the serial port to turn on a matrix of leds not using an Xbee using the 30 pin connector hooked up to an arduino via breakout board. i made a coffee table with an 8X8 matrix and and an ipod dock that plays music.
    check it out here: http://www.MyArduinoProjects.blogspot.com admittedly i’m new to this whole ipod programming stuff but i’m not even sure if i have my certificate installed correctly :( please take a look at my project and let me know if you can or want to help. thanks

  4. hcgilje Says:

    The coffee table looks nice!

    The certificate part is really a pain, but kind of hard to help you with.
    Remember to check out the links in the networkpx article:

    http://networkpx.blogspot.com/2009/09/compiling-iphoneos-31-apps-with-xcode.html

    It is probably a good idea to start with just getting a simple app running on the iphone first. Memo has a pretty good tutorial here:

    http://www.memo.tv/openframeworks_on_iphone_sample_1

    and if you are interested in using openframeworks to develop on the iphone you might want to have a look at the wiki:

    http://wiki.openframeworks.cc/index.php?title=OfxiPhone_comprehensive_guide

  5. Vlad Cazan Says:

    Great project, I have ordered my breakout and I cant wait to try this out! Do you know any way to do it with an old ipod cable?

  6. dustin Says:

    thank you! i’m hoping to make hackaday when its done :) i’ve downloaded the “what way is up” source code from apple and when i compile i don’t get an error saying anything about my certificates anymore for some reason i get an error that says something about unexpected end of file and i really have no idea why. i’ll do some more looking at those links. thanks again

  7. Joe R Says:

    Amazing! Thanks so much! I’ve been looking into writing apps for my jailbroken phone for communicating over serial for the last few months and was completely lost before this. I don’t have any programming experience which doesn’t help haha but this is a great guide.
    Thanks,
    Joe

  8. hcgilje Says:

    In theory you should be able to find the right cables using the pinout linked to in the post and a multimeter.

  9. Top Posts — WordPress.com Says:

    [...] iphone serial communication Apple has not made it easy to let the iphone communicate with external devices. Basically, you need a jailbroken phone [...] [...]

  10. Epor Says:

    This is an easier way to move the application over using SSH. This maybe outdated as it was made for 3.0 but it should be able to be tweaked:

    http://www.cocoamachine.com/blog/2008/01/easy-iphone-iukit-development.html

    This should ssh it right into the applications folder and not into the sandbox with the crazy folder name.

    I have been meaning to get into serial iphone applications and had done most of the same research you did up to the point right before making a serial application. I will need to look into openframeworks as that sounds like a great place to start. Thanks!

  11. Boetn Says:

    Hi,

    For a school project we are making a bluetooth controlled hovercraft. Now we almost finished this up using a windows mobile phone and we wanted to add the iphone in the project mostly because of the use of the accelerometer. Now i was wondering if it’s possible to use the serial communication over bleutooth?

    kind regards,
    Boetn

  12. hcgilje Says:

    Hi,
    check out the btstack link in this post. There are people working on a bluetooth stack for the iphone, but last I checked it only works with serial in, not serial out, but hopefully that is something that will change soon.

  13. Boetn Says:

    hi,

    thanks for the fast replay.
    have had a quick look at that already, and like you said it only is possible to read stuff, not to send it.
    Our project though needs us to send stuff as well.
    In the meantime i’m making a server on the windows mobile phone so i can connect to that to send the commando’s over bluetooth but that’s a bit far fetched, would be a lot easier if i could directly used the serial communication over bluetooth

  14. alfa Says:

    Hi,
    thanks for the tutorial, I’ve a jailbroken iPhone with firmware 3.0 and I’ve a problem with the last passage (the one of moving program.app to /var/stash/Applications) because after the copy and after the respring my application doesn’t start… It flashes as it’s opening and then the iPhone return to springboard…
    Do you have any idea about what I’m wrong?
    Thanks!

    P.S. sorry for my english…

  15. hcgilje Says:

    hi,
    did you remember to trash the app in the official applications folder? If you have two copies of the program in different locations that might confuse the iphone. Also check out the alternative method for installing the app mentioned by epor in the comments. I haven´t tried this myself yet.
    hc

  16. alfa Says:

    Yes I did. I also tried the other method but the results is the same… Any ideas?

  17. epor Says:

    alfa,

    It sounds like you don’t have Appsync installed on your iPhone. If you are running firmware 3.0 as you said in your first post, I believe you need to have Appsync 3.0 installed to allow you to run the unsigned program. Appsync 3.1 is designed for 3.1.x firmware.

    See this link for more info:

    http://hackulo.us/forums/index.php?/topic/39399-release-appsync-for-31/

  18. alfa Says:

    No… It’s not the problem… AppSync 3.0 is installed…
    Can it be an entry of the Info.plist file that is missing?

  19. Ayodele Says:

    I am very new to Iphone development however I have a project to complete as part of my thesis which involves obtaining data from a medical device over bluetooth with an iphone and doing some analysis. I have searched several forums and I dont seem to understand what everyone is saying. My question is, based on the fact that I am new to Objective C (learning fact though) and the limitation imposed on data connection via bluetooth by Apple. Is there a way I can conveniently circumvent this to implement successful data tranfer, or are their external bluetooth adapters I can program with the SDK to implement this? Thanks

  20. hcgilje Says:

    the only way to use the built-in bluetooth module is to use the btstack mentioned in the post.

  21. Paolo Says:

    Hi i’m italian and i need if is possible the total code of demo2 can you post it??? pLEASE if you do this you save me!!!

  22. Oni Says:

    Hi there. Great tutorial and some good tips. Im interested in how you managed to get the iPhone to talk back. So far I have only managed to receive data but not to send. How have you managed to get around this?

  23. hcgilje Says:

    I added the openframeworks code at the end of the post.
    hc

  24. Epor Says:

    hcgilje,
    FYI, your link seems to be broken. “Page not found”

  25. hcgilje Says:

    thanks, fixed!

  26. Karel santral Says:

    nice. thanks for sharing…

  27. Sam Says:

    Thank you for this fantastic post! Amongst so many irrelevant or dodgy blogs, this one addresses a crucial problem in prototyping with the iPhone and external hardware (not endorsed by Apple of course). I’m still tentative on jumping on the Jailbroken train, but perhaps in this case, the ends justify the means.

    It’s interesting that you came from Processing to C++. I’m on the inverse route, and finding awesome features about the language that I wish C++ had…

  28. hcgilje Says:

    Glad you find it useful!
    I spend most of my time in processing and maxmsp, so this was my first project using openframeworks, since c or python seemed to be the only options to get serial communication working on the iphone. Iprocessing is interesting for prototyping, but very slow compared to openframeworks, and anyway you wouldn´t be able to talk to the serial port.

    hc

  29. Fab Says:

    Hi guys,
    regarding the iphone serial communication topic , anyone of you perhaps know if it would be actually possibile to use the normal Iphone USB Cable togheter with a USB-Serial (RS232) converter (normally used with a laptop that hasn’t the Serial Port) ?

  30. Paolo Says:

    Thanks very much for the up you save me :)
    If i need in future can i ask you somethings about this at your email address??

  31. hcgilje Says:

    I prefer to keep it on the blog, because that way it can be available to others, and it is also more likely you will get answers from other people who know more than me about it.

  32. Paolo Says:

    hi! sorry but my english is not too perfect, so maybe i make a mistake to debug the program, i’m looking for the serial in with the light sensor can you help me more please?
    i download the directory of the openframeworks code but my ansewr is:
    how i can use it? this openframeworks are the code that i have to put on the iphone?
    Please i trust in you!

  33. Tyler Says:

    I don’t see you explicitly state it, but would I be right in assuming that all solutions for serial comm require a jailbroken device?

    My project involves just using an iPhone to display data being sent to it by an Arduino. I have no need for two way communication. But I’m struggling to find a simple method for ONE way communication without jailbreaking.

    Any thoughts?

  34. Daeseok Hwang Says:

    Thank you for your awesome post. It will helpful for our zigbee-serial development project. Thank you very much.

  35. Bume Says:

    Thank you for your posts.
    We are working on the project (ZigBee to iPhone serial communication) has been a great help to.
    Perhaps you may have had the information that can fail without.
    Is greatly appreciated. : )

  36. stephan schulz Says:

    hey.
    great work.
    do i have to install minicom? and if so, does minicom set the baud rate to a fix value or just to a value minicom uses?
    or can i use any baud rate depending on what i set it to in my openframeworks app?

    thx,
    stephan.

  37. hcgilje Says:

    hi,
    you don´t need to install minicom if you are making your own app. minicom is just the simplest way to get started with serial communication, but it is of course limited to a terminal interface.

    hc

  38. vince Says:

    Hey, I’m having a lot of problems getting the code to compile. I’ve downloaded OF and installed as much as I can however xcode still is unable to compile it. Can you give a better description of how your files are setup and maybe a large .zip file containing all of the frameworks/libraries that will compile first try?

  39. stephan schulz Says:

    @ hc. thanks again.
    @ Vince. Openframeworks has a great forum and wiki that might help you to get setup.
    and some other things that helped me:
    google memo +
    google jeffcrouse + openframeworks-on-iphone

  40. hcgilje Says:

    there are even some zip files to be found in the openframeworks iphone forum
    btw, Stephan made a nice firmata implementation for iphone/arduino, also available through the forums.

    hc

  41. Damon Says:

    Interesting development work. I have a rather simple question that perhaps some of you could answer- if I use the IPOD breakout connector can I draw power from the Iphone without having to do any application work? In other words I just want to plug something into the Iphone and have it work on its own. Thanks in adavance to all. Also- if anyone here does freelance software work pertaining to the iphone serial interface I would be interested in speaking with you.

    Damon
    dborich@austinbiomed.com

  42. vince Says:

    I have the same problem you had about accessing the dev/tty.iap file. The app loads fine when installed in the mobile directory however, when I load it into the root directory and respring, the app fails to open. Ever have this happen to you?

  43. stephan schulz Says:

    Yes this happens to me too.
    I usually sftp from my computer to my ipod, navigate to the stash/appilcations folder. i first delete the old .app file, than copy the new one in there. i don’t have to respring every time. this gives me pretty repeatable results.
    sometimes though i get what you described. than i delete the app, respring, copy the new version in to stash/appilcations and respring.
    good luck.

  44. ds Says:

    Regarding the permissions issue, by first setting the permissions of the /dev/tty.iap so they appear as crw-rw-rw- this might make things easier.

    I have managed to get it going without much juggling using this method. Namely, compile the .app and SFTP it straight into the /Applications alias in the root of the iPhone.

  45. ds Says:

    My last post about setting the permissions on tty.iap turned out to be a false alarm.
    The app still needs to run from the /private/var/stash/Applications.XXXXXX/ directory on the phone.

    To make this process easier I wrote a quick script to add as a Xcode script build phase.

    You will first need to setup password-less access to root on the phone by following this tutorial.

    http://www.stocksy.co.uk/articles/Mac/ssh_on_mac_os_x/

    Then add the script below as the last step in the build.

    http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeBuildSystem/200-Build_Phases/bs_build_phases.html#//apple_ref/doc/uid/TP40002690-CJABHEIB

    Once that is done, replace the XXX.XXX.XXX.XXX with the iPhone IP address, and the Applications.XXXXXX with the folder on your phone where Cydia apps are stored.

    The script will first delete the old app, copy across the new one, then finally respiring so the new app can be used.

    #———————-
    echo “Product Name ${PRODUCT_NAME}”
    echo “Target Build Dir ${TARGET_BUILD_DIR}”
    #
    ssh -T root@XXX.XXX.XXX.XXX rm -R /private/var/stash/Applications.XXXXXX/${WRAPPER_NAME}
    echo “${TARGET_BUILD_DIR} Removed”
    #
    scp -r “${TARGET_BUILD_DIR}/${WRAPPER_NAME}” root@XXX.XXX.XXX.XXX:/private/var/stash/Applications. XXXXXX/
    echo “Copy Complete”
    #
    ssh -T root@XXX.XXX.XXX.XXX killall -HUP SpringBoard
    echo “Respringing…”
    #———————-

  46. Justin Says:

    Thanks to post so challenge topic.
    I have two general questions about your openframeworks code.
    1: What different between hcSerial01 and hcSerialin01? they supposed be under openframework060?
    2:If I use Xcode, do I need jailbreak my iphone to run your code?

    Lots of thanks

  47. vince Says:

    Wouldn’t it just be easier to run an NSThread that continuously keeps reading from the serial port file descriptor and just having the C function return what was received? I feel like open frameworks isn’t really necessary…

  48. Irwan Says:

    Hi,

    Can I check with you the pins that you are using for the serial communication demo. It is Pin 1 (GND), Pin 12 (Tx), Pin 13 (Rx) and Pin 18 (3.3V)? I am trying to retrive data from my ZigBee module and want to display the result on the iphone. I am very new to iphone development, apprecaite that you can give me some pointers or perhaps point me to the right direction. Thanks.

    Irwan

  49. Jaime Says:

    Hi!,
    I have downloaded the code and the openframework like it said and put the example code on the app folder but when i try to build it with xcode it tells that they are 1500 errors aprox,can anyone help me please? Thanks.

  50. chan Says:

    Hi,
    Thanks for your efforts for developers.
    I’ve test serial port open followed by your procedure.
    But it turnded out that my App flashed as it’s working then the iPhone return to springboard.
    My procedure was that I copied my Test.app folder from /var/mobile/applications/DESS-1123XXXXX to desktop and then deleted the folder (DESS-1123XXXXX). And I copied the Test.app folder to /var/stash/Applications.O0lsfX.
    In order to get and copy the folder, I used diskaid that support root folder access.
    My device is a jailbroken iPhone with firmware 3.1.2.
    I think I missed something.
    If you can help me out, that would be appreciated.
    Can I know your email also?

    Thanks,

  51. Dutch_Razor Says:

    It seems Minicom has been deleted from Cydia, does anyone happen to have a link to the package?

    Thanks in advance!

    Just moving over the binary the right folder doesn’t seem to work, as there are other files needed.

  52. Sajiv Says:

    Can this project used to control home appliances through iphone?

  53. ae Says:

    Hi,

    Has anyone tried using the USB port for simple communication to a microcontroller? Has Apple restricted the use of USB like serial?

    Thanks,

    ae

  54. dw Says:

    Great post! Thank-you! I’ve been looking for something like this for weeks! Any idea if there is a way to do serial communication without a jailbroken iphone?

  55. hcgilje Says:

    There may be certain gps apps that work with specific gps modules without jailbreaking your phone, but for any other practical purpose this is not possible as far as I know.

  56. Farrukh Says:

    SIMPLY MARVELOUS!!! The post answers all the questions for me and you explained all of it in a wonderful way.

  57. Farrukh Says:

    hcgilje: i have trouble fixing errors when i try building your code in xcode (says winbase.h, tchar.h etc are missing) is this normal because the code is written for the iphone and can’t be run on the iPhone simulator. and if this is the case how i am supposed to check my code for errors as i can’t upload the app to iPhone after every single modification.
    Thanks

  58. Farrukh Says:

    my ofserial.h file has the follow header files

    #include “ofConstants.h”

    #if defined( TARGET_OSX ) || defined( TARGET_LINUX )
    #include
    #include
    #include
    #include
    #else
    #include <–
    #include <–
    #include
    #include
    #include <–
    #include
    #define MAX_SERIAL_PORTS 256
    #include <–

    but my open frameworks package doesn't have those headers files, is there something wrong with my OpenFrameworks files?

  59. Farrukh Says:

    the ones those are marked* (in the last post)

  60. szech Says:

    minicom has been removed from cydia, any idea where i can find this?

    thanks

  61. IntXbee Says:

    I want to be to send Xbee message to a webserver through the iPhone?
    Any idea, code, links or hints.

    Thank you.

  62. Mat Says:

    Hi, first thanks for this great post..!!I’ve 4 question
    1 – You said: “So, by modifying an existing serial code example I was able to compile and run”, do you refer to “serialExample.xcodeproj”?
    2 – Please could you give us more detail about your code modifications?(..also because in your projects there isn’t OF library so i have to import it)
    3 – I’ve not the Mac OS x SDK, are there problem in this?
    4 – My mission is just create an app in xcode that allow user to write inside a textview, and a button to send this data (text in this case) over serial port to display in my terminal, like minicom but the text is send from an obj-c app, not from MobileTerminal, is possible?

    p.s i have not an Arduino board, i’ve just an RS232 USB-to-SERIAL.
    Sorry for long thread and thanks in advance

  63. stephan schulz Says:

    here is my xcode iphone serial project and the arduino code that i am using to test the tx rx connection for my projects.

    i am using OF v0.06_iphone.

    http://www.lozano-hemmer.com/ss/serial_ipod_hc7.zip

    http://lozano-hemmer.com/ss/TEST_serial_in_out.pde

    @IntXbee
    maybe try the wishield, it communicates to the iphone over a standard wifi connection.

    @ ae
    it would be great to get data access over the actual usb D- and D+ pins. but how?

  64. Farrukh Says:

    Mat:
    1&2: it is serialexample.xcodeproj, every type of modification is clearly explained in the above post by hcgilje. OF isn’t part of the code you have to download it and place it in its appropriate directory…

    3: HCJILGE’S APPROACH CAN ONLY BE IMPLEMENTED IN MAC OS X SDK.

    4: you want to send data from an iphone app and then display it in terminal again, i am not sure what your last question is

    Arduino isn’t necessary for this experiment as long as you have its appropriate replacement, though i am not sure how you plan to just use a usb-to-serial converter as you need a MCU or a PC/laptop/mac

  65. Jess Says:

    Hey guys, I’m working on a project that is sort of like a
    remote thermometer. I used DevDot’s C-file with modifications in my
    project and is trying to get the serial port permission thing
    working on iTouch 2nd gen with IOS 4.0. Any Ideas? I searched
    Google and tried various methods, none seem to work.

  66. Mark Says:

    This is interresting but i’m a noob in this case, but isn’t it possible to make a adapter by wich you can connect a usb device to the iphone???
    For example a usb OBD device or a i/o device…

  67. yrb Says:

    hi

    I would like to know more about serial communication over iphone & also a good software to design a User interface for iphone to communicate with another device.

    Regards
    Yrb

  68. Shawn Says:

    I have been able to get this sample code to compile and run on my phone but I get no activity on the serial port. I hooked up a scope to pin 12 but it remains at 3.3V all the time. Sending characters has no effect.

    I installed mincom and got it working but again I see no activity on the TX pin from the iPhone. I streamed in a bunch of characters on the RX pin and see nothing in Minicom.

    Do you have to put a 6.8K resistor on pin 21 to enable the serial port or should it work without it?

    Any help would be appreciated.

    Shawn

  69. The far side of the Moon | Post-It Driven Development Says:

    [...] great thing is that it is really straightforward and it has already been done. A lot of projects use serial communication this way, and the tools Cydia provides for this [...]

  70. D.Viorel Says:

    Hello hcgilje! Can you tell me or post in this article the schematic of hardware that you used to conect iPhone serial port? Thank you!

  71. hcgilje Says:

    hi,
    the link to the iphone adapter is in the post, as well as the connections. The iphone adapter I use as is clearly labelled.
    “Using the xbee which runs on 3.3v I connect tx_iphone to rx_xbee, rx_iphone to tx_xbee, and gnd_iphone to gnd_xbee.

    If you connect the iphone directly to an arduino running on 5v, you need to have a 1 k resistor between tx_arduino and rx_iphone.”

  72. Nice Serial Communication photos | Communication Says:

    [...] iphone serial communication with xbee Image by hc gilje a simple test of two-way serial communication with the iphone, using the terminal program minicom, an iphone/ipod breakout adapater and a xbee radio modem. hcgilje.wordpress.com/2010/02/15/iphone-serial-communicat… [...]

  73. ubi de feo Says:

    very interesting article.
    I just wanted to point out that you could in theory talk to the serial port from JS if you’d run a serial daemon written in Perl or Python and accept socket connections from it.
    I remember while prototyping a project 2 years ago, this is how we had it working (I was on the hardware part, so not much knowledge of the python side).
    it was very stable.
    quickly searching I found this

    http://chisflorinel.blogspot.com/2005/05/pyserial.html

    I will go the Obj-C way, i think.
    thanks for the great read.
    ubi

  74. Nathaniel Lewis Says:

    Nice tutorial! I have based what I am doing off of the DevDot tutorial. My project is to control a small robot with the iPhone 4. One of the cool things is that I have compiled OpenCV (unfortunately no optimization for ARM yet) 2.2 for ARMv7 so that it works with the phone. I have an ATMega644 (atmel avr) running at 3.3V to the iPhone serial port and passing packets between the two for sensor data reception and motion control.

  75. JRMN Says:

    Thanks for writing this tutorial hcgilje. It took me awhile, but I was able to get both your OF applications to run on my jailbroken iPhone. But that’s as far as I got because you didn’t post your Arduino sketch. Can you please post your Arduino sketch because I would like to start with something simple like controlling a led on a Arduino. Oh and I am not using xBee, I have my iPhone directly connected to my arduino. Thanks again.

  76. Ausama Says:

    Hi
    I recently started developing for iphone. This tutorial was a great help for me. But when i try to use the provided open frameworks code i run into errors. Can someone please guide me as to what steps exactly have to be done to get this code to compile and what OF version to use with iOS 4.2 and Xcode 4.0.1.
    Thanks

  77. JRMN Says:

    I had that same problem at first. I think it has something to do with the location of program folder. I don’t remember right of hand and I am not at home, but I ended up moving both folders in the same folder as the iPhone OF examples.

  78. Ausama Says:

    Thanks for replying
    SO you are saying that i should put both folders downloaded from here in “of_preRelease_v0.06_iphone/apps/examples”?? and secondly after opening the project in xcode what stepsother than change base SDK and signing idenity to my own should i take?? and is there any specific folder where i should unzip “of_preRelease_v0.06_iphone” or any folder/place will do??

  79. JRMN Says:

    I’ll try to help you out the best I can, however, my memory isn’t that great because its been a while since I played around with this. You are correct, you have to place both of hcgilje programs in the “Xcode/of_preRelease_v007_iphone/apps/iPhoneExamples” folder in order to run them. I’m not sure if you have to have OF in a specific folder or not, but I saved mines here: “/Users/JRMN/Documents/Xcode/of_preRelease_v007_iphone/.” You look to be running a older version of OF. From what I remember I had issues with signing my applications and even though I got errors the application ran anyways. I believe I used this youtube video to get around the signing issues. http://www.youtube.com/watch?v=ErLt2Le558Q&feature=related Start there and if you have any other question just let me know. Although, I didn’t do a complete documentation on the process, I tried to save all the links I used to get my apps running.

  80. Ausama Says:

    Thanks for replying
    Yesterday i got rid of all the errors and now the app runs and i got it to install on my ipod touch 4. But when i try to move it to var/stash/applications, it stops working. i tap on icon and screen flashes once. I do have the ipod jailbroken. before moving i did delete the old directory. App did start after running from xcode but console said unable to open serial port; because of the folder xcode installs in. But the point is the app starts before i move it to the new location but not after

  81. JRMN Says:

    Cool, you got it to run. I’ll have to check when I get home, but from what I remember you have to save in in a certain location. I think that might be the issue with in not running on you iPod Touch.

  82. Ausama Says:

    please do. This last part is keeping me from testing the serial communication

  83. JRMN Says:

    Looks like you’re store the applications in the right place. My exact location is “/private/var/stash/Applications.pwn.” You might still be having issues with signing you applications.

  84. Ausama Says:

    I need help. I cant get the app to run on my ipod from the stash folder. ANd after that when i try to compile and install on my ipod again, it gives “internal api error”. I really need help guys. I am doing a university project and need this example to use as a reference.

  85. JRMN Says:

    How are you getting the appls on your iPod touch? I always used the simulator to build my apps. I manually moved my application over to my jailbroken iPhone 3G.

  86. Ausama Says:

    i install the app on the ipod using xcode build and run and then move it to the new location. Is there any thing wrong with doing that??

  87. JRMN Says:

    Building the application directly on your iPod Touch might be your problem. I never tried it that way, I always ran the app in the simulator and once it ran, I just moved the file over to my iPhone 3G. I test the application with the simulator first and once it runs fine there, I would try your iPod Touch. I personally think there might be something wrong with the signing process because if it’s not properly signed it won’t run on your iPod touch.

  88. Ausama Says:

    can you do me a favor and tell me step by step as to where to put the .app file etc, after you copy it from the simulator. and how did you put it into your phone? which software/method did u use? i use iphone explorer to move my .app file to my ipod touch… I am a licensed developer so signing is not an issue. i just need to get root access..

  89. JRMN Says:

    1. First make sure app runs on the simulator (Select iPhone 4.0 Simulator > Run)
    2. I build the app (Product > Build)
    3. Browse to location of app (/Users/USER_NAME/Library/Application Support/iPhone Simulator/4.0.2/Applications)
    4. Launch Cyber duck and SSH into iPod Touch (http://www.youtube.com/watch?v=UpYKOxRg9k4)
    5. Copy your app to iPod Touch (/private/var/stash/Applications.pwn)
    6. Reboot / Respring iPod Touch

  90. Ausama Says:

    did everything but it still flashes once and then quits

  91. JRMN Says:

    I had that before, I thought I used that youtube video I posted on how too fake sign apps, but after looking at a few of my projects, looks like I might have used this method instead. Follow steps 1 – 10 and let me know if it works for you.

    http://stackoverflow.com/questions/1285980/attempting-to-deploy-my-app-on-my-jailbroken-iphone-but-the-app-closes-immediat

  92. Jayesh Italiya Says:

    Nice Post, I am new to this thing I want to communicate with TX and RX Port For Getting data, Can you please give me a sample app for that

  93. JRMN Says:

    @Ausama, did you get it to work yet?

    @Jayesh, hcgilje posted two sample apps, just download them.

  94. видеоуроки по wordpress Says:

    Hi, Neat post. There is a problem with your website in internet explorer, might check this? IE nonetheless is the market chief and a big portion of other people will pass over your magnificent writing due to this problem.

  95. hcgilje Says:

    what kind of problem are you referring to?

  96. Ausama Says:

    Not yet. Same problem. I can’t get it to start when i put it in the new root directory

  97. Mauricio Bustos Says:

    Just wanted to thank you for the great work. I’m working on a swarm-like costume project for Burningman and this got me over the hump. Things are humming along. Very nice work and can’t thank you enough for sharing.

  98. Mark Says:

    Hi, Thanks for this great information, as well i was looking a way to get a serial communication in my ipod, thats really good, also im interested in the mech net you did, I have some xbee, and i would like to implementem in mech, do you have any suggest, tuto or link where I can see how to comfigure them???,

  99. hcgilje Says:

    There is extensive info about the first version of that project, but that was not mesh based. Here is the link: http://hcgilje.wordpress.com/resources/xbee_arduino_code/

  100. iPhone serial communication with external devices | EngBlaze Says:

    [...] (typeof(addthis_share) == "undefined"){ addthis_share = [];}HC Gilje has posted an excellent guide to serial communications with external devices using the iPhone. There are lots of resources out there for setting up serial [...]

  101. serjio Says:

    Heyho! Trying to link my ipod with tiny2313. Which pin did you use as ground for serial communications? According to pinouts.ru it should be pin 11. However, shortening pin 11 and pin 13 gives nothing on the terminal, while shortening pin 1 and pin 13 gives some rubbish (I thought that’s the good sign?)

  102. Evan Jones Says:

    I am attempting to connect a Medical Device with to the iphone. I have connected the red wire (3.3v input) to pin 18, the black wire (ground) to pin 1, and green wire (0 – 3.8VDC TTL Serial Output: 9600 Baud, 8 data bits One Start bit, One stop bit, with no parity) to pin 13 of the PodGizmo 1.5 Podbreakout.

    When I plug in the device, it’s power light comes on, YaY! When I configure minicom to the above settings and run it, I get tons of fast incoming jibberish/trash/junk data. The characters are not in the format which the Medical Device specifies it should be streaming. I have tried everything; e.g. changing the Minicom terminal emulation.

    Any ideas?

  103. teenytiny Says:

    I’d first start with shortening RX and TX pins on ipod to test if it works ok (when you type in the terminal with the pins open you shan’t see anything, however, when you shorten the pins, you normally see echo.
    Second point: I won’t use ipod’s 3.3 Vcc pin as I don’t know what current it can provide. It might be so that your Medical Device (what’s that btw?) consume too much power for the ipod, so it could go crazy. Instead, I’d source MD from the external source. For one-way serial communications two wires are enough.
    As far a I remember, there were several versions of podgizmo, one of those (namely 1.4, according to some sources) had some wrong wiring. on v1.4 you should connect it to pin 14.
    Next, although, for a short period of time I connected my ipod to 5V level, exceeding 3.3 voltage could harm your ipod.
    Have you tried connecting it to any other 3.3 device? Do you see the same gibberish stuff as well? If so, then check your MD and/or you might need technical support from the manufacturer of this MD.

  104. Evan Jones Says:

    Thanks for your prompt reply!! I’m not sure what you mean by shortening RX and TX Pins, but my device is a heart rate sensor which is powered by a 3.3v input and draws 34mW which is equal to 10mA. The device is sufficiently and appropriately powered by the iphone/ipod/ipad; but I will try to power it externally to determine if the data transmits in a different format.

    To clarify, (other than ground and power) I only have one output wire (green) connected to the v1.5 PodBreakout on Pin 13 (Iphone’s Rx Serial input port).

    The Kineteka PodBreakout Pinout reference paper I received with the PodBreakout Kit specifies that Pin 11 is “Serial Ground”. Is it possible that I need to connect the MD’s Ground wire with Pin 11 on the PodBreakout to “enable” the serial port to decipher the data? Thanks in advance for your/any response(s). ~Evan

  105. teenytiny Says:

    well, I am successfully transmitting data to the ipod using ground pin1 (I am not using podgizmo, soldering wires directly to the ipod connector from some old firewire cable).
    As for the shortened pins, you can check your connections in the following way:
    1. open minicom (I usually ssh to my ipod from my laptop – it’s much more convenient)
    2. open port tty.iap with your settings and type anything. normally you won’t see any letters in your terminal
    3. connect podgizmo with RX and TX lines connected to each other. type something else – you should see what you type.

    it’s sort of a loopback test. I bet that you either made a mistake in your minicom settings, or you MD works in a different format.
    what’s the length of the cable? could it be caused by EMI?
    any other connections on the podgizmo board, or just these four wires?

  106. ae Says:

    What about baud rate? What is the setting on ipod and MD, do they match?

  107. Evan Jones Says:

    The device has one green wire output; the following is copied & pasted from the manufacturer’s specs:
    (Serial Output of TTL Levels 0 to 3.8VDC) at 9600 Baud, 8 Data Bits, One Start bit (Start bit = 0), One stop bit (Stop bit = 1), No Parity. Host Input Impedence must greater or equal to 4kohms.

    I do have minicom set to 9600 Baud, (8-N-1) and when I run it, I get jibberish/junk/trash data. The only part where i’m a little confused is how the manufacturer specifies “One start bit (Start bit = 0)” which contradicts itself; but minicom doesn’t have a startbit parameter/setting. I’m also concerned that the “Host Input Impedence must greater or equal to 4k ohms”. Does this suggest that I need a resister placed somewhere? Please see below youtube video for details (sorry it’s 9 minutes long).

    I still have not tried the loopback, nor any other devices which consume 3.3v that send the above-specified TTL Serial data. I have attempted to utilize interceptty and screen; however their application more-than-likely has not been used properly because I am a n00b to unix based systems and don’t understand their usage. This article is a great tutorial, which I have re-read about 10 times along with the other 3-4 tutorials. From what I understand the iPhone utilizes TTL 3v serial pins (12 & *13) which my device natively transmits in; no converter boards should be necessary from what I understand. My asterisk next to 13 denotes the wire I am sending data to. (Pin 12 does not receive any data; only sends it if applicable).

    Any assistance is highly highly appreciated and the one who resolves it will be eligible for at least $50.00 in their paypal account. Thank you ~Evan

  108. teenytiny Says:

    man, how are you going to develop your own application if you don’t know how to read datasheets? What is the format you expect the data to come? I just read doc from nonin on Model 3011LP & 3012LP (don’t think that data output is much different). starting from page 6 it gives you the formats of data output. It seems, yours is df2 (page 7).
    The first byte in the frame is always x01, the second byte is status, and so on and so forth. I guess you could start capturing the output into the file, and then somehow interrpret that data. The data is presented in binary format, so you can’t see exact words or figures in minicom. You need to create an app to do that. Probably, not that difficult.
    I wonder if nonin offers any applications for iPod on cydia? :-)

  109. teenytiny Says:

    Evan, what’s exact the model of your device? What do you expect to get from your iPod? Should it just read the data from the device? Although I am not an iOS developer :-) I could try create a jailbroken application, say, for $500, that you’d have to install on your iPod. It would display nicely the numbers from the device using data format 1.

  110. evanjones4321 Says:

    Just send me an email to EvanJones@mdr.net with your contact info, and I’ll talk to my boss to see if he wants to spend that much money. Thanks for your input; I didn’t realize the jibberish was possibly valid data coming over; interceptty is displaying what appears to be consistent data in 0x## format when I use command:

    Interceptty -s ‘ispeed 9600 ospeed 9600′ /dev/tty.iap

    I am not familiar with unix based command prompts, and I hope I used it in the appropriate format, but looked like valid data format. But anyway; thank you for your follow-up with me an send me an email when you get a chance. ~Evan

  111. Work with me XCode | projects@338.oakland Says:

    [...] been having some trouble on the iPhone side. The data that I got fromhttp://hcgilje.wordpress.com/2010/02/15/iphone-serial-communication/ has been incredibly helpful. Most of my issues are in XCode and trying to get the compiler to play [...]

  112. Frank Saffery Says:

    I had a working RFID scanner a few month back. I moved country changed my iPhone due to this. I jail broke it re-downloaded OF threw my code into a blank project compiled placed it on my iPhone and it didn’t read the same as it used to. So I had a pre-compiled copy of my original code and i placed that on and the exact same happened. Am i missing something or have apple or OF changed something somewhere that has caused the program to cease to function correctly?

    Code can be supplied if anybody can help. Thanks.

  113. ipatch Says:

    does anyone know if using the “serial port” pin 12 / 13 still works in iOS 5.1.1?

  114. ipatch Says:

    it indeed still works with iOS 5.1.1 use pins 12 / 13 to complete the circuit.

  115. Hacking for Artists | I / O Says:

    [...] iPhone Serial Communication C++ [...]

  116. iphone serial communication with xbee | iptips - iphone / ipad / ios / android / mobile / tutorials Says:

    [...] iphone serial communication with xbee Image by hc gilje a simple test of two-way serial communication with the iphone, using the terminal program minicom, an iphone/ipod breakout adapater and a xbee radio modem. hcgilje.wordpress.com/2010/02/15/iphone-serial-communicat… [...]

  117. 13oR Says:

    Hi, all Geek,
    First bravo :) very nice post.
    So i have a question: What about using ‘xbee usb explorer’ with the ‘usb camera connexion kit’ insteed of ipod breakout adaptator ?
    Xbee —> xbee-usb-explorer —> usb-camera-connexion-kit —> Iphone
    If it work it avoid soldering etc…

  118. JP Says:

    Hi Stephan,

    Thank you very much for this very clear and helpful page.
    I am also very interested in programming a RS232 bluetooth link from an IPAD to a microcontroler via JY-MCU bluetooth module (I do prefer microchip to arduino but this is not an issue !). See my home page for a few realisations I did : http://freedom2000.free.fr

    My question would be : is BtStack ready now to communicate with a jailbroken device to a RS232 bluetooth device ?
    I have only found the GPS and Wii examples but no simple RS232 examples…

    Thanks
    JP

  119. Matthias Ringwald (@mringwal) Says:

    BTstack provides support for send and receive over RFCOMM channels. It doesn’t support RS232 configuration, but so far nobody seemed to need it.

  120. iphone serial communication demo | Arduino collector blog Says:

    [...] iphone serial communication demo Image by hc gilje a small application that sends control information over the serial port of the iphone through a xbee to an arduino. hcgilje.wordpress.com/2010/02/15/iphone-serial-communicat… [...]

  121. iphone+xbee | Arduino collector blog Says:

    […] iphone+xbee Image by hc gilje a small application that sends control information over the serial port of the iphone through a xbee to an arduino. hcgilje.wordpress.com/2010/02/15/iphone-serial-communicat… […]

  122. Cool Xbee To Arduino images | Arduino collector blog Says:

    […] iphone+xbee Image by hc gilje a small application that sends control information over the serialport through a xbee to an arduino. hcgilje.wordpress.com/2010/02/15/iphone-serial-communicat… […]

  123. stephen Says:

    Thanks for the post, I could communicate through pin 12 & 13, but can’t get 3.3v output from pin 18. My config is iPhone4s iOS 5.1.1. Anyone have successfully on this config?

  124. iphone komunikacji szeregowej z XBee | Pan T.U.S.K. Says:

    […] komunikacji szeregowej z XBee obrazu przez hc Gilje Prosty test z dwukierunkowej komunikacji szeregowej z iPhone, za pomocą terminala programu minicoma, iPhone / iPod adapater xbee wyrwania i modem radiowy. hcgilje.wordpress.com/2010/02/15/iphone-serial- communicat … […]

  125. serjio Says:

    any ideas if this can help avoiding touch interface? I need just to be able to connect the ipod and to launch my app with screen unlocked – basically I want to use iPod as an embedded screen.

  126. Juan Athill Says:

    Hey Hcgilje,
    Interesting Thoughts I recently bought a RedEye Mini universal remote device. It is an add-on for the iPhone. Whenever I try to add a new device, an error message pops up on my screen stating, “Error in network communication”. Also, when I open the app and press setup, then room setup, the serial number space is blank. Please Help! Thanks.
    Thanks


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

Follow

Get every new post delivered to your Inbox.

Join 181 other followers