[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”
I have been tpying with this idea, I wanted to use PHP. I tried several times, but scrapped my work, wasnt happy.
This is great, keep it up!
PHP would be nice too =P
I’m not a huge fan of microcontrollers (usually try to use an FPGA), but this is awesome.
I’m just the opposite, though not through experience with both (only with the uCs). Could you tell me how you got started with FPGAs, and why you prefer them? Just curious.
The more I look at this, the more impressed I am.
I hang my head in shame for posting my crusty port of TinyBASIC to the AVR.
code has to be converted by external tools, where is the vm part?
I think the word you’re looking for is bytecode interpreter. Java’s bytecode interpreter is often called the “Java VM.”
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..
this is soooooo cool.
microncontrollers with virtually unlimited ROM for programming.
codeimages on SDcards
live code updates over zigbee / rmf modules++
thank you so much clifford
Where’s the Python? All I see is a C variant.
I’m not saying it’s unimpressive. I’m just commenting that the title is *highly* misleading.
and this is not it…
can’t wait to see somebody demonstrate python on a chip!
No need to wait, lochnessduck. I’ve been running the PyMite VM on an ATmega since 2003. Since then, it’s morphed into pythononachip.org and runs on most MCUs with at least 64K Flash and 8K RAM.
The tools for this are written in Python. It otherwise reminds me of the “Sweet-16” virtual machine that Woz wrote for the Apple II.
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)
Great, great, great project. I had been looking for this on-and-off for a while.
Keep in mind that this doubles as a Rick/Roll.
This makes Clifford is an evil genius.
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.
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
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.
Please be kind and respectful to help make the comments section excellent. (Comment Policy)