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.