Page 1 of 2
Running Python on your NXT
Posted: 14 Dec 2011, 00:20
by janosch_graef
Hi,
I started to write a new firmware which runs python. Actually it should only run compiled python programs (the ones from CPython) due to memory restrictions. I'll use PyMite, a python VM for embedded systems, which already has nice support for AT91SAM7S256. For the base OS and hardware drivers I'll use NxOS since it has very clean code and it's easy to create new kernels with it.
I'll also try to keep the USB/Bluetooth interface compatible with the one of the LEGO firmware and I'll use the same file formats for image, sound, melody files, etc.
Nevertheless I don't really know how fast this will run and how big programs could be. So this will be rather experimental. But I'm very optimistic and for as a python fan I just can't wait to run some python code on my NXT
Preliminary project name is "PythoNXT" short for Python on NXT. At the moment I haven't done very much, except setting up a development environment and writing a simple test program combining PyMite and NxOS. Now I first have to wait for LEGO to replace my NXT, since my display is broken.
Re: Running Python on your NXT
Posted: 14 Dec 2011, 07:28
by mightor
Very cool, I look forward to seeing what you'll do with this project!
- Xander
Re: Running Python on your NXT
Posted: 14 Dec 2011, 15:17
by HaWe
can you pls explain with a few words which advantages (and disadvantages) Python has got compared to NXC or Java?
Re: Running Python on your NXT
Posted: 14 Dec 2011, 20:28
by linusa
janosch_graef wrote:But I'm very optimistic and for as a python fan I just can't wait to run some python code on my NXT
Yeah, great attitude. Really liking this idea!
. Make sure to keep us posted!
doc-helmut wrote:can you pls explain with a few words which advantages (and disadvantages) Python has got compared to NXC or Java?
Biggest difference: Python is a weakly typed language (opposed to Java, C, NXC). Variables and function parameters don't get type information from the code, so simple example: You can pass a string or an integer. While you lose the compiler as safety net (no type checks), you gain flexibility.
This results in a flexible thing called "duck typing". If something acts like a duck, let's assume it's a duck. So if a method expects an object and calls its ".quack()" function, you can pass anything that has a .quack() function. You can even bind a quack-function dynamically to an object.
Another big pro is the "batteries included" principle: Huge standard library, well documented, always available (comparable to .net or Java).
Biggest disadvantage: Performance. It's slow. In Python you tend to write nice & compact code, but it's difficult to get a feeling for performance or "to write fast code" (but that's just my 2 cents).
Re: Running Python on your NXT
Posted: 15 Dec 2011, 15:24
by janosch_graef
linusa wrote:
Yeah, great attitude. Really liking this idea!
. Make sure to keep us posted!
Development is delayed at the moment until I've got a new NXT (display broken). At the latest I'll start coding in February when semester break begins. Eventually, I can borrow another NXT from a friend until I got a new one, then of course I could start coding ealier.
linusa wrote:
Another big pro is the "batteries included" principle: Huge standard library, well documented, always available (comparable to .net or Java).
Of course I won't port all modules of CPython to the NXT. I'll port some standard modules: io, os, sys and of course I'll write a module for controlling the NXT (nxt.motor, .sensor, .usb, ...). And later I'll possibly write some modules like navigation, behaviour, AI, etc.
If anyone wants to contribute to the project, I'll setup a GIT repository or even a Gobby server.
Re: Running Python on your NXT
Posted: 19 Dec 2011, 02:23
by tcwan
janosch_graef wrote:Hi,
Preliminary project name is "PythoNXT" short for Python on NXT. At the moment I haven't done very much, except setting up a development environment and writing a simple test program combining PyMite and NxOS. Now I first have to wait for LEGO to replace my NXT, since my display is broken.
Hi,
I'm using NxOS as the base for writing Assembly Language code on the NXT. Currently it is hosted on GitHUB as
https://github.com/tcwan/nxos-armdebug.
I've developed a firmware-based ARM instruction Debugger for the NXT, which is present in the nxos-armdebug project. If you host your code on GitHUB, I'd be interested in tracking your progress, and it'd make code exchange easier. I've merged in most of the NxOS variants hosted on Github into my code base.
With nxos-armdebug, you can use the USB connection (via the Fantom Drivers + nxt-python 2.2+
http://code.google.com/p/nxt-python/) for debugging with GDB.
if you're interested in finding out more please contact me.
Unfortunately I don't think I can contribute actively to your project right now, Python is cool but I'm still trying to flesh out the ARM assembly stuff for teaching my university level course on ARM assembly language programming.
(There's not been any update to the repository for the past 3 months due to teaching commitments, I hope to resume after the start of the new year).
Re: Running Python on your NXT
Posted: 05 Jan 2012, 19:22
by schodet
Great project, I also thinks that NxOS is a good base for new firmwares.
I look forward to see the first steps!
Re: Running Python on your NXT
Posted: 27 Jan 2012, 22:28
by jmarotta
Howdy!
I look forward to seeing the results of this - I've become a recent Python convert.
I should note - I'm having some trouble finding Bluetooth drivers for Python on my 64 bit Windows 7 desktop. You may find yourself writing a driver
.
Joe
Re: Running Python on your NXT
Posted: 05 Feb 2012, 15:24
by metadot
I'm sorry to say, but you are about to try something impossible. The NXT doesn't have enough RAM to run a Python interpreter.
I used to work for several years on a Python interpreter port to a mobile device. We tried hard to squeeze it as small as possible, but even then it was hundreds of kilobytes at a minimum. The NXT has 64 kB.
Re: Running Python on your NXT
Posted: 05 Feb 2012, 15:28
by metadot
After checking out the PyMite link, I sit corrected. Interesting!