Skip to content

Instantly share code, notes, and snippets.

@ersatzavian
Created April 24, 2015 21:39
Show Gist options
  • Save ersatzavian/56522ad28d1bb037e45c to your computer and use it in GitHub Desktop.
Save ersatzavian/56522ad28d1bb037e45c to your computer and use it in GitHub Desktop.
9dof-tail-log
device.on("data", function(data) {
server.log(http.jsonencode(data));
});
// https://github.com/electricimp/lsm9ds0
#require "LSM9DS0.class.nut:1.0"
i2c <- hardware.i2c89;
i2c.configure(CLOCK_SPEED_400_KHZ);
imu <- LSM9DS0(i2c);
function poll() {
imp.wakeup(1,poll);
local acc = imu.getAccel();
local mag = imu.getMag();
local gyr = imu.getGyro();
agent.send("data", {
acc = acc,
mag = mag,
gyr = gyr
});
}
/* RUNTIME START ------------------------------------------------------------ */
// Enable the gyro in all axes
imu.setPowerState_G(1);
// Enable Accelerometer in all axes
imu.setEnable_A(1);
// Set the Accelerometer data rate to a nonzero value
imu.setDatarate_A(10); // 10 Hz
// Enable the Magnetometer by setting the ODR to a non-zero value
imu.setDatarate_M(50); // 50 Hz
imu.setModeCont_M(); // enable continuous measurement
poll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment