Run with:
node eg/hmc5883l.js
var Board = require("firmata").Board,
address, board;
address = 0x1E;
board = new Board("/dev/tty.usbmodem411", function() {
var x, y, z, interval;
board.sendI2CConfig();
board.on("string",function( string ) {
console.log("string", string);
});
// Continuous measurement mode
board.sendI2CWriteRequest( address, [ 0x02, 0x00 ] );
// Set pointer to XMSB
board.sendI2CWriteRequest( address, [ 0x03 ] );
// initial interval wait time is 500ms
interval = 500;
setInterval(function() {
// Read 6 bytes from the register
board.sendI2CReadRequest( address, 6, function( data ) {
// The HMC5883L returns data in this order:
//
// XX ZZ YY
//
// x, y, z are initialized at top of board ready callback
// // XX 0, 1
// x = data[0] | data[1] & 0xFF;
// // ZZ 2, 3
// z = data[2] | data[3] & 0xFF;
// // YY 4, 5
// y = data[4] | data[5] & 0xFF;
// XX 0, 1
x = ( data[0] << 8 ) | data[1];
// ZZ 2, 3
z = ( data[2] << 8 ) | data[3];
// YY 4, 5
y = ( data[4] << 8 ) | data[5];
console.log( x, y, z );
});
}, interval );
});
/**
Example run:
194 3 65330
195 1 65330
195 3 65330
195 0 65330
195 2 65330
195 5 65331
197 7 65333
191 48 65347
155 101 65355
140 111 65351
113 125 65350
91 135 65351
96 131 65348
117 121 65347
141 104 65346
174 76 65346
207 26 65348
214 65527 65352
206 65488 65347
201 65478 65342
201 65479 65342
193 65467 65333
208 7 65357
176 75 65351
142 101 65348
134 103 65346
134 102 65346
*/
(Nothing yet)
All contributions must adhere to the the Idiomatic.js Style Guide, by maintaining the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
(Nothing yet)
Copyright (c) 2012 Rick Waldron waldron.rick@gmail.com Licensed under the MIT license.