Hacker News new | past | comments | ask | show | jobs | submit login
MicroPython: Python for microcontrollers (micropython.org)
103 points by bootload on May 17, 2015 | hide | past | favorite | 19 comments

thx for adding this @maxerickson, excellent read. Best bits I found reading this post [0]:

- inline assembler

- written in C99 ANSI C

- almost entire entire Py3 standard library.

nb: The original post url has 404'd, a link with this title is found at: https://mail.python.org/pipermail/python-list/2014-June/6857...

MicroPython has been ported to the esp8266: https://www.sparkfun.com/products/13252

which is a wifi-ready microcontroller that can be found on eBay for a few bucks:


If anyone wants to try it out, I wrote up a guide on how to compile and install the MicroPython firmware for the ESP8266: https://learn.adafruit.com/building-and-running-micropython-... Note that it's still very early in its development so it doesn't support all the functionality of other MicroPythong boards, but it does have enough implemented to start hacking around with it like blinking LEDs and connecting to internet services.

Also there is eLua for MCUs - http://www.eluaproject.net/

NodeMCU, Lua based ESP8266 WiFi development Kit.

It based on eLua.


explanation: ~ https://youtu.be/5LbgyDmRu9s (9m40s)

There's also http://www.tinypy.org/ which should be better known. It's not "for microcontrollers", but it is quite small - fits within 64k, mostly complete py2 language implementation, has a luaesque API and GC (that is, not reference counting).

I personally wouldn't consider a 168MHz Cortex-M4 as "microcontroller" level performance - it's in the same range as a 100MHz Pentium, and the desktops machines of the time could certainly run Python code without much difficulty.

Getting Python on something like an AVR or PIC18, that would be far more interesting...

Processing power is only one part of the equation, though. These Cortex processors are significantly more constrained in RAM and storage than computers of 1995. Run Python on a 100MHz Pentium with 192 KiB of RAM, I'll be impressed.

Python was ported to PalmOS, where it could run on a 16MHz CPU with 64KB of usable heap space: http://isr.uci.edu/projects/sensos/python/

Palm OS3 indeed (1998). I didn't see Python on Nokia, PyS60 till 2005:

- S60 https://en.wikipedia.org/wiki/Python_for_S60

- S60 http://www.onlamp.com/pub/a/python/2005/04/14/s60.html

- N73 https://rubayeet.wordpress.com/2009/01/30/installing-python-...

I never did see any real usage aside from one of the flickr devs using an N75 to upload/query flickr via Python.

That's golden news! ("news" in a sense "new is well forgotten old"). I heard about bunch of previous small Python implementations, but never about that one. As a MicroPython contributor, I'd be proud to think of it as MicroPython's spiritual ancestor. It is even an 1.5.2 port, wouldn't think someone attempted to space-optimize CPython (MicroPython is developed from scratch, CPython3 hardly could be shrunk into that).

For you reference, MicroPython can start up in as little as 2K of heap. Of course, one hardly can execute something more than a simple expression like "1+1" in that memory, but 2K also include memory required for interactive interpreter (and parsing into AST and compiling into bytecode).

It's still interesting as an educational platform. For instance, being able to switch into assembly-style code in context with other high-level functionality can help communicate some key programming concepts.


> Getting Python on something like an AVR or PIC18, that would be far more interesting...

Are you sure it would be more interesting? We have people asking (and working!) for more ARM, MIPS ports, but nobody ever asked about AVR port, so maybe it's not that interesting, even though ATmega2560 should be able to fit it. No ATtiny or PIC18 ports on the horizon, sorry ;-), but PIC24 port exists.

Anyway, if you'd like to see MicroPython run on smaller devices, please consider contributing to the project - we love optimization freaks ;-). Current minimal requirements are 128K flash (50K for your code), 8K RAM.

PyMite aka python-on-a-chip targets 8-bit microcontrollers:



Yes, but PyMite is not a Python, it's a Python-like language - there're too many features lacking (e.g. proper exception support) to develop Python applications comfortably. And to clarify, MicroPython targets any environment with ANSI C99 support. It will work on 8-bit or even 1-bit microcontrollers, given enough code storage and RAM.

Anyone know of a Python equivalent to Lua / LuaJIT or Duktape for JS? I just really like drop-in single source file scripting environments. This looks close.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact