Introduction: Control Stuff With Your IPod Touch/iPhone

Create your own control panels on your iPod Touch or iPhone.  This instructable demonstrates how to use Control , a FREE app available from the iTunes store.  It also demonstrates how to communicate with the app using a PC program. 

Minimum Requirements:
PC running Windows XP or newer.
A Wi-Fi connection to your PC.
An iPod Touch or iPhone.  I used a iPod Touch 4G.

You do not need programming experience for this instructable; however, if you want to create your own screens, or write your own code for the PC host, you will need to have some experience in network programming with UDP datagrams, and some javascript programming experience.  I provide all the source code for this instructable (see step #6).


Step 1: Install Control From ITunes

Install the FREE app, Control, available from iTunes.
http://itunes.apple.com/us/app/control-osc-midi/id413224747?mt=8


Step 2: Run the App

Start Control . The program should automatically start at the “Interfaces” screen. If not, use the lower menu bar to navigate to the “Interfaces” screen.
Tap “+” to add the OnOff control. Enter the URL:
http://home.cogeco.ca/~mybrainhurts/onoff.js

This is the source code for the screen.  It describes the shape, colour, and operation of the buttons.  It is written in JSON, a subset of Javascript.  Once it is loaded on your iPod, you don't need to reload it.

Note the last entry on the “Interfaces” screen is now “OnOff”.  I've found it is hard to navigate to new menu items.  If you have trouble, simply stop Control and restart it.

Step 3: Run the PC Host Program

Download the OnOff.zip file from this location:
http://home.cogeco.ca/~mybrainhurts/onoff.zip

Extract the onoff.exe file from the zip and run it.  Click the Start button. The program will tell you the IP of your PC.

On your iPod Touch, select “Destinations” from the menu. Tap “+” and enter your PC's IP in the “Enter Destination URL” (just the IP, no “http://”). Enter 10000 as the port number, then tap “Add”. Your IP address and port will appear in the list. Select it and it will turn grey.

Select “Preferences” from the iPod Touch menu. Enter 10000 for the OSC Receive Port.

Your iPod Touch is now ready to communicate to your PC.
NOTE: Every time you start Control, you will have to select your URL from the “Destinations” screen.

Step 4: Run the IPod Control Screen

On your iPod Touch, go back to the “Interfaces” screen and select the OnOff interface. Notice both the ON and OFF buttons are not lit. This is because as of now, your iPod Touch is not communicating to the host. Tap ON. If you have communications, the ON button will turn red, the data “127” will appear in the upper left corner. On your PC, the screen will display the data from the button and the radio button will change.

At this point, you are now communicating in both directions. The iPod Touch sent the value of the ON command as 127. The PC received the datagram, detected the originating IP, and begins updating the iPod Touch at 2Hz with the current value.

Press the OFF button on the iPod and it will change the state on the PC and on the iPod Touch.

Click the radio button on the PC’s dialog box and the iPod Touch buttons will change state.

The loop on the PC runs at 500ms, so don’t be harsh about the update speed.

Step 5: Bonus Step: Control Something

If your PC has a serial port at COM1, you can wire something up between pins 4 and 5 on the 9-pin D-sub connector.  I connected a solid-state relay, and turned on and off a lamp.  DO NOT USE AN ELECTRO-MECHANICAL RELAY!  There is not enough drive current from the serial port.

The relay I used is a Crydom D1240, which I had in my junk pile.  I see they are available from Digi-Key for about $40 US.

If you don't have anything like this, then try turning on and off a LED.



Step 6: What Next?

Now that you have the basic communication working, you may want to create your own screens. The best way to get started in this is to learn by example. The JSON source codes for the examples provided with Control are located here.
http://charlie-roberts.com/Control/interfaces/

Use a text editor (notepad or write) to experiment. Be sure to have the documentation for the widgets open in a browser window for reference.  http://charlie-roberts.com/Control/?cat=4

The zip file you downloaded contains the C++ code (Visual Studio 6) for OnOff.

The zip file also contains JSON and C++ programs for analog controls using a slider.  There is also a LabView 2009 implementation of OnOff .

The communications between Control and the host uses the OSC (Open Sound Control) protocol.  For more information on the message formats, see http://opensoundcontrol.org/spec-1_0