2.0.0 • Published 5 years ago

j5-sparkfun-weather-shield v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

SparkFun Weather Shield

Build Status

For use with Johnny-Five.

  • SparkFun Weather Shield DEV-13956, 13956 (Current)

    • Humidity/Temperature Sensor - Si7021
    • Barometric Pressure - MPL3115A2
    • Light Sensor - ALS-PT19
  • SparkFun Weather Shield DEV-12081, 12081 (Retired)

    • Humidity/Temperature Sensor - HTU21D
    • Barometric Pressure - MPL3115A2
    • Light Sensor - ALS-PT19

API & Documentation

For use with Particle Photon:

npm install johnny-five particle-io j5-sparkfun-weather-shield

For use with Arduino:

npm install johnny-five j5-sparkfun-weather-shield

Weather

The Weather class constructs objects that represent the built-in components of the shield.

  • Explicit Initialization, defaults "data" to 25ms intervals

    const weather = new Weather({
      variant: "DEV-13956",
    });
    
    ...or...
    
    const weather = new Weather({
      variant: "DEV-13674",
    });
  • Explicit Initialization, specify "data" to 200ms intervals

    const weather = new Weather({
      variant: "DEV-13956",
      period: 200
    });
    
    ...or...
    
    const weather = new Weather({
      variant: "DEV-13674",
      period: 200
    });

Parameters

PropertyTypeValue(s)/DescriptionDefaultRequiredVersion
variantstring"ARDUINO", "PHOTON"noyesv0.1.0-v1.0.0
variantstring or numberSee Variantsnoyesv2.0.0+
elevationnumberBase elevation in meters (You can use whatismyelevation.com to find out the base elevation for your location)yes *yesall
freqnumberUse period25 (ms)nov0.1.0-v1.0.0
periodnumberMilliseconds. The rate in milliseconds to emit the data event25 (ms)nov2.0.0+

* If elevation is omitted, the value of the feet and meters properties will be null. When elevation is included, there is a 3 second calibration window before all values are reported.

Variants

ShieldProduct NameVariant ValuesRetired ?
SparkFun Weather Shield"DEV-13956", "DEV13956", 13956No
SparkFun Weather Shield"DEV-12081", "DEV12081", 12081Yes
SparkFun Photon Weather Shield"DEV-13674", "DEV13674", 13674No
SparkFun Photon Weather Shield"DEV-13630", "DEV13630", 13630Yes

Using the Arduino shield

(Without a specified elevation)

const five = require("johnny-five");
const Weather = require("j5-sparkfun-weather-shield")(five);
const board = new five.Board();

board.on("ready", () => {
  const weather = new Weather({
    variant: "DEV-13956",
    period: 200
  });

  weather.on("data", () => {
    const {
      celsius,
      fahrenheit,
      kelvin,
      pressure,
      relativeHumidity,
      lightLevel
    } = weather;

    console.log("celsius: %d°C", celsius);
    console.log("fahrenheit: %d°F", fahrenheit);
    console.log("kelvin: %d°K", kelvin);
    console.log("pressure: %d kPa", pressure);
    console.log("relativeHumidity: %d RH", relativeHumidity);
    console.log("lightLevel: %d%", lightLevel);
    console.log("----------------------------------------");
  });
});

(With a specified elevation)

const five = require("johnny-five");
const Weather = require("j5-sparkfun-weather-shield")(five);
const board = new five.Board();

board.on("ready", () => {
  const weather = new Weather({
    variant: "DEV-13956",
    period: 200, 
    // Set your base elevation with a value in meters,
    // as reported by http://www.whatismyelevation.com/.
    // `5` is the elevation (meters) of the
    // Bocoup office in downtown Boston
    elevation: 5,
  });

  // Including elevation for altitude readings will
  // incure an additional 3 second calibration time.
  weather.on("data", () => {
    const {
      celsius,
      fahrenheit,
      kelvin,
      pressure,
      feet,
      meters,
      relativeHumidity,
      lightLevel
    } = weather;

    console.log("celsius: %d°C", celsius);
    console.log("fahrenheit: %d°F", fahrenheit);
    console.log("kelvin: %d°K", kelvin);
    console.log("pressure: %d kPa", pressure);
    console.log("feet: %d'", feet);
    console.log("meters: %d", meters);
    console.log("relativeHumidity: %d RH", relativeHumidity);
    console.log("lightLevel: %d%", lightLevel);
    console.log("----------------------------------------");
  });
});

Using the Photon shield

(Without a specified elevation)

const Particle = require("particle-io");
const five = require("johnny-five");
const Weather = require("j5-sparkfun-weather-shield")(five);
const board = new five.Board({
  io: new Particle({
    token: process.env.PARTICLE_TOKEN,
    deviceId: process.env.PARTICLE_PHOTON_DEVICE_ID
  })
});

board.on("ready", function() {
  var weather = new Weather({
    variant: "DEV-13674",
    period: 200
  });

  weather.on("data", () => {
    const {
      celsius,
      fahrenheit,
      kelvin,
      pressure,
      relativeHumidity,
      lightLevel
    } = weather;

    console.log("celsius: %d°C", celsius);
    console.log("fahrenheit: %d°F", fahrenheit);
    console.log("kelvin: %d°K", kelvin);
    console.log("pressure: %d kPa", pressure);
    console.log("relativeHumidity: %d RH", relativeHumidity);
    console.log("lightLevel: %d%", lightLevel);
    console.log("----------------------------------------");
  });
});

(With a specified elevation)

const Particle = require("particle-io");
const five = require("johnny-five");
const Weather = require("j5-sparkfun-weather-shield")(five);
const board = new five.Board({
  io: new Particle({
    token: process.env.PARTICLE_TOKEN,
    deviceId: process.env.PARTICLE_PHOTON_DEVICE_ID
  })
});

board.on("ready", () => {
  const weather = new Weather({
    variant: "DEV-13674",
    period: 200,
    // Set your base elevation with a value in meters,
    // as reported by http://www.whatismyelevation.com/.
    // `5` is the elevation (meters) of the
    // Bocoup office in downtown Boston
    elevation: 5,  
  });

  // Including elevation for altitude readings will
  // incure an additional 3 second calibration time.
  weather.on("data", () => {
    const {
      celsius,
      fahrenheit,
      kelvin,
      pressure,
      feet,
      meters,
      relativeHumidity,
      lightLevel
    } = weather;

    console.log("celsius: %d°C", celsius);
    console.log("fahrenheit: %d°F", fahrenheit);
    console.log("kelvin: %d°K", kelvin);
    console.log("pressure: %d kPa", pressure);
    console.log("feet: %d'", feet);
    console.log("meters: %d", meters);
    console.log("relativeHumidity: %d RH", relativeHumidity);
    console.log("lightLevel: %d%", lightLevel);
    console.log("----------------------------------------");
  });
});

Convenient serialization for data payloads:

const weather = new Weather({
  variant: ...
});

weather.on("data", () => {
  console.log(JSON.stringify(weather, null, 2));
});

Produces:

{
  "celsius": 24,
  "fahrenheit": 75.2,
  "kelvin": 297.15,
  "pressure": 125.5,
  "feet": 3.28,
  "meters": 1,
  "relativeHumidity": 48,
  "lightLevel": 50
}

Since the Photon shield does not include the ALS-PT19 light sensor, the lightLevel property will always be null for that variant.

NOTE

The examples shown here are provided for illustration and do no specifically indicate variant support. This component class is expected to work with any variant that has I2C support.

2.0.0

5 years ago

1.0.0

5 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago