Compass Sensor - HMC5883L

TRIPLE-AXIS magnetometer (compass)

Calibration is important to get correct direction.

Datasheet

wired(obniz, { [gnd, sda, scl, i2c]});

Connect to an obniz.

obniz can't supply a power to this sensor directly.
Use external 3.3v or use linear regulator to drop 5v output of obniz to 3.3v.

// Javascript Example
var compass = obniz.wired("HMC5883L", {gnd:1 , sda:2 , scl:3 });
compass.init();
while(true) {
  var obj = await compass.get();
  console.log(obj.x, obj.y, obj.z);
}

init();

initialize the sensor.

// Javascript Example
var compass = obniz.wired("HMC5883L", {gnd:1 , sda:2 , scl:3 });
compass.init();

[await] get()

get x,y,z result object from a sensor.

// Javascript Example
var compass = obniz.wired("HMC5883L", {gnd:1 , sda:2 , scl:3 });
compass.init();
while(true) {
  var obj = await compass.get();
  console.log(obj.x, obj.y, obj.z);
}


Found at :