Python on the Nokia N900



One of the really attractive things about the N900 is the possibility of customising it. You see, I’m a bit of a geek at times. A nerd, if you will. And the idea of being able to tweak the way my phone works appeals to me, whether it be in fixing a bug I find in an app or out-and-out writing a new one for something the manufacturer hadn’t though of (and I think a lot of the iPhone’s appeal to geeks is represented by that too, app store policy issues aside). But that’s not an option on symbian. First off, well, programming for symbian is fairly horrible; and secondly, you’d need the source code to the app which most companies aren’t going to provide without a rather large chunk of change.

But the N900 runs linux and therefore it should be really easy to code for (if you’ve written code on linux before). And since Python is one of the easier ways to write an application, I wondered how long it would take me to get up and running with Python on the N900, from nothing installed through to getting “Hello, World” running. So here’s how it went.

Start the clock at 1300h. After a brief google search, I open this blog post and the PyMaemo quick start guide. Right, there are two options:

1. Don’t install any complex cross-compiling environment, just develop the python code on your desktop machine and then just scp the .py file(s) to the N900 and run the application from there (this requires that you’ve installed the OpenSSH package on the N900, which I had already).

2. Go the whole hog with scratchbox and set up the full Maemo5 SDK and be able to run apps on the desktop in an emulated N900 environment for test/debug purposes.

Okay, it’s 1308h so let’s do the first route just to see how long it takes.  I download and install the the Personal IP desktop widget to see what the N900’s IP is, and then ssh to it (I have a minor hassle with trying to ssh to the N900 when it’s on its 3G IP address, which you can’t do for networking reasons; so I put it on the local wireless lan and the problem goes away).

Copy hello.py (stolen from the maemo.org wiki) to the N900 with scp.

[cc escaped=”true” lang=”python”]

import gtk
from gtk import Window, Button, Widget

if __name__ == "__main__":
    window = Window(gtk.WINDOW_TOPLEVEL)
    window.connect("destroy", gtk.main_quit)
    button = Button("Hello World")
    button.connect_object("clicked", Widget.destroy, window)
    window.add(button)
    window.show_all()
    gtk.main()

[/cc]

Then from the ssh session into the N900 I run [cci]python hello.py[/cci] and then hit Ctrl-Shift-P to take a screenshot and haul this out of /home/user/MyDocs/.images/Screenshots using scp:

HelloWorld.py

HelloWorld.py Screenshot

That’s 27 minutes from absolutely nothing to “Hello, World” on an embedded system. While eating lunch and blogging my steps. Can I just say that the N900 rocks for this alone?

Okay, but it’s not a real cross-platform dev environment. So next up, route 2 – the full Maemo5 SDK and scratchbox.

Scratchbox, for those who’ve never heard of it, is the emulated N900 environment, which uses Xephyr (an X-within-X server) for the display. It proved a little tricky to install on my laptop, because I’m running on a 64-bit platform. Here’s what I did:

sudo apt-get install xserver-xephyr

That’s all it took for Xephyr, but the Maemo SDK was a wee bit more annoying.

wget http://repository.maemo.org/stable/5.0/maemo-sdk-install-wizard_5.0.py
chmod a+x maemo-sdk-install-wizard_5.0.py
sudo ./maemo-sdk-install-wizard_5.0.py

PyMaemo SDK Installation Screenshot

From here it’s just a straightforward wizard installation:

PyMaemo SDK Installation Screenshot
PyMaemo SDK Installation Screenshot
PyMaemo SDK Installation Screenshot
PyMaemo SDK Installation Screenshot
PyMaemo SDK Installation Screenshot

Quite a few EULAs, but eventually the real work gets going…

PyMaemo SDK Installation Screenshot

And at this point, you go off and make a cup of tea while it all downloads. This runs for a half-hour or so on my network connection until (the clock’s at 1414h for those keeping score)…

PyMaemo SDK Installation Screenshot

So the install failed. A bit of digging reveals that the wierd assertion error that caused the bug (you can see it in the screenshot there) is a 32bit -v- 64bit problem. This is overcome with a boot kernel option so I re-ran the install wizard to uninstall what it had installed, then rebooted and used the GRUB editor to set vdso32=0 in the boot options for the kernel and let it boot up. You can, of course, find other more permanent ways to do that, and it can be done via sysctl.conf as well if your kernel is version 2.6.24 or earlier (mine’s 2.6.30 so no hope there, has to be done by boot parameter).

Once that was done and we’d rebooted, I re-ran the install wizard. It does takes a lot of time (it’s woefully optimistic about installing inside of 20 minutes), but it needs no input, so you’re free to get some coffee or read away…

