Creating Your First GRiSP Application
Before proceeding with this guide, make sure you have set up your development environment according to Setting Up a Development Environment.
-
First, we create a new project using the GRiSP application template. We will use the name
robot
for the project in this tutorial. The destination path/tmp/sd_card
should be replaced with where your SD-card is mounted in your operating system. For a FAT32 formatted SD-card with the nameGRISP
the locations will most likely be:-
/Volumes/GRISP
on macOS -
/media/GRISP
on Linux is common, but it can vary. Check the details for your distribution.
It also works fine with using
/tmp/sd_card
which lets you to test the deployment locally and allows you to copy the files to an SD-card at a later time.$ cd ~/GRiSP $ rebar3 new grispapp name=robot dest=/tmp/sd_card ===> Writing robot/src/robot.erl ===> Writing robot/src/robot_sup.erl ===> Writing robot/src/robot.app.src ===> Writing robot/rebar.config ===> Writing robot/.gitignore ===> Writing robot/LICENSE ===> Writing robot/README.md $ cd robot
-
This is all that is needed to start development and later deploy the application to the GRiSP board itself.
Let us create an application that uses the color LEDs already present on the board.
-
Edit
src/robot.erl
to contain the following:% @doc robot public API. % @end -module(robot). -behavior(application). % Callbacks -export([start/2]). -export([stop/1]). %--- Callbacks ----------------------------------------------------------------- start(_Type, _Args) -> {ok, Supervisor} = robot_sup:start_link(), LEDs = [1, 2], [grisp_led:flash(L, red, 500) || L <- LEDs], timer:sleep(5000), grisp_led:off(2), Random = fun() -> {rand:uniform(2) - 1, rand:uniform(2) -1, rand:uniform(2) - 1} end, grisp_led:pattern(1, [{100, Random}]), {ok, Supervisor}. stop(_State) -> ok.
This will flash both LED red for 5 seconds, then switch to a randomly generated pattern on the first LED.
-
Make sure your changes compile without issues locally:
$ rebar3 compile ===> Verifying dependencies... ===> Compiling robot $
Continue with the guide Deploying a GRiSP Application.