2010-11-13

Physics game @ codebits2010

I am currently at Codebits, were we tried to implement a physics game with Processing and Open CV. Here is the result:


Those were three funny days here! Code is available at github.

2010-11-07

The Arduino and The N900

I always thought about connecting an Arduino controller board to my N900, to have external sensor data available on the phone. My first attempt was quite successful now, I managed to send data of an Accelerometer via a serial bluetooth connection and just print the raw data in the N900 terminal. Everything is based on my first experiments with Arduino, which I built after a sample setup on heise.de. All I did now was add a Bluesmirf Modem to RX/TX pins of the Arduino board, change the power supply from USB to 4 attached AA batteries, et voilá: I just open a serial bluetooth connection on my N900 with Python and receive the data.

This is more or less a proof of concept for now, as only raw data is printed to the N900's terminal. And, of course, the N900 also has its own accelerometer.. Anyway, here is a sketch of the board:




The controller script is very basic and should be uploaded to the Arduino board through the Processing environment:

/*
 * Siehe auch:
 * http://www.arduino.cc/en/Tutorial/ADXL3xx
 */

// Definition der Pins des Beschleunigungssensors ADXL330
int xPin = 2;                     // X-Achse
int yPin = 1;                     // Y-Achse
int zPin = 0;                     // Z-Achse
int buttonPin = 2;                // Schalter

void setup() {                    // Initialisierung
  Serial.begin(115200);             // Serielle Verb., 9600 baud 
  pinMode(buttonPin, INPUT);      // Schalter-Pin als Eingang
}

void loop() {
  Serial.print(analogRead(xPin)); // X-Achse lesen, seriell ausg.
  Serial.print(" ");
  Serial.print(analogRead(yPin)); // Y-Achse
  Serial.print(" ");
  Serial.print(analogRead(zPin)); // Z-Achse
  Serial.print(" ");
  Serial.print(digitalRead(buttonPin));  // Schalter
  Serial.println();               // Zeilenvorschub
  delay(50);                      // 50 ms warten 
} 

It just reads out the sensor data and sends it to serial out every 50 miliseconds. The Python script that you should start on the N900 (may also work on desktops, I didn't try...):

import sys, os
import dbus
import glob
import termios, fcntl

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object("org.bluez", "/"),
      "org.bluez.Manager")

adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()),
       "org.bluez.Adapter")

address = "00:06:66:02:CC:89"
service = "spp"

path = adapter.FindDevice(address)

serial = dbus.Interface(bus.get_object("org.bluez", path),
      "org.bluez.Serial")

node = serial.Connect(service)

print "Connected %s to %s" % (node, address)

print "Press CTRL-C to disconnect"


a = open("/dev/rfcomm0","r")

fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)

oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)


try:
    while 1:
        w = a.readline()
        print w
        try:
            c = sys.stdin.read(1)
            if c == 'q':
                break
        except IOError: pass
finally:
    termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
    fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)

serial.Disconnect(node)

It uses the dbus Bluez drive on Linux to open a serial port. It just prints the data until you press the key "q". You must first connect the N900 to the Bluesmirf chip via the standard procedure to connect bluetooth devices on the N900. Here is a photo of everything running:





Next thing: connect other sensors to the Arduino board, to measure things like temperature and humidity. Have fun!

2010-11-06

What's this?



HAI
CAN HAS STDIO?
PLZ OPEN FILE "LOLCATS.TXT"?
    AWSUM THX
        VISIBLE FILE
    O NOES
        INVISIBLE "ERROR!"
KTHXBYE

LOLCODE. Haha!

2010-04-26

Qt for Dingux in download section

Yesterday I published a new download page with Qt libaries for Dingux on the Dingoo A320. Dingux is a Linux-based operating system for the mobile gaming console Dingoo A320. Available downloads are the Qt library and the game Asteroids, which I ported from the original Qt examples. Have fun with it!

2010-03-09

Neuer RSS-Feed für meinen Mikroblog

An alle, die's angeht: ab sofort habe ich eine neue RSS-URL für meinen Mikroblog-Feed. Die alte URL war "http://www.peterbouda.de/microblogs/index.atom", die neue URL ist:

http://mobileqt.de/microblogs/index.rss

Ich mache meine "private" Website unter peterbouda.de ab morgen statisch, damit ich auf dem Server mehr Speicherplatz für andere Ruby on Rails-Applikationen habe. Bisher lief alles mit Rails, aber außer dem Kontaktformular und dem Mikroblog-Feed braucht die Seite keine aktiven Inhalte. Das Kontaktformular fliegt raus und der Feed wandert auf eine andere URL. Danke für die Aufmerksamkeit.