Created
March 14, 2019 06:26
-
-
Save DavidIAm/8ac1ee025f1a4d2491fa95761bf0cad2 to your computer and use it in GitHub Desktop.
test node program for i2c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const i2c = require("i2c-bus"); | |
const OSM_ADDR = 0x0b; | |
const I2C_START = 0x90; | |
const SET_PWM = 0xA0; | |
const RESET = 0xA0; | |
const i2c1 = new Promise((resolve, reject) => { | |
const handle = i2c.open(1, (err) => err ? reject(err) : resolve(handle)) | |
}); | |
i2c1.then(handle => { | |
const request = Buffer.from([ I2C_START, 0x03, 0x40, 0x00, 0x42 ]); | |
handle.i2cWriteSync(OSM_ADDR, request.length, request) | |
process.exit(); | |
}) | |
/* | |
i2c1.then(handle => { | |
const request = Buffer.from([ I2C_START, 0x07, SET_PWM, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]); | |
const response = Buffer.alloc(3); | |
handle.i2cWriteSync(OSM_ADDR, request.length, request) | |
handle.i2cReadSync(OSM_ADDR, 0x03, response) | |
console.log(response) | |
}) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment