Arduino goes lambda!


Snap4Arduino 1.2.7 has been released on October 22, 2018

What is it?

Snap4Arduino is a modification of the Snap! visual programming language that lets you seamlessly interact with almost all versions of the Arduino board.

You can see a short example of what you can do with it in the video at the rightmost column.

Snap!

Snap! (formerly BYOB) is an extended reimplementation of Scratch that allows you to Build Your Own Blocks™. It also features first class heterogeneous lists, first class procedures, and continuations. These added capabilities make it suitable for a serious introduction to computer science for high school or college students.

Snap! is presented by the University of California at Berkeley. It was developed by Jens Mönig, with design input and documentation by Brian Harvey and contributions by students at Berkeley and elsewhere.


Features

  • Blocks-based, dynamic, live, concurrent, parallel programming
  • Almost all Arduino boards supported
  • Uses standard Firmata firmware
  • Auto-configurable pinouts and high level hardware abstractions
  • You can interact with multiple boards at the same time
  • Desktop-based versions for the three major OSes
  • Online version that can be connected to Arduino boards with a Chrome/Chromium plugin
  • Free software licensed under the Affero GPLv3
  • Transpilation of simple scripts into Arduino sketches
  • HTTP protocol for remote control and live-streaming of the Snap! stage
  • Command line version for embedded GNU/Linuxes

Download

There are currently desktop versions for GNU/Linux, MacOSX and Microsoft Windows, a web version (available online) and connectable by a Chrome/Chromium plugin, and other experimental versions.



The project and all its components (including Snap!) are registered under public free software licenses (AGPLv3 and MIT), so you can download the sources and pretty much do whatever you want with them!

Please download the version that matches your operating system. Current version: 1.2.7 released on 22/10/2018

Installation

Snap4Arduino requires that you have StandardFirmata installed in your board.

To do so, follow these simple steps:

  1. If you haven't already, download and install the Arduino environment by following the instructions on http://arduino.cc/en/Main/Software.
  2. Open the Arduino IDE, go to File → Examples → Firmata → StandardFirmata
  3. Connect your board to a USB port in your computer
  4. In the Tools menu, select the board version and the serial port where the board is connected
  5. Go to File and click on Upload
  6. Snap4Arduino will now be able to interact with your board.

These instructions are needed to prepare your device (board). If you have an Arduino with the firmware installed, you don't worry about this... and you only need Snap4Arduino software. Anyway, to make sure you will have not problems with drivers (for Windows OS) or permissions, installing Arduino IDE can be a good idea.

StandardFirmata is the basic requirement for your devices but you can implement more features using others Firmatas. See Devices section to get more info.



ChromeOS app

You can install ChromeOS app from the Chrome Web Store or download the package, uncompress it and drag and drop the crx file into the chrome://extensions browser tab. This is a limited version of Snap4Arduino, but you can use it offline easily.

GNU/Linux

You just need to unpack the package. In most window environments you can just click on Snap4Arduino. If this fails, you can always run ./run from the command line.

MacOS X

Unzip the package and run the Snap4Arduino package. If you wish, you can move it to your Applications folder so you can access it as a regular app.

Microsoft Windows

Just unzip the package and run the installer.

Web version for Chrome/Chromium

Online version requires a Chrome/Chromium plugin to connect to Arduino boards. To install it, just download the plugin package, unzip it and get the Chrome_Snap4ArduinoConnector_ 1.2.7 folder. Then, go to chrome://extensions in your browser, activate the developer mode and drag and drop that folder inside.

If you prefer to run it offline or in your own server, use this downloadable version.

Embedded

The embedded command line version works in any GNU/Linux based machine, including embedded platforms and single board computers. New generation Arduino boards like Yun, Tian or Industrial 101 can run this version right inside the board, and if you have a regular Arduino and any kind of Gnu/Linux based single board computer, you can always have the latter be the host computer to the Arduino board, giving autonomy to your project without having to modify your Snap4Arduino program at all.

Check out this section of our GitHub wiki.

Happy prototyping!

Demos

Here's a couple of fun things that can be done with Snap4Arduino, most of them recorded on a Hi-Tech last generation potato camera.

A bluetooth-controlled car (HOWTO: Blueetooth connectivity)
A line follower with parking lights
An ultrasound ruler
An LCD screen
A command line application (HOWTO: Command Line)
A somewhat autonomous RaspberryPi powered bullseye contraption (HOWTO: Command Line)
An Etch-A-Sketch that streams itself to any device over the network (source)
A shy Poppy Ergo Jr Robot
Music for a horror film of the 50s (source)
A machine that beats you at Tic-Tac-Toe
A mechatronic teddy bear
A LOGO-turtle-like bluetooth drawing robot (HOWTO: Blueetooth connectivity)
A mechatronic eye (source)
A Phiro robot
Two laptops communicating via Morse

