keith-packard / snek

Snek programming language for tiny systems
GNU General Public License v3.0
294 stars 30 forks source link

Snek — a tiny python-inspired language for embedded computing

Snek picture

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.

Documentation

Downloads

Supported Hardware

Snek supports analog and digital I/O operations on all of these boards. Snek also has some support for built-in devices on boards as described below.

To Do list

Recent Changes

Here's some places that have seen recent work

Build and Run!

If you want to build Snek yourself, you'll need to have the build tools and other dependencies installed.

Dependencies

To build Snek you need these dependencies:

On Debian unstable, you can get everything from the main archive:

# apt install lola gcc-avr avr-libc python3-serial gawk \
      gcc-arm-none-eabi gcc-riscv64-unknown-elf libreadline-dev \
  picolibc-arm-none-eabi picolibc-riscv64-unknown-elf \
  asciidoctor ruby-asciidoctor-pdf gcc-arm-linux-gnueabi

Debian stable has too old a version of lola, so if you're using that, you'll need to install lola from the git repository above.

The snek build scripts use the GNU awk implementation, gawk, including a GNU extension, strtonum, which is not available in other awk implementations. It's not critical to compiling the code as it's only used to print out ROM usage for AVR targets so you can tell how much space is still available, but if you don't have gawk, you will get build failures.

Building and install

Here are some useful options to control the build. Each of these is run from the top level directory.

$ make

If you just type 'make', the system will build all of the embedded binaries and a native binary to run locally.

$ make install

'make install' will copy all of the built programs to /usr/local

$ make PREFIX=$HOME/.local

This compiles everything to run from your home directory, instead of /usr/local.

$ make PREFIX=$HOME/.local install

Make sure you use the same PREFIX value every time you run make so that the snek install scripts (which get PREFIX embedded in them) that are installed know where to find the snek binaries for each device.

Running on Embedded Devices

Snek is designed to run on small embedded devices with 32kB or more of flash and 2kB or more of RAM. Snek has been ported to a variety of embedded devices, providing access to pins as GPIOs as well as some built-in peripherals. Documentation about the supported boards can be found in the Snek Manual.

Running on Linux, Mac OS X Windows

Snek is also built to run natively on Linux, Mac OS X and Windows. When installed, you'll find it available in the regular system menu.

The Mu Editor

mu is an IDE especially designed for new Python developers. It has support for boards running snek upstream, but no release has been made with that code yet.

The Snek Development Environment

Snekde is provided on all three platforms; you'll find it in the system menu on Linux and Windows and down in your personal Applications directory on Mac OS X.

The snekde window is split into two parts. The upper 2/3 is a text editor for source code. The bottom 1/3 lets you interact with the Snek device over the USB port. The very top line lists functions that you can invoke by pressing the associated function key:

There are a couple more keybindings which you'll want to know:

Tab auto-indents the current line. Backspace backs up over a tab stop when appropriate.

Examples

There are examples provided, some of which work with both Python and Snek, and some of which show how to use SoC-specific APIs that aren't available in Python.

Contributions

I'd love to receive more contributions in the form of patches, suggestions and bug reports. Please feel free to send mail or use the github process. I've created a mailing list for collaboration; you'll need to subscribe to be able to post. Subscribe to the snek mailing list here

Releases

Here are more specific notes about Snek releases.

Version 1.8

Version 1.7

Version 1.6

Version 1.5

Version 1.4

Version 1.3