PyMaemo SDK Installation Screenshot

Until it finally succeeds.

PyMaemo SDK Installation Screenshot

The clock’s now at 1714h for those keeping score. The next job is to fire up the development environment. This starts off easy enough:

Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac &
ln -s /scratchbox/users/mdennehy/home/mdennehy scratchbox
cp /tmp/hello.py scratchbox/MyDocs/
/scratchbox/login
export DISPLAY=:2
af-sb-init.sh start

And there we are, the emulated N900 device starts up:

PyMaemo SDK Installation Screenshot - Emulated N900

Now to run the app is a bit more complicated, you have to add the python SDK to the emulated device too. First, ensure the following lines are in its sources.list file:

deb http://repository.maemo.org/extras-devel fremantle free non-free
deb-src http://repository.maemo.org/extras-devel fremantle free

Then update and install:

apt-get update
apt-get install python-gtk2 python-sdk

And finally, run the python script (which you can just copy from your $HOME to the directory in the emulated N900).

run-standalone.sh python2.5 hello.py

HelloWorld.py on ScratchBox

HelloWorld.py on ScratchBox

And don’t forget to shut the door and turn out the lights once you’re done:

af-sb-init.sh stop
exit

That took until 1815h, but most of the delay was in setup; actual code hassles were nonexistant. That’s remarkable for an embedded platform like this. 27 minutes to get a basic app running; an afternoon (most of it spent doing other stuff while stuff downloaded) to get the full development environment (with emulator) up and running. Simply excellent. The N900 really is a very good platform for development work, especially with Python.

Tags: , , , , , ,

12 comments

  1. […] This post was mentioned on Twitter by Mark Dennehy, Mark Dennehy. Mark Dennehy said: #StochasticGeometry Python on the Nokia N900: Subscribe to the comments for this post? Add this to … http://bit.ly/d5GIAx […]

  2. I was going to blog about it you did before me :D One of the nicest thing with N900 is you can establish USB, Bluetooth, Wireless networks between your computer (using PC-Connectivity package). I have figured out establishing Bluetooth and Wireless on my Fedora 12. I will yet to learn USB network procedure. From then on ssh, scp, sftp and especially vnc’ing makes accessing the device super convenient. If you can setup VNC you don’t need any scracthbox environment to develop test your code since no compilation necessary to run Python code. (Lastly, your links are broken)

  3. Thanks Gökhan, I think all the links are fixed now.

  4. I’m new to Python and pretty excited to learn more as I go along. But I can’t help wondering “what’s the point?”. So you got Python onto this device, what you going to do with it? Are there features that you can add via Python that the phone doesn’t already have, or can you speed the phone up or something? Or is it purely a case of getting Python on the phone?

  5. I was hoping to tweak Witter (the twitter client) a bit; but many of the apps on the N900 are written in Python. gPodder – the best podcast client on the N900 – is written in python, for example. But the main point of the post was to walk through getting set up on the N900 with a python dev environment so that the next person to try has more material to work with.

  6. Randle TaylorNo Gravatar

    Great post! I wish it was easy to use python for development on other phones too.

  7. As a python addict, I bought this phone just to pythonize at street :D (Ho my god, i’m a geek ?!)
    Very good post.

    Althought, I saw that some hildon widgets do not seem to work with the scracthbox (e.g. PickerButton).
    I’ll think to the Gökhan’s alternative …

  8. I actually use VNC-Server on my N900 openSSH. I develop on my Linux via SSH and test my application with VNC ( i have to say that it lag but i’m ok with that ).
    Nice tutorial.

  9. […] at Stochastic Geometry has written a post for the more – shall we say – complex-minded amongst […]

  10. Awesome post Mark. I am quite keen to follow your route so a very big thank you for taking the time to write a step by step guide.

  11. feck it, this n900 is a mighty piece of machine. looks like way better than PyS60 with its cumbersome UI

  12. Richard CookeNo Gravatar

    It is maybe an inconvenient truth that you could get pyS60 running on a Symbian device in a similar amount of time…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


WordPress database error: [Duplicate entry '8388607' for key 1]
INSERT INTO `wp_latencytracker` (`longdatetime`,`qcount`,`qtime`,`qpage`,`qmemory`,`useragent`) VALUES ('2014-11-27 02:34:48','29','1.215','http://www.stochasticgeometry.ie/2010/04/29/python-on-the-nokia-n900/','47.673','CCBot/2.0 (http://commoncrawl.org/faq/)')

Stochastic Geometry is Stephen Fry proof thanks to caching by WP Super Cache