Source Code

You can find our GitHub repo at Snap4Arduino@GitHub. Please feel free to send us your pull requests and participate in reporting, fixing or commenting on bugs!

Supported Devices

You can modify Firmata to have it work with a wide variety of devices that, by default, are not supported. Check out this blog post if you want to do it yourself. Additionally, we will be publishing a series of modified Firmata versions and their corresponding Snap4Arduino block libraries here, so if your device shows up under this list you can just download the extension and start prototyping:

From Citilab Edutec Team:


And you can use any device (not only Arduinos) running a Firmata firmware. For example ESP8266 and nodeMCU are widely used.

And more... Other devices like Picaxe boards, micro:bit, Lego WeDo, Boost... can be used with Snap! (and of course also with Snap4Arduino) using different middlewares. More info here

User-contributed Firmata versions

Snap4Arduino libraries include SA5Firmata and Creative Robotix blocks, and these require their own firmata:

  • Joan Guillén's SA5Firmata is another super-Firmata modification that adds tone, pulse and ping functions, along with support for DHT11 humidity and temperature sensors, ultrasound sensors, Nunchuks and message sending and receiving over IR.
  • The Creative Science Foundation's Creative Robotix Firmata is a Firmata version for use with the Creative Robotix Educational Platform.

  • Matthew Canham's Snap4Arduino Firmata Collection features several great Firmata modifications.
  • Chris Clay's Robotics-unleashed is yet another super-Firmata modification that allows you to control several devices at the same time.

HTTP Protocol

http://IP:42001/

Snap4Arduino comes with a built-in tiny HTTP server that mimics (and extends) the one Scratch 1.4 had. This means you can control your Snap4Arduino application from any computer, mobile phone, tablet or any other network-enabled device in the same network. In the following sections, the word IP refers to the IP address of the machine that has Snap4Arduino running on it.

Giving orders to Snap4Arduino
/broadcast=MESSAGE

Point your browser to http://IP:42001/broadcast=MESSAGE

This will broadcast the message MESSAGE to Snap4Arduino, where you can capture it with a regular When I receive [MESSAGE] block.

These public messages must begin with the + character. The rest of the messages are private and they are not considered.

Updating the value of a Snap4Arduino variable
/vars-update=VARIABLE-NAME=VARIABLE-VALUE

Point your browser to http://IP:42001/vars-update=VARIABLE-NAME=VARIABLE-VALUE

This will set the global variable called VARIABLE-NAME to the value VARIABLE-VALUE.

This only works for global variables that start with the + character. The other variables are not editable. Bear in mind that variables with names containing the '=' character can not be used, even though Snap! supports them.

You can also update multiple variables at once by means of a POST request (see below).

Finding out which messages is Snap4Arduino listening for
/send-messages

Point your browser to http://IP:42001/send-messages

This will show a list of all message names for which Snap4Arduino has When I receive [message] hat blocks and they start with the + character (the other messages are private).

Getting variables and their values from Snap4Arduino
/send-vars



Point your browser to http://IP:42001/send-vars

This will show a list of all global variables defined in Snap4Arduino and whose name starts with the + or with the - character (+ variables are editable and - are readable) , along with their current value.

Getting the value of a single variables from Snap4Arduino
/send-var=VARIABLE-NAME

Point your browser to http://IP:42001/send-var=VARIABLE-NAME

This will return the value of the variable ready for you to use, no string manipulation needed. The variable must start with the + or with the - character to be public.

Getting a real-time stream of the stage in Snap4Arduino
/stage




Point your browser to http://IP:42001/stage

This will render a real time version of what's going on in the stage. Like demonstrated in this video.

You will be presented with an auto-refreshing HTML page, enabling you to watch the stage contents in your browser, though in a non-interactive way. Public Stage must be checked in the settings menu; otherwise, the stage is not public.

Getting a snapshot of the stage in Snap4Arduino
/stageimg




Point your browser to http://IP:42001/stageimg

This will render a snapshot of the Snap4Arduino stage in the form of an image encoded in base64 that you can use for any purpose. Again, Public Stage must be checked in the settings menu; otherwise, the stage is not public.

POST. Updating multiple variables of Snap4Arduino from an HTML form
<form action="http://IP:42001" method="post">

You can update multiple global variables in your project at the same time by means of an HTML form sent through a POST request.

By using <INPUT> and <TEXTAREA> tags, you can send all kinds of input types to Snap!, except for booleans. Their name attribute should contain the name of the variable you wish to update.

Note that Snap4Arduino expects all queries to be UTF-8 encoded. To make sure your query goes through properly, especially when dealing with special characters, you can always use:

<form action="http://IP:42001" method="post" accept-charset="utf-8">