NEQTO Docs
  • Languages iconEnglish
    • 日本語
  • Docs
  • API
  • FAQ

›I2C

Getting Started

  • NEQTO Hello World!
  • Tutorial Step 1. NEQTO Console Setting
  • Tutorial Step 2. Device Settings & Launching Service (NEQTO Bridge)
  • Tutorial Step 2. Device Settings & Launching Service (STM32 Discovery)
  • Tutorial Step 2. Device Settings & Launching Service (SPRESENSE)
  • Tutorial Step 3. Application development using scripts

NEQTO

  • NEQTO Account Registration
  • Sub-accounts
  • API Usage
  • NEQTO Engine Firmware List
  • Support Guidelines
  • For safe and secure use of the NEQTO products
  • Vulnerability Disclosure Policy

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Linux-based Device Management
  • Batch Registration
  • Scripts
  • Actions and Contacts
  • View Data from the Console
  • NEQTO Apps

    • About NEQTO Apps
    • NEQTO Infinitypool
    • NEQTO Insights
    • NEQTO Custodia
    • NEQTO Flow
  • Machine Driver
  • Recommended Browsers
  • Billing Information

SPRESENSE

    Hardware Specifications

    • 01. About Spresense

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. Spresense Wi-Fi Initial Setup
    • 04. Spresense LTE-M Initial Setup
    • 05. Debug Log Acquisition
    • 06. System LED Indications
    • 07. Event Messages
    • 08. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. GPIO
    • 12. UART
    • 13. SPI
    • 14. I2C
    • 15. ADC
    • 16. GNSS
    • 17. Camera
    • 18. Utils
    • 19. nqSpresense
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte

STM32 Discovery

    Hardware Specifications

    • 01. About STM32 Discovery Kit (B-L4S5I-IOT01A)

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. STM32 Discovery Wi-Fi Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 18. Utils
    • 19. nqDiscovery
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi

NEQTO Bridge

    Hardware Specifications

    • 01. NEQTO Bridge Module
    • 02. NEQTO Bridge Wi-Fi Module
    • 03. NEQTO Bridge LTE-1 Module
    • 04. NEQTO Bridge LTE-M/NB Module
    • 05. NEQTO Bridge IO Board
    • 06. NEQTO Bridge Digital IO Board
    • 07. NEQTO Bridge Connector Board

    Software Specifications

    • 01. Operational Flow
    • 02. NEQTO Bridge Wi-Fi Module Initial Setup
    • 03. NEQTO Bridge LTE Module Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 17. BLE
    • 18. Utils
    • 19. nqBridge
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte
    • 25. nqLAN
    • 26. nqEx

Linux-based device

    Software Specifications

    • 01. System Requirements
    • 02. Installation
    • 03. Software Configurations
    • 04. Operational Flow
    • 05. Debug Log Acquisition
    • 06. Event Messages
    • 07. Updating Software

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. RTC
    • 10. UNIXSocket
    • 11. FileSystem
    • 12. SubProcess
    • 13. SubTask
    • 14. Queue
    • 15. Utils
    • 16. nqLinux
    • 17. nqService
    • 18. nqMqtt
    • 19. nqFOTA
    • 20. nqLAN

neqto.js Libraries

  • About neqto.js Libraries
  • UART

    • GM65 Barcode Reader
    • SRF Ultrasonic Range Finder - Serial Mode

    I2C

    • HTS221 v2 Temperature and Humidity Sensor
    • LIS2DW12 v2 Accelerometer
    • SRF Ultrasonic Range Finder - I2C Mode
    • [Archive] HTS221 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer

    Utils

    • RTC Alarm Synchronized Scheduler

    Integration

    • AWS S3 v2
    • AWS IoT Core v2
    • Azure IoT v2
    • [Archive] GCP IoT Core
    • [Archive] AWS S3
    • [Archive] AWS IoT Core

neqto.js Snippets

  • About neqto.js Snippets
  • DataDog
  • Dropbox
  • Google Sheets
  • InfluxDB
  • Oracle Cloud Object Storage
  • Salesforce
  • Splunk
  • Niagara
  • [Archive] SAP Cloud Platform Internet of Things

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (STM32 Discovery Wi-Fi) Releases
  • NEQTO Firmware (Spresense Wi-Fi/LTE-M) Releases
  • NEQTO Engine for Linux Releases
  • neqto.js Libraries Releases

[Archive] LIS2DW12 Accelerometer

This library has been archived and is no longer supported. The latest version of the LIS2DW12 Accelerometer Library can be found here.

The LIS2DW12 is a MEMS digital output motion sensor capable of high-performance, ultra-low-power and 3-axis acceleration readings. The accelerometer plugs into the NEQTO Bridge and is accessible to read and write data over I2C protocol. The LIS2DW12 library provides the user with the functionality required to read acceleration values as a vector.

