Snek: A Python-inspired Language for Embedded Devices

Snek is a tiny embeddable language targeting processors with only a few kB of flash and ram. Think of something that would have been running BASIC years ago and you'll have the idea. These processors are too small to run MicroPython.

Snek borrows semantics and syntax from python, but only provides a tiny subset of that large language. The goal is to have Snek programs able to run in a full Python (version 3) implementation so that any knowledge gained in learning Snek will transfer directly to learning Python.

Documentation

The Snek Manual is under development. Current drafts are available in both PDF and HTML format:

I started documenting snek in my blog, here is a link to all snek-related blog posts.

There is also a Snek mailing list, which you are encouraged to subscribe to

Releases

I'm starting to work on getting Snek packaged for generic Linux and Windows machines. These packages include a snek binary for the host operating system to experiment with, binaries for target devices (only Arduino Duemilanova at this point), snekde (the Snek Development Environment) and documentation.

Packages are available in the dist directory here

Source Code

You can find Snek in either my git repository or github

Snek is licensed under the GPLv2 (or later)

Debian Packages

Pre-built Debian packages for Debian are available in my personal package archive. Instructions on how to set that up for your machine are available in the README in that directory.

There are two snek packages in the archive:

  • snek. The main 'snek' package includes source code for use in your own embedded environment, a binary for Duemilanova boards, the 'snekde' development environment and documentation.

  • snek-bin. The auxiliary 'snek-bin' package includes a 'snek' application compiled for the host machine, which can be useful to experiment with language features and functions that do not require access to the target hardware.

Snek on Arduino Duemilanova

This remains my primary development target as I have existing classroom supplies using this architecture. This port offers access to GPIO pins and the USB serial port, along with a few other builtin functions. Source code is stored in EEPROM and automatically loaded at boot time, so devices can run stand-alone.

Snek in NuttX

NuttX is a moderate-sized embedded RTOS that works on a variety of small systems. I've written the necessary glue-code and build instructions to make Snek available there. All of that code is licensed under the standard NuttX/BSD license, but because NuttX upstream is not willing to take code that references GPL code, I've created a fork of the NuttX app tree in my git repository..

NuttX has a good mechanism for adding code of this sort; there are no changes to existing NuttX files, just a new directory in app/interpreters/snek. When present, all of the necessary options become visible in the regular NuttX configuration tool.

This port doesn't interface to much of NuttX yet, it would be fun to see some experimentation here.

ToDo

The biggest item on my to-do list is documentation. I need to finish the reference material and then go write a tutorial to help people get started using Snek. That will be an iterative process, aided by students who will surely uncover bugs in all aspects of the system.

Aside from that, there are always wish list items to add to the language. I'd like to sort out how to expose the '.' operator for real. Right now, '.' is allowed in names, so functions like 'time.sleep' can have their normal Python3 names. Python3 uses dictionaries for this operation; perhaps I can do something similar.

Porting Snek to new hardware is also on the list. I've just ordered some Cortex M0 Arduino-compatible boards from adafruit. These have the ATSAMD21G18 SoC instead of the ATMega 328P. With 256kB of flash and 32kB of RAM, these offer a significant upgrade in capacity. MicroPython can run on these devices, so it's not entirely clear that this is a space for Snek to exist in or not. I'm thinking that a fully self-contained development system might be interesting though.