Adding sensors to your project using the Sensor Library Explorer

You can quickly find and use code examples for a wide variety of sensors and actuators using the Sensor Library Explorer. The Intel® XDK lets you browse devices by category, manufacturer, and connection type, then copy and paste example code directly into your projects. This helps you get started quickly using code that has already been written for you. For quick steps to add sensor code to your project or take advantage of bookmarking to access example code for a favorite sensor, see the appropriate links below:

For a quick example of adding a new sensor to your project, see Example: Adding a light sensor to your project.

Adding sensors to an IoT project: Overview

The Intel® IoT Developer Kit makes it easy to add sensors to your project. The basic steps are the following:

  1. Decide which sensors to add to your project.
  2. Connect the sensor to your board.
  3. Locate and add example code to your project, then modify the code to meet your needs.

Though you can write code from scratch, finding and reusing example code for supported sensors is often the easiest, fastest way to begin programming your board.

The example code in the Sensor Library Explorer is written using the UPM sensor library, or libupm, a collection of modules for interfacing with over 100 different sensors from various manufacturers. A list of supported sensors, along with JavaScript*, Python*, and C++ code for each sensor, can be found at https://software.intel.com/en-us/iot/hardware/sensors. If your sensor is not yet supported by the UPM library on GitHub*, you can request to have it added or add support yourself by creating a UPM module. For details, see the UPM page on GitHub. Each supported sensor has its own class file that needs to be imported into your project and instantiated.

Adding sensor code to your project

  1. Open the Intel XDK.
  2. On the left under Sensor Libraries, click Open Sensor Library Explorer. The Sensor Library Explorer opens.
  3. From the drop-down list at the top, select one of the following:
    • To browse devices by category, such as accelerometers or LEDs, select Browse by Category.
    • To browse devices by manufacturer, select Browse by Manufacturer.
    • To browse devices by connection type (such as SPI or UART), select Browse by Connection Type.
  4. Individual devices in a selected group are displayed in the Device list. Browse to and select the device you want to view sample code for. Information about the selected device is displayed in the Description pane to the right.
  5. To copy the example code to the clipboard, click Copy snippet to clipboard. The example code is automatically copied to your clipboard for you to paste into your project.

Viewing documentation for a device

  1. Open the Sensor Library Explorer.
  2. Navigate to the entry of the device you want to view, then click View docs. The website opens in a browser window.
  3. When finished, click Close.

Bookmarking a device in the Sensor Library Explorer

You can instantly bring up the entry for a device in the Sensor Library Explorer. To do so, bookmark the device. The Intel XDK displays the bookmark link under the Open Sensor Library Explorer link, allowing you to access the device's entry with a single click.

  1. Open the Sensor Library Explorer.
  2. Navigate to the entry of the device you want to bookmark. Select the Bookmark this sensor library for quick access check box. A small icon is displayed next to the name of the device in the Device list to confirm that it is bookmarked.

    The IoT Sensor Library Explorer
  3. Click Close.
  4. Once you have bookmarked a sensor, its name appears in the Sensor Library Bookmarks list in the lower left of the Intel XDK. Click a sensor name to instantly view the device's entry in the Sensor Library Explorer.

    Example of the Sensor Libraries options
For more complete information about compiler optimizations, see our Optimization Notice.