Wednesday, February 18, 2009

Updating the PS3 Eye driver

This week kaswy released a new version of his driver (V0.3) and there also was a new kernel release for Ubuntu. Some of you might want to update, but also want to keep a working driver, that is the purpose of this post.

Let's get started, go ahead and install the new Linux kernel using your favourite update manager (e.g. apt-get or Synaptic Package Manager). Reboot your computer after the update to make sure the new kernel is loaded (save the URL to this page so you can follow the rest of the instructions!).

At this point, you probably don't have a working driver, we're going to fix that. Get the latest version of kaswy's modified driver and extract it to a directory, e.g. ~/src/gspca-ps3eyeMT. It's important that you do not have a build of the old source code present in the directory you extract the source code to, you can prevent that by moving the destination folder to a backup location first if it already exists.

We need to verify the source will compile for the current kernel, in my case 2.6.27-12-generic. You can check your version with:
$ uname -r
At the time of writing, the source is set to compile for 2.6.27-11-generic, which is not what we want, as this will not work for our situation. But luckily this is easily resolved! Open the hidden config file ~/src/gspca-ps3eyeMT/v4l/.version and inspect it's content:
As you can see, the variable KERNELRELEASE does not match our kernel release. Edit the line to match your kernel and save it. Now we are ready to compile the binaries for the new kernel. Execute the following commands:
$ cd ~/src/gspca-ps3eyeMT
$ make
$ sudo make install
$ sudo modprobe gspca_ov534 videomode=04
Your driver should now be installed and loaded!

Side note: I learned about editing the hidden config file from an explanation from vw_kubel.

Sunday, February 15, 2009

PlayStation 3 Eye web cam working on Ubuntu 8.10!

When I heard about the PS3 Eye cam and what it's capable of, I immediately ordered one for my DIY multi touch table project! It can deliver a staggering 120 frames per second, and it's relatively cheap to other cameras that can do this. I ordered mine for 40 euros. The high frame rate allows for a smaller delay when processing (multi) touch input, see an example here. This beasty doesn't directly work out of the box, you need to get drivers first. In this post I'll be explaining how to get it working on Ubuntu and the problems I faced while installing the driver. If you are looking for drivers for the PS3 Eye on Windows or Mac, see this thread or this thread, respectively.

First, get the gspca modified driver from kaswy. Extract the source to a directory, e.g. ~/src/gspca-ps3eyeMT. Then issue the following command in a terminal:
$ lsmod | grep gspca
If this command gives you any output, you have to unload the module(s) first. The drivers loaded at the time gave me problems because my computer was running for a long time without rebooting. The loaded drivers were older, when I tried to load the new gspca driver, the two conflicted. So to be on the safe side, it's best you not skip this step. This is an example possible output:

(Columns are: Module, Size, Used by)

You want to unload the driver that has a 0 in the third column, this unloads the drivers recursively. It's done like this according to the example:
$ sudo modprobe -r gspca_pac207
Verify the driver is unloaded by doing a
$ lsmod | grep gspca
Now, there should be no output.

