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!

Determining which port to interface on

There are multiple ports on a computer to which you can interface, each has it's own pros and cons. My requirements were as follow:
  • it must be cheap,
  • it must be able to operate over distances greater than 10 meters,
  • I prefer not to use soldering iron extensively, because I suck at it :-) (note to self: take a soldering course).
I opted for the serial port, since I only needed 1 output pin which either has a signal or no signal; and it's cheaper compared to the other options. There were 3 ports which came to mind when deciding which one to use:
  • Parallel port
  • Serial port (also known as the COM port)
  • USB port
Let's review their characteristics first:

Parallel port
The parallel port offers 8 pins for data (it can send 8 bits, 1 byte, at the same time, hence the name parallel port). A bit with the value 1 is represented as a 5V signal, and a 0 bit is simply no voltage (0 V). 5V is perfect to work with, since IC do not require a high voltage. This port has 25 (!) pins in total and the male side of this cable has 36 pins (soldering hell!!).

Serial port
This port has 2 data pins, namely a read pin and a write pin. The total number of pins is 9. Not all pins need to be connected, hence a cable for this port is easily self-constructed and relatively cheap compared to a parallel cable. The data pins can deliver a voltage between -25 V and +25V, so a 50V peak-peak voltage can be drawn from this port. Note that a lower voltage may be drawn (it usually operates at ± 5 - 12 V), which is more desirable.

USB port
This one is tricky, I realized that when you connect an USB-device, the operating system usually asks the device what kind of device it is and other sorts of information. So in order to provide this information to the OS, you need an USB micro controller. I don't have an exact price range for this kind of hardware, but a quick search at my favorite supplier told me they have USB micro controller starter kits in the range of 65 – 200 Euro. (The actual controller itself is cheaper, but since neither the intended audience, or myself for that matter, has a clue how to use that thing, it's likely we need the starters kit which has some examples and documentation with it). The USB port has 4 pins, 2 for the power circuit which gives a continues ~5V and the other 2 are for data transmission.

Side note: In my case, I used an external power source for the IC, so I did not need to pay attention to the maximum amount of amps I can draw from the port, if you're planning on using the port as a power source, find out how much it can supply before it fries (it's usually not very high).

So the serial port is the cheapest option, requires the least amount of soldering and since I can create my own cable, it will be possible to make it over 10 meters long. Perfect!

In my next post I will explain how to create the connector.

Sunday, January 25, 2009

Integrated Circuit to open the front door

I'm blessed with a home that has an automatic sliding door, and these generally come with a button that opens the door from the inside (our door is set not to open on proximity, since the entrance is unmonitored). Of course, if you have a door that has to be manually operated, you'd have to create your own opening mechanism, which I won't be writing about (at least not anytime soon). The button looks like this:

(click for larger image)

The red arrows indicate the contact points. What happens when the button is pressed, is that a contact is made and the door opens. What we want to achieve is simulate that the button has been pressed by creating the contact ourselves (no, not by creating a robot with wi-fi that presses the button on command, there is an easier way ;-)). We can do this simply by the means of a transistor and it would look like this:

This diagram is made with KTechlab (linux users), by the way. If you're a Windows user and want to simulate a circuit, try getting your hands on a student license for Multisim if your university offers this. You can also download a trial.

Come to think of it, I wasn't entirely accurate about the "simply" part. It was possible in my situation to use a (NPN) transistor, but I had to account for the following:

Let's examine the transistor I used a little closer, it has 3 terminals: Collector, Emitter and Base. As the symbol indicates, the current can flow from C to E, but not the other way around from E to C (if you don't have a clue why, that arrow is called a diode and it only allows current to pass in the direction the arrow is in; but then again you probably should know that). This means that only a Direct Current (DC) is allowed to pass! Hmm, wait a second, do I know for sure that the circuit that controls the door operates on DC? No, I don't! So, I get out my multimeter and test for it (which I had to buy for this purpose, but I didn't think it would be the last time I used it, so I decided it was worth it. Those things are cheaper than you'd expect, I got one for 8 euro at a local shop I deem expensive). As it turns out, the door switch circuit operates on AC (the voltage on the switch was about 82 Volts).

But, if I send a direct current (DC) in the right direction, the door opens anyway. Lucky me! I found this out while doing measurements with the "Diode and buzzer" setting on my multimeter. What this setting does is, that it allows a DC to pass, and when it does, the buzzer sounds to indicate that the two points are connected. (If this doesn't work for you, you need a relay instead of a transistor, which allows for AC to flow. Mirror in case of failure.) So when putting the transistor in place, I have to take notice that the DC that activates the door switch is allowed to pass.

Later on, we will see that interfacing this IC to a computer, will need some precautions that are not yet shown here.

If you want to learn more about transistors, Wikipedia is always a good place to start and Google (click for search results on "Transistor") is your best friend.

Open front door using Bluetooth

Well, this is the start of a description of a project I recently finished! I can open my front door, without even touching the door, using my phone! Here is a preview of what I used for this and what's to come on this blog:

- Java MIDlet on my phone,
- Java application on a server near the front door that listens for incoming requests,
- Integrated Circuit (IC) which opens up the front door,
- Interface to that IC, using the serial port of the server.

Check out the video below to see it working in action!

Note: click on the tag Project Open Sesame for all posts related to this project.


Welcome to the 10100111001est (that's 1337est in binary ;-)) blog in the world! You guessed it, it's a geek blog! The purpose of this blog is actually very simple: when I look on the internet, I see all kind of cool home projects and I wonder "how do they do that?!" (e.g. DIY multi touch table). There is only one thing to do for a nerd who asks that question to himself/herself: find the answer :-)

This blog is about projects I do in my spare time and it will describe them in more detail than you would find on other sites. These are just a few examples of what you will be able to find here:
- interface custom made Integrated Circuits to your PC,
- how to build a multi touch table,
- how I managed to open my front door, just by pressing a button on my phone (awesome!!),
- MIDlet on my phone to remote control my media player,
- fun things to do with a Wii Remote,
- more!

Ultimately, this blog will be a source for people like me who want to create cool things, but don't have a clue about where to start (like me most of the time) and it'll save them some time by looking at my experiences :-) Or better yet, inspire them to create even more mind-boggling projects!