Mark Easley TI 42 Posted December 13, 2013 Share Posted December 13, 2013 If you haven't seen this kickstarter: http://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers It just succeeded and the founder is going to release the source code eventually. He currently has it working on ARM Cortex Ms, so hopefully not a hard port to Tiva LaunchPad, but it would certainly be interesting to get a python parser running on 430. Quote Link to post Share on other sites
pabigot 355 Posted December 13, 2013 Share Posted December 13, 2013 Interesting. From that page: The Micro Python board is an electronics development board that runs Micro Python, and is based on the STM32F405 microcontroller. This microcontroller is one of the more powerful ones available, and was chosen so that Micro Python could run at its full potential. The microcontroller is clocked at 168MHz and has 1MiB flash and 192KiB RAM, which is plenty for writing complex Python scripts. The most capable MSP430 (Fxx59) is still 1/7th the clock speed, half the flash, and one third the RAM. It'd be quite a task to make it fit. Quote Link to post Share on other sites
LariSan 81 Posted December 13, 2013 Share Posted December 13, 2013 It's not a new concept that has been explored. Rice University actually has a port of Python on the Stellaris LM3S microcontrollers. : http://embeddedpython.org/index.php?title=The_Owl_Embedded_Python_System it would be interesting to see if they could further shrink the python overhead to work on smaller memory sizes. Quote Link to post Share on other sites
spirilis 1,265 Posted December 13, 2013 Share Posted December 13, 2013 Python seems to be all the rage these days. I must be getting grey hairs already or something 'cause I don't see why... I started learning it a year ago and put the book down out of boredom after a while. Didn't feel as expressive to me as C. Maybe less detailed though. But I've seen pretty amazing high-level projects built from it--most notably OpenStack, a cloud computing/virtualization management layer that has to marshal all kinds of different resources together. I'm at a loss to see how an MCU would fit into that type of project, unless the MCU is positioned as an API-compatible IoT type of gadget that reports into a larger system based on Python. In that case having common Python codebases between the MCU and higher-powered clients and server-side software could be an advantage. Quote Link to post Share on other sites
t0mpr1c3 91 Posted December 13, 2013 Share Posted December 13, 2013 I think lots of people are recommended to learn Python as their first programming language these days. It's become popular for statistical and scientific programming which is my field and it seems well suited for that because of the rich data types. In fact much of SciPy is written in Cython which compiles to C code and I would have thought that is the most suitable avenue for microcontrollers. Quote Link to post Share on other sites
pabigot 355 Posted December 13, 2013 Share Posted December 13, 2013 Yeah, I think that's why this all seems weird to me, too. I like Python a lot: AFAICT my PyXB project is the most advanced XML Schema bindings tool available for Python. But all the things that make Python a great language for higher-level programming (huge number of pre-existing libraries, advanced data structures, portability) are irrelevant in the low-power microcontroller world. As far as I can tell, C is the go-to language for MSP430-class microcontrollers. I don't use Energia, but see the value for folks who speak Arduino. I just can't see that Python makes sense given the incredible resource limitations. Personaly, I'm moving my development effort toward C++11: I think there's a huge potential for template metaprogramming for microcontrollers, since it simplifies maintenance while allowing a lot of compiler optimizations. I'm going to do that on ARM, though, because the toolchain support (and capabilities of the microcontrollers) are significantly more advanced than MSP430. (Energy Micro EFM32GG-STK3700: EFM32GG990F1024 MCU with 1 MB flash and 128 kB RAM, and all sorts of on-board sensors/interfaces, for $79. ARM-supported GCC toolchain and openOCD, so it's fully open source too.) spirilis 1 Quote Link to post Share on other sites
mpymike 18 Posted December 19, 2013 Share Posted December 19, 2013 I had to go for it! I signed up for one of the MicroPython boards. Really like the small breadboard friendly footprint and SD socket. For me the beauty of Python is that it is compact, readable, intuitive, and easy to learn. There are free libraries for just about everything. IMO using python is the quickest way of developing software. So porting it to microcontrollers is the holy grail. It is a shame that Python requires such a large memory footprint to run, putting it out of reach for the modest msp430s. With the MicroPython project the author has completely rewritten Python optimizing it for microcontroller use, specifically reducing the memory footprint. Even after doing this, his barebones print('hello world') example comes out to whopping 60k flash and 4k ram. My guess MicroPython will be suitable for microcontrollers with >256k flash and >32k ram. My own attempt at a python implementation (mpy) manages to get into an msp430, but only by throwing out most of the python language leaving just enough to do the simple stuff. bluehash 1 Quote Link to post Share on other sites
t0mpr1c3 91 Posted December 20, 2013 Share Posted December 20, 2013 If I wanted a completely portable language that ran on embedded devices, I would probably take a look at .NET. I think the memory constraints are similar to what you mention though. Some of the Java cross compilers get down pretty small. That's sort of what Arduino/Energia is. Quote Link to post Share on other sites
rockets4kids 204 Posted December 20, 2013 Share Posted December 20, 2013 For those unaware, Python is an interactive scripting language as opposed to a compiled language. Python is a nice scripting language, but there is nothing truly exceptional about the language itself. What makes Python so useful is its libraries. There is a Python library for practically everything. In fact, Python has finally caught up with (if not surpassed) Perl's CPAN library in this respect. If I recall correctly, MicroPython is nothing more than a scripting language with a Python-like syntax. It is not Python, and it will almost certainly not be able to use any of the Python library code. It's usability will be determined largely by the libraries that are (or become) available for it. I highly doubt it will be usable on anything but the higher-end MSP430 chips, if it even gets ported to the MSP430. Quote Link to post Share on other sites
t0mpr1c3 91 Posted December 20, 2013 Share Posted December 20, 2013 If I recall correctly, MicroPython is nothing more than a scripting language with a Python-like syntax. It is not Python, and it will almost certainly not be able to use any of the Python library code. It's usability will be determined largely by the libraries that are (or become) available for it. Hence the popularity of Arduino, I suppose. I'm not against Python-alikes that are compiled via C for microcontrollers but I imagine they will have the same relationship to Python proper as Arduino has to Java/Processing, i.e. superficially similar syntax to get you off the ground, and that's about it. Isn't the thing with scripting languages that you run them from inside an OS? Perhaps it is stretching the terminology, but it seems to me that the scripting language with the smallest footprint is probably FORTH because it includes its own shell. I'm not familiar with it at all but Mecrisp apparently works on an MSP430G2553. Quote Link to post Share on other sites
mpymike 18 Posted December 21, 2013 Share Posted December 21, 2013 MicroPython is a pretty full python implementation of the language. Setting aside the large memory footprint overhead, the main issue will be that it will lack all the libraries and especially the hardware libraries (at least initially) It will have a long way to go to catchup with the extensive Arduino/Energia selection. IMO describing Python as a scripting language is a bit meaningless. More relevant is the fact that most python implementations including MicroPython are byte code interpreted. The virtual machine is running on the microcontroller. That must account for a hefty chunk of the overhead. Quote Link to post Share on other sites
t0mpr1c3 91 Posted December 21, 2013 Share Posted December 21, 2013 It doesn't necessarily follow because FORTH and Java both use byte codes and have been implemented on smaller micros, and as mentioned previously quite large chunks of the code base are in Cython which is compilable. I suspect the large RAM usage is probably down to that though. Quote Link to post Share on other sites
rockets4kids 204 Posted December 21, 2013 Share Posted December 21, 2013 IMO describing Python as a scripting language is a bit meaningless. Most people associate scripting languages with interpreted languages, but I probably should have been more clear. MicroPython is a pretty full python implementation of the language. Do you have any links to a language specification and/or source code? A quick look did not reveal any... Quote Link to post Share on other sites
mpymike 18 Posted December 21, 2013 Share Posted December 21, 2013 @@t0mpr1c3 I think it depends on the size of the bytecode VM. As I remember, Forth is fairly simple and can fit onto a small uC. But I wasn't aware of any Java VM that can fit onto a small uC. If anyone knows of one I'd like to look at it. May even be suitable forJython. (which is Python running on a Java VM) @@rockets4kids The source is not released yet, but from his kickstarter page he describes it as: Micro Python has the following features: Full implementation of the Python 3 grammar (but not yet all of Python's standard libraries). Implements a lexer, parser, compiler, virtual machine and runtime. Can execute files, and also has a command line interface (a read-evaluate-print-loop, or REPL). Python code is compiled to a compressed byte code that runs on the built-in virtual machine. Memory usage is minimised by storing objects in efficient ways. Integers that fit in 31-bits do not allocate an object on the heap, and so require memory only on the stack. Using Python decorators, functions can be optionally compiled to native machine code, which takes more memory but runs around 2 times faster than byte code. Such functions still implement the complete Python language. A function can also be optionally compiled to use native machine integers as numbers, instead of Python objects. Such code runs at close to the speed of an equivalent C function, and can still be called from Python, and can still call Python. These functions can be used to perform time-critical procedures, such as interrupts. An implementation of inline assembler allows complete access to the underlying machine. Inline assembler functions can be called from Python as though they were a normal function. Memory is managed using a simple and fast mark-sweep garbage collector. It takes less than 4ms to perform a full collection. A lot of functions can be written to use no heap memory at all and therefore require no garbage collection.? The only other source of info I know of is comments page Quote Link to post Share on other sites
rockets4kids 204 Posted December 21, 2013 Share Posted December 21, 2013 Micro Python has the following features: In that case, I will be extremely surprised if it runs on *any* MSP430. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.