Skip to content

Commit

Permalink
Multi: make altitude calibration contingent on user specifying opts.e…
Browse files Browse the repository at this point in the history
…levation
  • Loading branch information
rwaldron committed Oct 13, 2015
1 parent 242c5b4 commit 382765a
Show file tree
Hide file tree
Showing 13 changed files with 484 additions and 425 deletions.
11 changes: 7 additions & 4 deletions docs/altimeter-mpl3115a2.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
var barometer = new five.Altimeter({
var altitude = new five.Altimeter({
controller: "MPL3115A2",
// change altitudeOffset with whatever is reported
// Change `elevation` with whatever is reported
// on http://www.whatismyelevation.com/.
// `12` is the elevation (meters) for where I live in Brooklyn
altitudeOffset: 12,
elevation: 12,
});

barometer.on("data", function() {
altitude.on("data", function() {
console.log("Altitude");
console.log(" feet : ", this.feet);
console.log(" meters : ", this.meters);
Expand All @@ -61,6 +61,9 @@ board.on("ready", function() {

## Additional Notes
- [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
- [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
- [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
- [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)


## Learn More
Expand Down
5 changes: 4 additions & 1 deletion docs/barometer-mpl3115a2.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ board.on("ready", function() {


## Additional Notes
- [MPLe115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
- [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
- [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
- [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
- [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)


## Learn More
Expand Down
11 changes: 9 additions & 2 deletions docs/multi-mpl3115a2.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ var board = new five.Board();
board.on("ready", function() {
var multi = new five.Multi({
controller: "MPL3115A2",
// change altitudeOffset with whatever is reported
// Change `elevation` with whatever is reported
// on http://www.whatismyelevation.com/.
// `12` is the elevation (meters) for where I live in Brooklyn
altitudeOffset: 12,
elevation: 12,
});

multi.on("change", function() {
Expand All @@ -59,6 +59,7 @@ board.on("ready", function() {
});
});


```


Expand All @@ -68,6 +69,12 @@ board.on("ready", function() {



## Additional Notes
- [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
- [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
- [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
- [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)


## Learn More

Expand Down
5 changes: 4 additions & 1 deletion docs/temperature-mpl3115a2.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ board.on("ready", function() {


## Additional Notes
- [MPLe115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
- [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
- [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
- [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
- [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)


## Learn More
Expand Down
11 changes: 7 additions & 4 deletions eg/altimeter-mpl3115a2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ var five = require("../lib/johnny-five.js");
var board = new five.Board();

board.on("ready", function() {
var barometer = new five.Altimeter({
var altitude = new five.Altimeter({
controller: "MPL3115A2",
// change altitudeOffset with whatever is reported
// Change `elevation` with whatever is reported
// on http://www.whatismyelevation.com/.
// `12` is the elevation (meters) for where I live in Brooklyn
altitudeOffset: 12,
elevation: 12,
});

barometer.on("data", function() {
altitude.on("data", function() {
console.log("Altitude");
console.log(" feet : ", this.feet);
console.log(" meters : ", this.meters);
Expand All @@ -20,4 +20,7 @@ board.on("ready", function() {

// @markdown
// - [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
// - [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
// - [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
// - [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)
// @markdown
5 changes: 4 additions & 1 deletion eg/barometer-mpl3115a2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ board.on("ready", function() {
});

// @markdown
// - [MPLe115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
// - [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
// - [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
// - [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
// - [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)
// @markdown
11 changes: 9 additions & 2 deletions eg/multi-mpl3115a2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ var board = new five.Board();
board.on("ready", function() {
var multi = new five.Multi({
controller: "MPL3115A2",
// change altitudeOffset with whatever is reported
// Change `elevation` with whatever is reported
// on http://www.whatismyelevation.com/.
// `12` is the elevation (meters) for where I live in Brooklyn
altitudeOffset: 12,
elevation: 12,
});

multi.on("change", function() {
Expand All @@ -27,3 +27,10 @@ board.on("ready", function() {
console.log("--------------------------------------");
});
});

// @markdown
// - [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
// - [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
// - [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
// - [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)
// @markdown
5 changes: 4 additions & 1 deletion eg/temperature-mpl3115a2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ board.on("ready", function() {
});

// @markdown
// - [MPLe115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
// - [MPL3115A2 - I2C Barometric Pressure/Altimiter/Temperature Sensor](https://www.adafruit.com/products/1893)
// - [SparkFun Altitude/Pressure Sensor Breakout - MPL3115A2](https://www.sparkfun.com/products/11084)
// - [SparkFun Weather Shield](https://www.sparkfun.com/products/12081)
// - [SparkFun Photon Weather Shield](https://www.sparkfun.com/products/13630)
// @markdown
2 changes: 1 addition & 1 deletion lib/altimeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Controllers = {
var priv = new Map();

function Altimeter(opts) {
var controller, freq, last = 0, raw;
var controller, freq, last = 0, raw = 0;

if (!(this instanceof Altimeter)) {
return new Altimeter(opts);
Expand Down
33 changes: 21 additions & 12 deletions lib/imu.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ var Drivers = {
var READLENGTH = 6;
var io = board.io;
var address = opts.address || this.ADDRESSES[0];
var elevation = null;
var isPressure = false;

// See http://www.henrylahr.com/?p=99 for implementation approach
//
Expand All @@ -247,7 +249,9 @@ var Drivers = {
temperature: 0
};

opts.altitudeOffset = opts.altitudeOffset || 0;
if (typeof opts.elevation !== "undefined") {
elevation = opts.elevation;
}

var waitForReady = function(next) {
io.i2cReadOnce(address, this.REGISTER.STATUS, 1, function(data) {
Expand All @@ -261,7 +265,7 @@ var Drivers = {
}.bind(this));
}.bind(this);

var readValues = function(isPressure) {
var readValues = function() {
var modeMask = isPressure ? this.MASK.CONTROL.PRESSURE : this.MASK.CONTROL.ALTIMETER;
var mode = this.MASK.CONTROL.SBYB | this.MASK.CONTROL.OS128 | modeMask;

Expand Down Expand Up @@ -290,17 +294,13 @@ var Drivers = {
computed.altitude = altNow;
}

readValues(!isPressure);
isPressure = !isPressure;

readValues();
}.bind(this));
}.bind(this));
}.bind(this);

io.i2cConfig(opts);

// configure the chip
// Set Altitude Offset.
io.i2cWriteReg(address, 0x2D, 0x00);

var reads = [];
var calibrate = function() {
// Clear Oversampling and OST
Expand All @@ -317,9 +317,8 @@ var Drivers = {
reads.push((m << 10 | c << 2) + fl);

if (reads.length === 4) {

var curpress = (reads[0] + reads[1] + reads[2] + reads[3]) / 4;
var seapress = curpress / Math.pow(1 - opts.altitudeOffset * 0.0000225577, 5.255877);
var seapress = curpress / Math.pow(1 - elevation * 0.0000225577, 5.255877);

// Update Barometric input for Altitude
io.i2cWrite(address, this.REGISTER.BAR_IN_MSB, (seapress / 2) >> 8);
Expand Down Expand Up @@ -350,12 +349,22 @@ var Drivers = {
}.bind(this), 500);
}.bind(this);

io.i2cConfig(opts);

// configure the chip
// Set Altitude Offset.
io.i2cWriteReg(address, 0x2D, 0x00);

io.i2cWrite(address, this.REGISTER.DATA_CONFIG,
this.MASK.DATA_CONFIG.TDEFE |
this.MASK.DATA_CONFIG.PDEFE |
this.MASK.DATA_CONFIG.DREM);

calibrate();
if (elevation !== null) {
calibrate();
} else {
readValues();
}
}
},
identifier: {
Expand Down
Loading

0 comments on commit 382765a

Please sign in to comment.