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.
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.
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.
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.