Creating JavaScript*-based Intel® IoT projects with the Grove* - Starter Kit

This section contains an introduction to creating JavaScript*-based Intel® IoT projects with the Grove* - Starter Kit Plus: Intel® IoT Edition. To skip to the example code for sensors and actuators, see the appropriate link below:

The Grove system is an easy-to-use group of modules that minimize the effort required to get started with microcontroller-based experimentation and learning. Intel has partnered with Seeed, the creators of Grove, to distribute the Grove - Starter Kit Plus: Intel IoT Edition, which contains essential sensor and actuator modules to jumpstart your IoT prototyping. Once you install the base shield that comes with the kit, attaching sensors and actuators to your board is a matter of plugging them in to the clearly labeled sockets.

The sensors and actuators in the Grove - Starter Kit Plus: Intel® IoT Edition work with both the Intel® Galileo board and the Intel® Edison board with Arduino* expansion board.

The table below shows the contents of the Grove - Starter Kit Plus box.

  • Green components: Can be found in the plastic tray inside the green box.
  • Gray components: Can be found underneath the plastic tray or elsewhere in the cardboard box.

Grove* - LCD RGB Backlight

Grove *- Base Shield v2

(look underneath LCD)

26AWG Grove* - Cables
(× 10)

9V to barrel jack adapter - 126mm

Example of a buzzer

Example of a sound sensor

Example of a touch sensor

Grove* - Buzzer

Grove* - Sound Sensor

Grove* - Touch Sensor

3.3V FTDI
USB-to-Serial cable

Example of a temperature sensor

Example of a light sensor

Example of the Grove - Rotary Angle

Grove* -Temperature Sensor

Grove* - Light Sensor

Grove* - Rotary Angle

Ethernet cable

Example of a button

Example of a light sensor

Example of a relay

Grove* - Button

Grove* - LED Socket Kit

Grove* - Smart Relay

Micro USB cable

Example of an LED

Example of the Grove - Starter Kit manual

Example of a micro SD card

Grove* - Servo Motor

Red, green, and blue 3mm LEDs

Starter kit
manual

8GB micro SD card with an SD Card adapter

Installing the Grove - Base Shield

The Grove - Base Shield is an Arduino shield, an add-on that plugs in to standard Arduino header pin configurations, which includes the Intel® Galileo board and Intel® Edison board with Arduino expansion board. In general, shields allow for additional functionality without having to use an additional prototyping area such as a breadboard. The base shield lets you attach sensors and actuators to your Intel® Galileo board or Intel® Edison board by plugging them directly in to the base shield.

  1. Unplug the Arduino expansion board from all power sources, such as a breadboard. Line up the male header pins of the base shield with the female pins on the Arduino expansion board. The pin configuration only fits the Arduino expansion board in one direction, so do not force the pins if they do not line up.

  2. Push down firmly and evenly on both sides of the base shield until the shield is securely installed.

    Installing the base shield

  3. Check the voltage toggle switch (marked VCC, next to A0) on the base shield. It should be set to 5V.

  4. Power your Intel® Edison board or Intel® Galileo board back on. Allow 1 minute for the board to finish booting up.

Connecting a Grove component

You connect all components in the Grove system using 4-pin cable with JST connectors. This allows you to connect components and prototype without having to individually learn how to wire up each unique component.

  1. Choose a component from the Grove system, such as a light sensor or button.
  2. Use a 4-pin Grove Cable and connect one end of the cable to the component. The cable connectors only fit in one direction, so you can be confident that the wiring is correct.
  3. Refer to the base shield labels for the correct pin to connect the other end of the cable to. This varies depending on the component and what pin your code expects the component to be attached to. For example, if you are using the light sensor as an analog input and your code expects the sensor to be connected to analog pin 1, you connect the cable to the socket labeled A1.

    Example of a base shield

    The following pins are available:

    • Digital pins (D2-D8)
    • Analog pins (A0-A3)
    • I2C (bottom row)
    • UART (top right)

     

Example of an LED and button connected to a base shield

Grove component types

The simpler components in the starter kit fall into two categories: input or output. These two categories further subdivide into digital or analog. Other components in the starter kit may use more complex communications protocols, such as UART or I2C.

You must know in which category a component is in order to correctly attach the component to the base shield and use the correct code library and commands to control the component.

The following sections contain examples using components available in the Grove - Starter Kit Plus, divided by component type. If available, code examples are provided using both the lower-level MRAA I/O library and the UPM sensor library:

The following code examples are available:

Digital output

A digital output can write a value of either on (1) or off (0). You connect this type of component to any pin labelled "D" (for "digital") on the base shield, such as D2 to D8.

The table below contains examples of digital outputs, a link to sample code for the components, and the require statement needed to add the component to your project.

Grove - LED Socket Kit

Grove - Smart Relay

UPM sample code

UPM sample code

require('jsupm_grove')

require('jsupm_grove')

Low level MRAA-only example:

