Snek
Snek programming language for tiny systems
Install / Use
/learn @keith-packard/SnekREADME
Snek — a tiny python-inspired language for embedded computing
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
-
The Snek Home Page provides more information about the language and community.
Downloads
-
Snek is packaged for Debian and is available for the unstable release.
-
Packages for Linux, including older versions of Debian, Mac OS X and Windows are available in the Snek Dist directory
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.
-
Adafruit Crickit. This is sold as an expansion board for other Adafruit products, but Snek is able to run on the local processor. Snek supports the motor controllers and Neopixel.
-
Adafruit Feather M0 Express. Snek supports digital and analog input and output with this device.
-
Seeed Grove Beginner Kit for Arduino. Snek supports the LED, Buzzer, Light, Sound, OLED Display, Button, Rotary Potentiometer and 3-axis Accelerometer.
-
Circuit Playground Express. Snek supports the NeoPixels, sound, light sensor and temperature sensor. It does not support the accelerometer yet.
-
Snekboard. This board was designed to run Snek and control Lego Power Function motors.
-
Crowd Supply µduino. This board doesn't have any access to the programming pins, so you'd need to get Snek pre-programmed before it was split off of the carrier board.
-
Arduino Uno. This is pretty much the same as a Duemilanove board, but with a different USB to serial converter.
-
LEGO® MINDSTORMS® EV3. Snek supports EV3 motors and sensors.
-
Seeed Grove Beginner Kit. The port includes drivers for everything except the temperature, humidity and barometric pressure sensors.
-
Arduino Nano Every. This uses flash for storage, and includes most of the math library and the tone driver.
-
LilyPad Arduino 328. This port leaves out dictionaries and slices so that it has space for the tone driver.
To Do list
- Convert parser from LL to SLR. The hope here is to reduce the amount of parse stack space needed due to the large number of precedence levels in the language.
Recent Changes
Here's some places that have seen recent work
-
Remove the -big variants. The variants supporting boot loaders now have sufficient space to support all of the options formerly reserved for the -big ones.
-
Rewrite the ATmel chip support to use __flash attributes. Target newer GCC version. With these changes, there's lots more space available on ATmel targets.
-
Changed the builtin math, time and random functions to no longer include the math., time. or random. prefixes. This makes them more convenient to use. To retain compatibility with Python, you can use 'from math import *' which Snek will ignore.
-
Mu version 1.2.0 has Snek support built in now. Mu is an IDE designed for new Python users that offers a more polished alternative to the simple Snek IDE provide with snek.
-
Fixed a couple of
inputbugs compared with Python—input returned None instead of the empty string when nothing was typed before the return and input printed an arbitrary list of parameters rather than just the first one. Thanks to Justin Miller and Mikael Bonnier for reporting these issues. -
Store the most recently printed repl value in
_. Thanks to Justin Miller for this suggestion. -
For the Windows native port, add the input module and increase the heap size to 256kB.
-
Update the docs to format correctly with asciidoctor-pdf version 2.3
-
LilyPad Arduino 328 port. This is a round ATmega328p-based board designed for wearable projects. This board runs at 8MHz, which can't run the serial port at 115.2kbaud, so it runs at 57.6k instead. Thanks to Douglas Fraser for this.
-
Support multiple baud rates in snekde, auto-detect baud rate when connecting to non-USB based devices.
-
Fix NaN comparisons and make dicts containing NaN keys work. Jake Edge's article, “Revisiting NaNs in Python” led to the discovery that Snek had several bugs in NaN comparisons. Snek now computes the right value for comparisons with Nan, as well as permitting NaN to be used as a key in dictionaries.
-
Support explicit serial synchronization using ENQ/ACK so that applications sending lots of data do not require OS flow control support. With many devices connecting via USB/serial adapters that do not provide any flow control, adding explicit flow control to the Snek implementation provides a way to make downloading code reliable for them.
-
Fixed incorrect precedence between bitwise and (&) and bitwise xor (^) operators.
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:
- Lola
- gawk
- gcc-avr
- avr-libc
- gcc-arm-none-eabi
- gcc-riscv64-unknown-elf
- gcc-arm-linux-gnueabi
- picolibc
- python3
- pyserial
- python curses
- readline
- asciidoctor
- asciidoctor-pdf
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.