For information on how to import neqto.js libraries, please refer to this documentation.

Hardware Setup

The LIS2DW12 sensor plugs into the standard short cable I2C port of the NEQTO Bridge.

Software Setup

The LIS2DW12 library is needed to interact with the sensor over the I2C protocol.

Main Functions

The main functionality of the LIS2DW12 sensor comes in the form of a few functions. After creation, the functions setAccFifoMode to set the sensor into read mode, getAccFifoNum to get the number of FIFO samples from sensor, getAccValue to get acceleration value, getAccValues to get the list of acceleration values, getMaxAccValues to get maximum acceleration values and getSumAccValues to get the sum of acceleration values.

Creation

All NEQTO I2C libraries follow the same format for creation. The LIS2DW12 must be created with an I2C ready object passed in as an argument to the constructor. After creation, the init() function must be called to initialize and get the sensor ready to begin reading values. The init function only needs to be called once.

Usage Functions

The function setAccFifoMode() should be called before taking any readings to set the sensor into FIFO mode.

After setting FIFO mode the function getAccFifoNum() function is called to get the number of FIFO samples ready. After getting the number of samples ready, the next acceleration value can be obtained with a call to getAccValue(), or the next n number of samples can be obtained with getAccValues({numberSamples}). Also the getMaxAccValues({numberSamples}) and getSumAccValues({numberSamples}) can be called as well to get max or sum of n number of samples respectively.

Example Script

In this example script using the LIS2DW12 sensor, the user wants to log whenever the accelerometer takes a reading of a new maximum acceleration greater than a previous maximum acceleration value.

To begin with, the interfaces are turned on and an I2C device object is created to interface with the LIS2DW12 sensor.

The LIS2DW12 library is used to create a lis2dw object and then to initialize and put the sensor into FIFO mode and ready to take readings.

Initial maximum values are also set and an assert counter is setup for potential sensor misreadings.

The main loop is then created where the number of samples ready from the LIS2DW12 sensor is read using the getAccFifoNum and depending on the value returned two flows of operation will happen. When no samples are ready the assert counter is incremented and again the sensor is checked if any samples are ready. If no samples are ready for 10 assertions then the sensor is reset. When there are samples ready, the sensor is read for the maximum acceleration value from the previous number of samples ready and if greater than the current max then the current max is updated with the new maximum value and logged out. The sensor is also checked at the end to see if the number of samples ready is greater than the maximum FIFO samples allowed and if so then the sensor is reset.

This simple script logs to the console any time a new maximum acceleration reading is output by the LIS2DW12 sensor.

// IMPORTED LIBRARIES
// - LIS2DW12

// Logging setup
log.setLevel(2);   //-1:NONE 0:ERROR 1:WARNING 2:DEBUG 3:TRACE
log.printLevel(2);  //0:DISABLE 1:LOG 2:CONSOLE 3:BOTH
log.clear();

//Use standard interface of NEQTO IO board
nqEx.enI2CS(true);
nqEx.enI2CL(true);

//I2C Config
var baudrate = 400000;
var i2c = new I2C(1);

i2c.open(baudrate);

var lis2dw = new LIS2DW12(i2c);
lis2dw.init();

// Get LIS2DW12 sensor into FIFO mode ready to take readings
lis2dw.setAccFifoMode();

var assertCount = 0;
var maxP = -1;
var maxX = 0;
var maxY = 0;
var maxZ = 0;

while (1) {

    var num = lis2dw.getAccFifoNum();

    if (num == 0) {

        assertCount++;

        if (assertCount >= 10) {
            // Reset sensor
            lis2dw.setAccFifoMode();
            assertCount = 0;
        }
    } else {
        assertCount = 0;
        var mVector = lis2dw.getMaxAccValues(num);

        if (mVector[0] > maxP) {
            maxP = mVector[0];
            maxX = mVector[1];
            maxY = mVector[2];
            maxZ = mVector[3];

            print("Accelerometer current max vector x,y,z values: " + maxX + ", " + maxY + ", " + maxZ);
        }

        if (num == lis2dw.getMaxFifoSamples()) {
            lis2dw.log.warning("Sample overflow!");
            lis2dw.setAccFifoMode();
        }
    }
}

Updated: 2021-02-19
← [Archive] HTS221 Temperature and Humidity SensorRTC Alarm Synchronized Scheduler →
  • Hardware Setup
  • Software Setup
    • Main Functions
  • Example Script
AboutNewsProductsFAQPrivacy PolicyVulnerability Disclosure Policy
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge
NEQTO Bridge ModuleNEQTO Bridge Wi-Fi ModuleNEQTO Bridge LTE-1 ModuleError Logging Event Messages
API Documentation
API UsageGlobal APIRegional APIAPI Terms of Service
Jigsaw, Inc.
© 2025 JIG-SAW INC.