var mraa = require('mraa');
var led = new mraa.Gpio(6); // set up digital read on digital pin #6
led.dir(mraa.DIR_OUT);  // set the GPIO direction to output
led.write(1);  // set the digital pin to high (1)

Higher level UPM example:

var groveSensor = require('jsupm_grove');
var led = new groveSensor.GroveLed(6); // set up digital output on digital pin #6
led.on();  // set the digital pin to high

If you want to make the LED turn on and off, add a setTimeout() or setInterval() to toggle between writing 1 or 0 to the digital pin.

Digital input

A digital input can read a value as either on (1) or off (0).You connect this type of component to any pin labelled "D" (for "digital") on the base shield, such as D2 to D8.

The table below contains examples of digital inputs, a link to sample code for the components, and the require statement needed to add the component to your project.

Grove - Button

Grove - Touch Sensor
(TTP223)

UPM code samples

UPM code samples

require('jsupm_grove')

require('jsupm_ttp223')

Low level MRAA-only example:

var mraa = require('mraa');
var button = new mraa.Gpio(5);     // set up digital read on digital pin #5
button.dir(mraa.DIR_IN);           // set the GPIO direction to input
var buttonState = button.read();   // read the value of the digital pin
console.log(buttonState);          // write the value to the console for debugging

Higher level UPM example:

var groveSensor = require('jsupm_grove');
var button = new groveSensor.GroveButton(5); // set up digital input on pin #5
var buttonState = button.value();  // read the value of the digital pin
console.log(buttonState);          // write the value to the console for debugging

To react to button press beyond application startup, add a setTimeout() or setInterval() to periodically poll the pin state.

Analog input

An analog input will read a value between 0 and 1024. You connect this type of component to any pin labelled "A" (for "analog") on the base shield, such as A0 to A3.

The table below contains examples of analog inputs, a link to sample code for the components, and the require statement needed to add the component to your project.

Grove - Light Sensor

Grove - Rotary Angle

Grove - Temperature

Grove - Sound Sensor

UPM code samples

UPM code samples

UPM code samples

UPM code samples

require('jsupm_grove')

require('jsupm_grove')

require('jsupm_grove')

require("jsupm_mic")

Low level MRAA-only example:

var mraa = require('mraa');
var light = new mraa.Aio(0);     // set up analog input on analog pin #0 (A0)
var lightValue = light.read();   // read the value of the analog pin
console.log(lightValue);         // write the value to the console for debugging

Higher level UPM example:

var groveSensor = require('jsupm_grove');
var light = new groveSensor.GroveLight(0); // set up analog input on pin #0 (A0)
varlightValueRaw = light.raw_value();     // read the raw value of the analog pin
var lightValue = light.value();            // read the converted value of the pin
console.log(lightValueRaw, lightValue);    // write values to console for debugging

To react to changes in light beyond application startup, add a setTimeout() or setInterval() to periodically poll the sensor value. 

Analog output

An analog output is a digital output in disguise. Intel® IoT boards are digital microcontrollers that can pretend to be analog using a concept called pulse width modulation (PWM). Analog outputs will accept a floating-point value representing a duty cycle percentage between 0 (always off) and 1.0 (always on). For example, a value of 0.5 will rapidly pulse equally between on and off.

Components will only work when connected to PWM-enabled pins. By factory default, these PWM pins are D3, D5, and D6. (Digital pin #9 is also available on the Arduino expansion board via the standard female header pin.)

The table below contains examples of analog outputs, a link to sample code for the components, and the require statement needed to add the component to your project.

Grove - LED Socket Kit

Grove - Buzzer

Grove - Servo Motor

(ES08A)

(no UPM sample)

UPM sample code

UPM sample code

require("mraa")

require("jsupm_buzzer")

require("jsupm_servo")

Low level MRAA-only example:

var mraa = require("mraa");
var led = new mraa.Pwm(3);  // initialize PWM on digital pin #3
led.write(0.5);             // make LED half brightness
///--- below example: fade over time ---
var brightness = 1;
var fadeInterval;
function fade(){
  led.write(brightness);
  brightness -= 0.01;
  if (brightness < 0) clearInterval(fadeInterval);
}
fadeInterval = setInterval(fade, 100);

Higher level UPM example:

Please see: https://github.com/intel-iot-devkit/upm/blob/master/examples/javascript/es08a.js.

I²C

I²C (Inter-Integrated Circuit), pronounced "I-two-C" or "I-squared-C", is a multi-master, multi-slave, single-ended, serial computer bus used for attaching lower-speed peripherals to processors on computer motherboards and embedded systems.

Grove
LCD RGB Backlight
(JHD1313M1)

UPM code samples

require ('jsupm_i2clcd')

Higher level UPM example:

var jsUpmI2cLcd  = require ('jsupm_i2clcd');
var lcd = new jsUpmI2cLcd.Jhd1313m1(6, 0x3E, 0x62); // Initialize the LCD
lcd.setCursor(0,1); // go to the 1st row, 2nd column (0-indexed)
lcd.write("hello"); // print characters to the LCD screen

For more complete information about compiler optimizations, see our Optimization Notice.