If you haven't already signed up, it's not too late! Friday, May 15, at 10AM we're doing a webcast (using WebEx) where we answer questions from the audience on advanced hacking.

Click here for more info: http://is.gd/zWcC

damien's picture

iPhone Hacks source code!

Sun, 04/12/2009 - 22:39

iphone hacks book cover

The iPhone Hacks book is available in bookstores everywhere as of April 2009. Click on the image to go the O'Reilly website.

This page contains links to source code, addendums, and other materials related to the book.

Download the full hack materials here:

Book Content in single archive

If you would prefer to just grab a specific hack, here are the files.

Individual hacks:

Hack 12.16 - Control the Physical World with an iPhone

Hack 12.20 - Infrared Remote

Hack 12.21 - Serial Modem

Hack 12.22 - Keyboard

You'll also want:

iPhone Source code (with both the Serial Modem code and Keyboard code):

iPhone Source Code

If you're planning to modify the firmware for the Serial modem and keyboard hacks, you'll want the project files that are used with the Cypress PSOC Developer Studio:

Serial modem firmware project files
Keyboard firmware project files

April 4, 2009 - We also created a second, improved schematic after the release of the book that includes the IR hack, the serial modem, and the keyboard hacks:

Schematic Version 2

UPDATE: We sent the circuit board files off to be manufactured today, and we ordered all the parts. We'll be posting pictures of the board layout and enclosure soon."

A number of industrious individuals have achieved what to some is the holy grail of iPhone accessories: an iPhone keyboard. But most have done it in a very hard-to-repeat manner, and few have shared the methods they used.

Expanding on their audio port modem , PerceptDev engineers Zack Gainsforth and George Dean developed a hardware and software solution that allows infrared keyboards to be used for typing on the iPhone, using less than $20 of electronics.

Zack used a Cypress PSoC microcontroller to emulate a simple modem, and then expanded it to detect an infrared signal or read from a USB host controller, which converts this signal to FSK for transmission to an iPhone.

We will be releasing schematics and source code with the release of iPhone hacks.

UPDATE: Here's the latest video. You can see typing speed and our first project-box prototype

And here's the video that started it all...

Link to YouTube for iPhone

George then created an iPhone application to decode the FSK signals to interpret the keyboard data and display the appropriate characters on-screen.

100_2718

100_2691.JPG

The iPhone has a modem. Did you know that? Well, not quite, but we managed to build a device that interfaces with an iPhone via the headphone/microphone jack and can send bidirectional serial data.

Though there are a number of ways to get data into and out of the iPhone - the dock connector, Bluetooth, Wi-Fi, etc. - none of these are well-suited for simple, low-speed bidirectional communication with inexpensive components. Plus, many of these were inaccessible via Apple's 2.0 SDK. The audio port, however, is accessible from the SDK - both for playing audio and recording it.

iPhone Hacks has the schematic for the circuit you see below.

100_2691.JPG

The core of this solution is a souped up microcontroller, which has a serial port on one side and talks to the iPhone using FSK (frequency shift keying), the same technique used by some of the first modems. (Frequency shift keying uses a sequence of analog signals with alternating frequencies to send information. For example, in binary FSK a tone of 8kHz might represent '1', and 4kHz might represent '0'.)

For less than $20, we built a circuit that accomplished this, and wrote a corresponding iPhone application. Serial devices plugged into our circuit can communicate with any iPhone running our 2.0 code.

We will be releasing schematics and source code with the release of iPhone hacks.

While there have been numerous one-off examples of hobbyist iPhone accessories posted on blogs and YouTube, few of these approaches have been implemented using the official iPhone SDK.

However, there is an input/output port on the iPhone just waiting to be used: the headphone/microphone port. If you think about it, people have been squeezing over 50kbps over phone lines, and phone lines have far less fidelity than the iPhone's sound chip.

PerceptDev engineers George Dean and Damien Stolarz collaborated on a simple circuit (costing less than $2) to take infrared pulses and convert them to sound waves, as well as an application to recognize the signals. The application can recognize signals from the infrared remote that comes bundled with most Macs.

By connecting a plain-vanilla infrared receiver and a few other components, we created a circuit that converts the output of the IR receiver into an audio signal that can be connected to the iPhone's microphone input.

infrared receiver

Then George developed a simple iPhone app that reads the pulses and parses the remote's commands, using the iPhone 2.0 SDK.

infraredhack

The details of these designs, the parts list and links to the software and code are available in iPhone Hacks (O'Reilly Media, Spring 2009).

Well, we're finally relaunching the PerceptDev site. We've been waiting as patiently as possible for the iPhone Hacks book to complete so we could post details of our exploits here. The next few posts will detail some of the fun we've been having with hardware on the iPhone - using the current 2.0 SDK.