Virtual Machine For Microcontrollers Lets You Run Python On AVR Chips

[Clifford Wolf] wrote in to let us know about a project he recently completed called EmbedVM. It’s a virtual machine for AVR microcontrollers. The package has a relatively small overhead, taking up about 3kB of program memory. The VM can execute 74,000 instructions per second, and runs asynchronously from the microcontroller. As [Clifford] demonstrates in the videos after the break, this can be handy for preloading commands to prevent slowdown during heavy VM processor loads.

The snippet in the image above is an example program written in the C-like VM code which will play some [Rick Astley] on a speaker. This code can be run from RAM, EEPROM, or even external storage like an SD card. Recently there was a supplemental compiler project that even takes Python code and compiles it into VM byte-code. What a nice abstraction tool for making inexpensive microcontroller-based designs easily programmable for those that have a bit of Python experience.

If you don’t recognize the name, [Clifford Wolf] is also the author of OpenSCAD, a tool that is quite popular with 3D printing.



23 thoughts on “Virtual Machine For Microcontrollers Lets You Run Python On AVR Chips

      1. Where is the interpreter and bytecode? It’s a command line tool that converts python to the VM language, which isn’t bytecode but instead script that has to be built to avr binary via macros..

  1. YAY \ö/

    this is soooooo cool.

    microncontrollers with virtually unlimited ROM for programming.
    codeimages on SDcards
    live code updates over zigbee / rmf modules++
    the possibilities!

    thank you so much clifford

  2. Hi,

    you’ll have the python frontend in the pysrc/ directory.

    I’ve used pymite as well, and it’s as nice a job as embedvm.

    I think both have their own advantages.

    pymite : intends to be 100% compatible with python bytecode, portable along multiple platforms (ARM, …) but higher requirements

    embedvm : lower requirements, and multiple frontend languages (C like & python)


  3. This must be the most elaborate rickroll ever.

    Apart from that, seems like a nifty way of sharing code among different microcontrollers, although the loss in performance kind of defeats the point of using a microcontroller in the first place.

  4. It is a very nice VM, I have played whole day with it.
    My background is C/C++ and I am happy whit C like scripting language.
    But I have same suggestions about it:
    – Need full description of language
    – Full description how to pass / get values between VM and native functions
    – Need floating point types / arithmetic
    – 32 bit VM in this days 32bit microcontrollers are common
    Thanks Clifford Wolf for good job

  5. hi,

    i (the one who wrote the python extension) would like to clarify a bit about the python part — it’s rather underdocumented atm:

    the python branch of embedvm is not intended to be a fully functional python implementation. it translates a very restricted subset of python to embedvm bytecode. “very restricted” currently means that all variables are either 16bit integers or integer arrays (the only kind of variable embedvm supports; arithmetics wrap instead of changing to long), no proper objects, no functional programming, not even proper imports (imports can be done, but there is a dispatch between being run in native python and compilation for embedvm).

    some of the shortcomings can be adressed, others probably won’t. (classes and objects — although only statically typed with inference from first assignment — seem possible; others, like dynamic typing, i don’t consider reasonable on this platform.) if that’s too far off from what you would like to call python, call it an ad-hoc language with python syntax.

    @jf (“loss in performance”): the idea is to have a system where all the hardware interaction stuff (where you need speed) is done in C, and gets bindings to the vm (the funny sounds it can play are a typical example). the vm then handles stuff that requires more flexibility (where you’d normally have to flash the microcontroller). it’s a tradeoff between flexibility and performance.

    @mp: while the vm is platform independent, its typical use is on atmega or attiny devices — which lack native floating point or 32bit support.

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