Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Autonomy via CLI
Snap4Arduino is also offered as a command line application that can read Snap! projects and run them in a terminal.
What this means is that you could prototype your projects in a regular computer and then have a very little, resource limited and portable computer run them, giving you the possibility of making your project autonomous.
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, Tiān 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.
Examples of tiny computers (AKA single-board computers) that can run the command line version of Snap4Arduino are the Arduino Tian (see Linino), Raspberry Pi, BeagleBone black, ODROID or CHIP.
See this video for an example of a battery-powered Raspberry Pi running a Snap4Arduino program and interfacing with a regular Arduino UNO board:
The command line version is available for download in the official site under the name Embedded (Command Line).
To install it in a regular desktop computer, just unzip the package and run the
./install.sh utility as a superuser. In a Debian/Ubuntu system, you'd do so by running:
Single-Board Computers (Debian/Ubuntu-based, Raspbian)
You need to satisfy a couple of dependencies. For starters, you are going to need NodeJS (0.10.4x or higher) and npm. Follow instructions from https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions.
The next step is to unzip the package and
cd to its root directory. All the following commands should be issued from within that directory.
You then need to install the Node.JS Firmata package, which you can do by running:
$ npm install firmata
If you want to have full Canvas support to be able to stream your stage over HTTP:
$ npm install canvas
If npm fails to install canvas, you may need to install its prerequisites. In Debian/Raspbian, this should suffice:
# apt-get install g++ build-essential libgif-dev libpango1.0-dev libjpeg-dev libcairo2-dev
For other systems, please refer to https://github.com/Automattic/node-canvas#installation
You do not need to install Snap4Arduino, you can just run the command line interpreter by running
To install the snap-interpreter in your system, just run the
install.sh script with root privileges.
snap.js yourProject.xml [--plain-snap] [--canvas] [--serve] [/path/to/serial] Runs a Berkeley Snap! project or a Snap4Arduino one on the command line. --plain-snap Runs a plain Snap! project with no Arduino capabilities. --linino Uses the LininoIO library for communication with the Arduino instead of Firmata. Meant to be used in boards with embedded GNU/Linux inside (Tian, Yún, etc). If a serial port is specified, this setting will have no effect. --canvas Renders the Stage in an HTTP-streamable canvas. Automatically adds «--serve». --serve Starts a simple HTTP server at port 42001 with the following entry points: http://[IP]:42001/stage Streams the Stage in real time. Needs «--canvas». http://[IP]:42001/broadcast=[message] Broadcasts «message» to Snap! so it can be captured by «When I receive» hat blocks. http://[IP]:42001/send-messages Lists all messages being used in the Snap! program. http://[IP]:42001/send-vars Lists all variables being used in the Snap! program. http://[IP]:42001/vars-update=[variable]=[value] Sets the Snap! variable «variable» to «value».
On the terminal, you'll get outputs of say, think and ask blocks and all messages given by the UI. The contents of the stage can be seen via a tiny webserver accessible at http://[your-ip]:42001/stage. See this section to read about the whole HTTP protocol.