1 /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 /* This test is based on Raspberry Pi with GY-30 Sensor. */
18 var assert = require('assert');
19 var I2C = require('i2c');
23 var wire = i2c.open({device: '/dev/i2c-1', address: 0x23}, function(err) {
29 wire.write([0x10], function(err) {
30 assert.equal(err, null);
31 console.log('write done');
34 wire.writeByte(0x10, function(err) {
35 assert.equal(err, null);
36 console.log('writeByte done');
39 wire.read(2, function(err, res) {
40 assert.equal(err, null);
41 assert.equal(res.length, 2, 'I2C read failed.(length is not equal)');
42 console.log('read result: '+res[0]+', '+res[1]);
45 wire.readByte(function(err, res) {
46 assert.equal(err, null);
47 console.log('readByte result: '+res);
50 wire.readBytes(0x20, 2, function(err, res) {
51 assert.equal(err, null);
52 assert.equal(res.length, 2, 'I2C readBytes failed.(length is not equal)');
53 console.log('readBytes(cmd:0x20, length:2) result: '+res[0]+', '+res[1]);