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

›neqto.js

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 CloudSync for GCP
  • NEQTO Engine Firmware List
  • Support Guidelines

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. Utils
    • 14. nqLinux
    • 15. nqService
    • 16. nqMqtt
    • 17. nqFOTA
    • 18. 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
    • 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
  • SAP Cloud Platform Internet of Things
  • Splunk
  • Niagara

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

15. I2C

The I2C object is a built-in object that provides I2C communication functions.

Functional overview:

  • Provides I2C master mode function.



Abstracts

Methods()/PropertiesSummaryVersionNote
new I2C()Creates an I2C instance.00.00.15+

{I2C} Instance

Methods()/PropertiesSummaryVersionNote
.open()Starts the communication.00.00.15+
.close()Ends the communication.00.00.15+
.write()Writes the data.00.00.15+
.read()Reads the data.00.00.15+
.writeRead()Reads the data after writing the data.00.00.23+


Details

new I2C(nodeNo)

Creates an I2C instance.

NameTypeM/OSummaryNote
nodeNonumbermandatorySpecifies the node number of the I2C interface to be used.
Please refer to Pinout.
return{I2C}-{I2C} : Generated {I2C}

.open(baudrate)

Starts the communication.

NameTypeM/OSummaryNote
baudratenumbermandatoryCommunication speed
Specify the communication baudrate [bps].
Range: 100000, 400000
returnboolean-true: Success
false: Failure

.close()

Ends the communication.

NameTypeM/OSummaryNote
returnboolean-true: Success
false: Failure

.write(slaveAddr,buff)

Writes the data.

NameTypeM/OSummary                                        Note
slaveAddrnumbermandatorySlave address of the I2C device
Range: 0 - 127 (7 bit)
buffArrayBuffermandatoryWrite data
ArrayBuffer size will be written.
The size that can be written at a time is 255 bytes.
returnboolean-true: Success
false: Failure

When the data length is 1 byte, use Uint8Array as follows:

var buff = new ArrayBuffer(1);
var arr = new Uint8Array(buff);
arr[0] = your_data;
var ret = i2c.write(slave_address, buff);

.read(slaveAddr,len)

Reads the data.

NameTypeM/OSummary                                        Note
slaveAddrnumbermandatorySlave address of the I2C device
Range: 0 - 127 (7 bit)
lennumbermandatorySpecify the read data length.The maximum size that can be read at a time is 255 bytes.
returnArraybuffer-Read data
If read function fails, the returned size will be 0.

.writeRead(slaveAddr,buff,len)

Reads the data after writing the data.

NameTypeM/OSummary                                        Note
slaveAddrnumbermandatorySlave address of the I2C device
Range: 0 - 127 (7 bit)
buffArrayBuffermandatoryWrite data
ArrayBuffer size will be written.
The size that can be written at a time is 255 bytes.
lennumbermandatorySpecify the read data length.The maximum size that can be read at a time is 255 bytes.
returnArraybuffer-Read data
If the reading fails, the returned size will be 0.



Object Usage Examples

Sample 1

This sample is an I2C device with a slave address of 0x3A, which writes 0x03 to register 0x05, and then reads 1 byte from register 0x06.

var NODE_NO = 1;
var BAUDRATE = 400000;
var SLAVE_ADDR = 0x3A; //slave address

//I2C write function
var write = function(i2c, reg, data) {
    var buf = new ArrayBuffer(2);
    var arr = new Uint8Array(buf);
    arr[0] = reg;
    arr[1] = data;
    var ret = i2c.write(SLAVE_ADDR, buf);
    if (!ret) print('I2C write error');
    return ret;
};

//I2C read function
var read = function(i2c, reg) {
    var buf = new ArrayBuffer(1);
    var arr = new Uint8Array(buf);
    arr[0] = reg;
    if(!i2c.write(SLAVE_ADDR, buf)) {
        print('I2C read error');
        return 0;
    }
    var retBuf = i2c.read(SLAVE_ADDR, 1);
    if (!retBuf.byteLength) print('I2C read error2');
    var ret = new Uint8Array(retBuf);
    return ret[0];
};

var i2c = new I2C(NODE_NO);
i2c.open(BAUDRATE);

write(i2c, 0x05, 0x03);
read(i2c, 0x06);

i2c.close();

Sample 2

This sample is an I2C device with a slave address of 0x3A, which writes 0x03 to register 0x05, and then reads 1 byte.

var NODE_NO = 1;
var BAUDRATE = 400000;
var SLAVE_ADDR = 0x3A; //slave address

//I2C writeRead function
var writeRead = function(i2c, reg, data) {
    var buf = new ArrayBuffer(2);
    var arr = new Uint8Array(buf);
    arr[0] = reg;
    arr[1] = data;
    var retBuf = i2c.writeRead(SLAVE_ADDR, buf, 1);
    if (!retBuf.byteLength) print('I2C write read error');
    var ret = new Uint8Array(retBuf);
    return ret[0];
};

var i2c = new I2C(NODE_NO);
i2c.open(BAUDRATE);

writeRead(i2c, 0x05, 0x03);

i2c.close();



Updated: 2020-09-18
← 14. SPI16. ADC →
  • Abstracts
  • {I2C} Instance
  • Details
    • new I2C(nodeNo)
    • .open(baudrate)
    • .close()
    • .write(slaveAddr,buff)
    • .read(slaveAddr,len)
    • .writeRead(slaveAddr,buff,len)
  • Object Usage Examples
    • Sample 1
    • Sample 2
AboutNewsProductsFAQPrivacy 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.
© 2023 JIG-SAW INC.