Archive for the 'iPhone external keyboard' Category

A Bluetooth stack in user space

Saturday, February 7th, 2009

A Bluetooth stack in user space already existed for quite a while. The researchers at ETH Zurich provide software for their BTnodes. A BTnode has (among other features) an ATmega 128 micro controler and a BT module with an HCI interface that is connected via a UART.

Fortunately, you can do development and real-world tests with just the same software compiled for running on a host system (e.g. PC). The emulator runs in user mode and uses a BT module attached to the serial port. Have a look at

for further info.

For experimenting with the sensor node software I used a module like this - which has a Mitsumi Bluetooth module with a CSR chipset, works at 115200 bps and could do hardware handshaking (RTS/CTS) - nevertheless - the jumpers on the board also allow to work with no handshaking at all (in case your serial port does not provide it) by looping RTS/CTS at the module side. The photo on Flickr has notes that explain the jumper settings.

wml_c09_4_dev

I benefited a lot from having worked with Bluetooth on the HP iPAQ (Compaq at that time still) from the very early days - when this even still involved switching the HCI transport mode for the chip in the iPAQ with a tool provided by CSR. At that time I built a 2nd generation iPAQ based wearable computer for usage in a research project.

See the recent setup with the external adapter working on Linux.

bt_in_user_space_01

After having tested it on a Linux system - I can confirm that the software works on OSX as well - run as a standard user with read/write access to /dev/tty.KeySerial1 (a Keyspan USA-19HS adapter).

btnode_sw_on_osx

Now - let us attach the (we are still talking about an external one) BT module to the iPhone serial port and compile / run the emulator program as just another user space program.

btnode_sw_on_iphone

It just works (you will notice that - as shown on the photo on the top - I have 2 external modules - that’s the reason for the different MAC addresses).

coding for the iPhone Bluetooth module - starts without an iPhone

Tuesday, January 27th, 2009

Let’s assume we get access to the HCI interface of the BT module inside the iPhone.

The software to be used then should be similar to the one talking to another BT module with its HCI interface attached to a PC serial port. This approach should make development more flexible and comfortable.

And here’s the hardware to do so - just click on the photo to get more info.

wml_c09_4_dev

talking to a serial port in C on OSX

Wednesday, January 7th, 2009

of course - if you are just about testing - attach your periperial as described in attaching peripherals to the serial port (just 3 pins, GND, Tx, Rx - no more need for the former specific “toggle GND” procedure with the most recent (Jan 2009) iPhone / iPod touch firmware) and use the minicom terminal program (can be installed via Cydia). As for the HW connections - this is a 3.3 V port - without any level shifters, so DON’t connect to your PC serial port directly.

the code referenced below is very basic - but should give you the idea how it works - accessing the serial port on OSX in C

This was once used for talking to another serially attached peripheral. Adapt the path to the serial port and the generation of sent / parsing of received data to your needs.

iPhone keyboard (code) snippets - part 3

Monday, January 5th, 2009

- editing in progress -

Let’s have a look at the hardware.

iphone_port_breakout_board

- editing in progress -

Update notices to the iPhone external BT keyboard documentation

Sunday, January 4th, 2009

go on Twitter

iPhone keyboard code snippets - part 2

Saturday, January 3rd, 2009

Part 2: let’s talk with the external BT keyboard

Get some more info about your keyboard (it needs to be switched to SPP) first. The picture below shows how you do this on OSX.

info_about_bt_device

On Linux make sure bluez is installed and use: hcitool scan

My keyboard has the BT address: 00-0b-0d-8a-36-3a

Finally, we probably want the code for interfacing to the RoboTech RBT-001 BT module in C, but for now - Python is a good way to show how it works. And it runs on OSX, Linux, Win - just the same way. You need to have Python and the pyserial module (for accessing the serial port) installed and need to adjust the path to the serial port you connect the RBT-001 module to.

For development and test I use a littleUSB adapter (see photo below for more info and links) - so I can develop and test everything on a Mac (I do), a Linux or a Win system. The USB-2-UART chip on the littleUSB has drivers for all these systems. It is based on the Silabs CP2102.

bt_module_4_development

We want the RBT-001 BT adapter (that will finally be connected to the iPhone / iPod touch serial port) to connect to the BT keyboard and receive data from it. Let’s have a look at the Python code that does so.

It produces the output you see below. You need

to understand this.

decoding_bt_keyboard_data_annotated

This shows the data received from the BT keyboard at the RBT-001 side. We are mainly interested in the SPP_INCOMING_DATA packets. Within their payload there is a byte for the key pressed and in the next packet the same byte + 0×80 for the key released.

I pressed “abc” - and we can decode this with the translation table from the kbdd code.

iPhone keyboard code snippets - part 1

Friday, January 2nd, 2009

Part 1: the key event injection part

You may do this with a VNC client on either

  • a Mac (I use a Mac mini with fink)
  • a Linux machine
  • whatever system that lets you compile libvncserver and its client examples
  • a jailbroken iPhone with a toolchain installed - so you can compile on the device itself
  • a jailbroken iPhone to run the program that you cross-compile on another system

Just take the following steps

  1. install Veency on your iPhone / iPod touch device (I did this using Cydia)
  2. test the Veency VNC server with a VNC client like e.g. JollysFastVNC (if you are on a Mac)
  3. get libvncserver, compile it and run client_examples/ppmtest <ip_address_of_your_phone> - it will connect to the Veency server and give you a screenshot of the iPhone screen in the file framebuffer.ppm
    if you run the VNC client on the iPhone itself you may use its loopback interface IP address 127.0.0.1
  4. play around with a modified client_examples/ppmtest.c file like this one ppmtest.c with minimal changes / just for test
  5. this should let you simulate the keyboard events we need - test it with e.g. Mobile Terminal or a native iPhone application like “Notes”

We will re-use this snippet and feed it with data we receive from the BT keyboard in the next steps.

Using the iPhone internal BT module seems to step forward

Thursday, January 1st, 2009

I just made a photo of an app using the internal iPhone BT module.

internal_bt_sees_keyboard

Here is some more info.

Mainstreaming external iPhone / iPod touch keyboards

Wednesday, December 31st, 2008

see my flickr pages for more info right now.

or follow the step by step instructions that describe all the snippets at iPhone external keyboard

mainstreaming_an_iphone_external_keyboard

frogpad_usbwiz_bluetooth_iphone_keyboard