If you haven't already, get the build tools for Ubuntu with the following command:
$ sudo apt-get install build-essential
Next, we can start compiling, that's done like this:
$ cd ~/src/gspca-ps3eyeMT
$ make
$ sudo make install
The building process may contain some warnings, but it should finish without errors (some terminology: a warning isn't as bad as an error and warnings should not prevent a successful build).

Now we load the driver, the working modes for the web cam are:
00: 640x480@15
01: 640x480@30
02: 640x480@40
03: 640x480@50
04: 640x480@60
10: 320x240@30
11: 320x240@40
12: 320x240@50
13: 320x240@60
14: 320x240@75
15: 320x240@100 (added 15/02/09 V0.3)
16: 320x240@125 (added 15/02/09 V0.3)
Say we want to use the mode 640x480 pixels at 60 frames per second (mode 04), we issue the following command:
$ sudo modprobe gspca_ov534 videomode=04
This loads the driver and sets the desired video mode. Adjust the video mode to your own preference.

Next, we can plug in the PS3 Eye camera. We can verify that it has been plugged in by doing a
$ ls /dev/video*
before you plug in the camera, and then run it again after it's plugged in. It should display a(nother) video device, e.g. /dev/video0.

To preview the stream, we're going to use VLC, this is an excellent media player, if you don't have it installed, you can simply get it with:
$ sudo apt-get install vlc

Finally, we can open the web cam's video stream:
$ vlc v4l2:///dev/video0
(change /dev/video0 to the correct device if you have more than 1 video device plugged in.)
Voila, you should now have a video feed from the PS3 Eye on Ubuntu! Enjoy!

Update 18-feb-09: new driver V0.3 released by kaswy on 15-feb-09, new video modes added! See this post on how to update.

Side note #1: credit to kaswy for helping me install his drivers. This is the thread on forums about the PS3 Eye drivers. There is another driver, but kaswy's is the most promising at the moment.

Side note #2: you may unload the drivers with the following command:
$ sudo modprobe -r gspca_ov534
And you may uninstall the drivers by running the following command from the source dir you installed from:
$ sudo make rminstall

DIY Multi Touch table

I started a new project (well, I actually started it a long time ago and I'm now resuming it). It's a do-it-yourself multi touch table! Take a look at the following movie to get an idea of what a Multi Touch device is, it inspired me to build my own:

I'm building a table that uses FTIR and has a 80 cm x 60 cm screen, my test machine is running Ubuntu 8.10, Intel quadcore Q9550, 4 GB of RAM and a nVidia 9800GTX+ 512MB video card.

It'll be a challenge to get this working on Linux, as this hasn't been done/documented a lot before. Documenting my progress on Linux will be my gift back to the multi touch community that is out there!

When the table is finished, I also want to write software for it that makes use of multi touch (it's kind of boring to have a MT table with single touch programs on it!)

Sunday, February 1, 2009

Getting the tools for Java, Bluetooth, MIDlet and Serial port

Before we dive into the source code, I thought it would be a good idea to explain where to get the tools needed for developing mobile applications. These are the tools:
  • Java Development Kit
  • Eclipse
  • Sun Java Wireless Toolkit for CLDC
  • EclipseME
  • Bluecove (java bluetooth library)
  • Java Runtime Environment for your mobile phone
  • RXTX (serial port library)
The best part is, is that these tools are supposed to be working on Windows, Linux and Mac OS! (I haven't tested that, though!)

Java Development Kit (JDK)
The application is coded in Java, and so are MIDlets. You can get a JDK from Sun or openJDK. Mac OS already has a JDK installed by default. At the time of writing, I'm using openJDK 6 on Ubuntu.

You should have heard about Eclipse before, if you haven't, try a quick Google search to find out more about it. In short: it's an open source IDE, we'll be doing all of the coding with this program. Go to their download page and download Eclipse IDE for Java EE Developers (~160 MB). Always download the latest version, but FYI I used Eclipse 3.4 a.k.a. Ganymede.

Sun Java Wireless Toolkit for CLDC
We are going to use this toolkit to run our MIDlets in an emulated device, get it here. Update: there is no official support for Mac OS, but this guy seems to have got it working.

EclipseME is an Eclipse plugin to help develop J2ME MIDlets. On their site there is a very detailed installation guide. In short:
Make sure you downloaded and installed Eclipse and the Sun Java Wireless Toolkit for CLDC first. Use the update manager in Eclipse to install EclipseME (it's all covered in the installation guide).

BlueCove is a Java library for Bluetooth (JSR-82 implementation), without such a library we are unable to use Bluetooth in our applications. Here's the download link. You need only one or two files depending on your operating system. Windows/Mac users only need bluecove-x.x.x.jar, Linux users also need the bluecove-gpl-x.x.x.jar file. (Latest stable version at time of writing: 2.1.0.)

Java Runtime Environment (JRE) for your mobile phone
A lot of devices come with a JRE nowadays, however, not all those devices support the Bluetooth specification, also known as JSR-82. That means that even if your device has Bluetooth, you would not be able to use it with your Java application. Check your device manual or see this (incomplete afaik) list of devices which support JSR-82 natively, if your device has a JSR-82 implementation, you're in luck.
If your device does not have a JRE, you have to install one yourself if possible. If it's not possible, you will have to look for another device to test it on. Note that you do not need to have a JRE on your device to begin writing and testing the application, but I recommend you install it, without it, you won't be able to fully test your application (I'll disclose why in another post). phoneME is a very promising JRE for Windows Mobile. Precompiled binaries are available here, make sure you download the phoneME Advanced Dual Stack version, the other versions are not capable of supporting Bluetooth and MIDlets. You need to copy a few files from Bluecove into the phoneME installation to enable the Bluetooth library on your Windows Mobile device, see this description.
If you're interested in more information about phoneME, you can also visit the official phoneME project website. As an alternative to phoneME, you can also download Mysaifu JVM (currently version 0.4.1). This JRE cannot run MIDlets, though, but it can run Bluetooth enabled applications in combination with Bluecove. I do not have any experience with other mobile device operating systems, so if you do not have Windows Mobile and do not have a JSR-82 capable device, you'll have to do a little research of your own.

RXTX (serial port library)
We are going to address the serial port directly with Java. (Yes, you can send data to the serial port from command line, but who'd use such a crude programming method? :) ) We need the RXTX library for this, get it here. If you're on Ubuntu, you can install the package 'librxtx-java', the library will be available at /usr/share/java/RXTXcomm.jar.

When you downloaded and installed all the software, you're ready to start your first project (e.g. Bluetooth application). I will cover this another time.

Wednesday, January 28, 2009

Finally, the serial port is interfaced

The Transmit Data pin (#3) will require a little more attention. How will the signal (in other words: the wave) be interpreted by the IC? I'll be sending data according to the RS232. The signal is a block type wave, a 0 bit is represented as positive voltage (also called a “space”), a 1 bit is represented as negative voltage (called a “mark”). Furthermore, if the data line is idle, the signal is “spacing” (meaning, it's negative). How a byte is sent, depends on the following parameters: baud rate, byte encoding (e.g. 7-bit or 8-bit), presence of the parity bit (which is optional) and the number of stop bits. I stuck with the default parameters and thus didn't give them any special attention.

Let's visualize how this wave will look like:

Now that I know how it's looks like, I can modify it to my liking. First of all, I do not want it to send out a signal when the line is idle (or else my front door would be open all the time!). This is accomplished by adding a diode to the TD wire. This means that I can only use the positive signal to send to my front door switch. Next, whenever I send a byte out the serial port, I'd like it to be as continuous as possible. Therefore I send out only 0 bits, this is called a null character.

Serial ports cannot give a lot of amps, and I actually don't know how much amps my front door system will ask of my serial port (or even if it will ask any at all) once the current starts flowing. As it turns out, anything below 500 mA should be safe, so that's the rated current for my fuse (if it breaks I'll know my front door system sucks out to much juice and I'll have to come up with something else).

Finally, I know how the entire picture looks like, here's how it looks like schematically:

(click for larger image)

It's all in place, it's time to test for the first time if all my research that I've done so far will suffice! I plugged in the connector, fired up a prompt, and elegantly typed:
$ echo 0 > /dev/ttyS0
Side note: I'm actually sending out the bits 0110000 (= ASCII code 48 = 0). I was anxious to try it out and I couldn't be bothered at the time on finding out how to send a null character to my serial port from command line :-) (which is "echo -en \\0000 > /dev/ttyS0" on Linux, btw.)

Side note #2: /dev/ttyS0 is the serial port under Linux, doing a “echo 0 > COM1” in Windows will have the same effect.

W000000000000000T! My doors opened! I couldn't believe it! So naturally I tried it again, hmm, that's odd, the doors didn't open...

My first assumption was that the fuse had blown, so I checked that, but it wasn't. Next, I tried to echo data to the serial port again, and again, and again, but this time with more bytes:
$ echo 0000000000000000 > /dev/ttyS0
That worked! Apparently the front door black box system has to receive the signal at a given moment for a given amount of time, or else the door will not open. I just was VERY lucky that it opened on the first time, with just sending 1 byte (or else I might have assumed something wasn't working and I'd be stuck for a long time figuring this out). Maybe that adjusting the baud rate of the port would solve this problem, but I'll settle for sending more bytes (so I can send “I AM 1337! 101100111001!” to my front door, and it opens in fear of me :-))

So far so good, this was the easy part! I'll be posting about my Java Bluetooth application for my server and phone in a short while.

Tuesday, January 27, 2009

Never buy indentical Bluetooth adapters

I recently bought 2 Bluetooth adapters, so that I could test between 2 computers. However, both adapters have the same MAC address, and you cannot pair to your own MAC address, yay! So here's a piece of advice, when buying 2 adapters for testing, do not buy identical ones! ;-)

So far I haven't found out how to change the MAC address of the adapter, if anyone has a suggestion, I'm more than happy to hear it. The brand is Qmotion.

Monday, January 26, 2009

Further research on how to interface the serial port

I choose the 9-pin serial port, so how do I proceed now? I asked myself the following questions:
  • What does each of the 9 pins do?
  • Which pins do I actually need?
  • What will my cable look like?
  • What does the signal coming from the data pin look like?
The connector
So I fired up Google, did a search on “serial port” and lots of information about the connectors showed up, I'll summarize it here (for the 9-pin variant):

Pin #






Carrier Detect

Used by modem to signal that it is connected to a working phone line.



Receive Data

Local device receives data sent from the other device.



Transmit Data

Local device transmits data to the device at the other end.



Data Terminal Ready

Local device sends a signal that it is ready to transmit.



Signal Ground




Data Set Ready

Remote device signals if it's ready to transmit.



Request To Send

Local device requests if remote device is ready to receive data.



Clear To Send

Remote device acknowledges that it's ready to receive data.



Ring Indicator

Used by modem to indicate that it has detected a ringing signal on the phone line.

Well, since my IC is not a modem, I am not going to use pins 1 and 9. My IC does not send feedback, so that excludes pin 2. So far, that leaves pins 3 – 8. Let's examine pins 4 and 6 a little closer: pin 4 sends a signal out that to tell that it's ready to transmit, and pin 6 is waiting for an incoming signal which means the other device is also ready to transmit. The IC is ready to receive data at any given time, so I will connect pin 4 to pin 6, which in fact tells the port that it's ready to transmit as soon the computer itself is ready. I also will connect pin 7 to pin 8 (check out the table to see why that is). Pin 5, I will leave this pin unconnected, since my IC is already grounded at another point. And last but not least, the Transmit Data pin (#3) will be used to send data to the IC.

So the connector which goes into my computer will look like this:

Side note: there are 9 pin connectors which are easy to disassemble, specially designed to be altered to your own needs. I used one that looks like this:

Side note #2: on Ubuntu, I used the program “statserial” to inspect the idle state of my serial port, when my connector was connected.

The question remaining here, is how does the signal (or wave) coming from the TD pin look like? I will be going into more detail about this in my next post. Stay tuned!