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.

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).

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 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.

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)…

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…

Until it finally succeeds.

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:

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

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.

12 comments

[…] 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 […]

I was going to blog about it you did before me 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)

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?

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.