Python For Maemo 5 Info

The python used in the Nokia N900 is known as PyMaemo. It is basically the normal python, with additional device related commands.

API Documentation (non-pythonic): Maemo 5 Api Docs

Python Tutorials: Python for newbies

It is also possible to access C APIs that don't have Python bindings. However, this can bring some interesting problems. Not recommended, as most of the maemo APIs should work just fine with Python. However, check Accessing APIs without Python bindings for more info.

Playing Sounds

Playing sounds here

Using Microphone

Mic stuff goes here

Using Camera

Camera stuff here

Bluetooth

Bluetooth stuff here

Using Accelerometer

Download this source from here: Accelerometer.py

""" Created August 9, 2011 @author: Janne Parkkila @contact: japskua@gmail.com @summary: This file contains class implementation on connecting to maemo dbus and receiving accelerometer data """ import dbus class Accelerometer(object): """ @summary: This class is used to get accelerometer data from the dbus """ bus = None accelerometer = None def __init__(self): """ @summary: The Constructor for the class """ self.bus = dbus.SystemBus() self.accelerometer = self.bus.get_object("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request") def getData(self): """ @summary: This function returns the data of the accelerometer @return: orientation, stand, face, x, y, z @rtype: list """ return self.accelerometer.get_device_orientation() def displayData(self): """ @summary: This function is just used to display data """ orientation, stand, face, x, y, z = self.getData() print "Orientation: ", orientation print "Stand: ", stand print "Face: ", face print "X: ", x print "Y: ", y print "Z: ", z # This is only if we want to run the accelerometer test straight from the command line if __name__ == "__main__": print "Starting the Accelerometer test" accel = Accelerometer() accel.displayData()

Using Location API

Note: The python location might not be installed on the device. In this case, you need to install it with apt-get install python-location

IMPORTANT TO NOTICE The GPS on the N900 is not very fast! Acquiring a signal can take a great amount of time. Thus it is just recommended to simulate this in some other manner. The probability of receiving a signal in the basement is really small, so please, don't waste too much of your precious time with this.

More info on location API with pyMaemo can be found from PyMaemo Location API at maemo wiki

The following file is brutally ripped from the Maemo wiki:

import location import gobject def on_error(control, error, data): print "location error: %d... quitting" % error data.quit() def on_changed(device, data): if not device: return if device.fix: if device.fix[1] & location.GPS_DEVICE_LATLONG_SET: print "lat = %f, long = %f" % device.fix[4:6] # data.stop() commented out to allow continuous loop for a reliable fix - press ctrl c to break the loop, or program your own way of exiting) def on_stop(control, data): print "quitting" data.quit() def start_location(data): data.start() return False loop = gobject.MainLoop() control = location.GPSDControl.get_default() device = location.GPSDevice() control.set_properties(preferred_method=location.METHOD_USER_SELECTED, preferred_interval=location.INTERVAL_DEFAULT) control.connect("error-verbose", on_error, loop) device.connect("changed", on_changed, control) control.connect("gpsd-stopped", on_stop, loop) gobject.idle_add(start_location, control) loop.run()