Python On A Microcontroller

The team at LeafLabs was looking for something cool to do with their new ARM development board. [AJ] asked if anyone had ever played around with Python, so [Dave] cooked up an implementation of PyMite and put it on a Maple board. While the writeup is only about blinking a LED with a microcontroller, they’re doing it with Python, interactively, and at runtime.

The build uses the Maple Native board the team is developing. The board has a 32-bit ARM chip with 1 Meg of RAM – more than enough horsepower to run PyMite. The tutorial for putting PyMite on a Maple is up on the LeafLabs wiki.

PyMite is theoretically able to control every pin on the Maple Native and do just about everything a regular Python distro can do. The LeafLabs team is still working on the necessary libraries for their board (although we don’t see anything on the Google code page), so right now only blinking the LED is supported. Still, it’s pretty cool to have Python in your pocket.

17 thoughts on “Python On A Microcontroller

  1. Hi Brian,

    Marti from LeafLabs here. Just a quick correction — while the Maple Native has 64 KB of on-chip RAM, it also has a 1 MB external SRAM chip built-in. The libraries are configured to work with it seamlessly, and the heap lives on it by default.

      1. Right, but usually when you say how much RAM something has, you mean to say “How much RAM does this board allow me to use?” and the answer to that question is over 1MB. :) People might be more interested in the Native if they knew it had so much headroom.

  2. I’ve never been a big fan of Python. the IDLE interpreter was terrible, (or at least was when I was using it in 2008/9) and the code just seems sloppy and disjointed.
    Obviously, however, I am in the minority, as people seem as obsessed with putting Python in places where it wasn’t as they do with Linux.
    So, congrats to the team at LeafLabs.

  3. I don’t see all this “python on a microcontroller” thing.

    For one, I tend to think of python as a high level language designed to ease software development at the expense of resources needed to run it, while microcontrollers are rather those “not really cpu” things that let you -and require- to optimize resource utilization.

    I mean, even C is quite the overkill for microcontrollers, if it wasn’t for the fact that coding in asm is such a PITA.

    1. Uh, assembly being a pain is literally the reason higher level* programming languages exist. You basically just said “I don’t understand why people use python” then explained the reason people use python. Why waste time doing low level bit wrangling when your project doesn’t require it?

      *Relative to assembly–I’m including both C and Python under this umbrella.

    2. Todays micro-controller was yesterdays processor (minus a bunch of OS related hw support) in terms of raw MIPS – and a 32bit 72MHz machine is plenty to run a thin python repl adapted for the purpose.

      But of course you’re right, the purpose of MCU’s is more than being cheap. They can meet real time constraints and interface with the real world in a way big OS-running systems cant.

      But the fact is that you only need that 72MHz, or meet that 1us deadline some of the time. Why not hand the rest of the nonsense over to something like python?

      You could develop you entire application as entirely event driven interrupt routines, in assembler, and give the main loop over to python for user i/o (always slow), debugging, config, system monitoring, etc. etc. etc.

      String manipulation is a particularly good example of something I almost never need to do quickly, is really painful in C, and trivial in python.

      And you if you run out of resources? well, you could nix python and drop back into asm, or you could just wait 6 months for the next chip generation. MCUs are still being made on old process tech, and they have a lot more room to get faster. Just check out the stm32F4s!

    3. Let us put modern computing power in perspective. In the late 70s DEC introduced the VAX 11/780. It was a super mini computer and supported many users at once using timesharing. It ran VMS and sometimes Unix. It was as fast as the IBM 360 mainframe and was a revolution at the time.
      It ran at 5mhz and supported up to 8 mb of ram.
      In other words we have more computing power than we know what do with so you might as well use some of that power to cut development time.
      Heck that Maple board is more powerful than the first computer I ran CAD on. It blows away the IBM AT and PDP-11. Their is no reason why you couldn’t run lisp on it if you wanted.

  4. Hi, nice work.
    But it would be really nice to make a script than send it to the module and run it.
    The module Telit gm-862 as a inside python script interpreter, all u have to do is write the script, compile than upload to the module. It can do lots of functions including IO’s control, serial, i2s, can control inside gsm and gps Module RAM is 1,9Mb and 1,2Mb for python usage.
    An ideia like that in this STM32 would be a really nice inovation.
    Python is high level and realy easy, so the ideia of running it on a microcontroller is great.
    Regards

Leave a Reply to crennCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.