Skip to content

Instantly share code, notes, and snippets.

@DavidIAm
Created March 14, 2019 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidIAm/8ac1ee025f1a4d2491fa95761bf0cad2 to your computer and use it in GitHub Desktop.
Save DavidIAm/8ac1ee025f1a4d2491fa95761bf0cad2 to your computer and use it in GitHub Desktop.
test node program for i2c
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