Giter Club home page Giter Club logo

lps25h's Introduction

Driver for the LPS25H Air Pressure / Temperature Sensor

Author: Tom Byrne

The LPS25H is a MEMS absolute pressure sensor. This sensor features a large functional range (260-1260hPa) and internal averaging for improved precision.

The LPS25H can interface over I²C or SPI. This class addresses only I²C for the time being.

To add this library to your project, add #require "LPS25H.class.nut:1.0.0" to the top of your device code

Hardware

To use the LPS25H, connect the I2C interface to any of the imp's I2C Interfaces. To see which pins can act as an I2C interface, see the imp pin mux on the Electric Imp Developer Center.

The LPS25H's interrupts are not currently supported by this class, as issues have been observed with using the LPS25H's internal reference pressure registers to generate differential pressure measurements.

LPS25H Circuit

Class Usage

Constructor

The constructor takes two arguments to instantiate the class: a pre-configured I²C bus and the sensor’s I²C address. The I²C address is optional and defaults to 0xB8 (8-bit address).

const LPS25H_ADDR = 0xBA;    // non-default 8-bit I2C Address for LPS25H (SA0 pulled high)

hardware.i2c89.configure(CLOCK_SPEED_400_KHZ);
pressureSensor <- LPS25H(hardware.i2c89, LPS25H_ADDR);

Class Methods

enable(state)

Enable (state = true) or disable (state = false) the LPS25H. The device must be enabled before attempting to read the pressure or temperature.

pressure.enable(true);    // Enable the sensor

read(callback)

The read() method reads the pressure in hPa and executes the optional callback passed as its only parameter with the result. The callback takes a single parameter, a table. If an error occurs during the reading, the table passed to the callback will contain a key "err", with a description of the error, and the pressure reading will be null. If the pressure is read successfully, it will be stored in the table with the key "pressure".

If the callback is omitted, read executes synchronously and returns a table. As with the asynchrounous flow, the "err" key is present in the table if an error occurs. The pressure is stored with the "pressure" key.

pressureSensor.read(function(result) {
  if ("err" in result) {
    server.error("An Error Occurred: "+result.err);
  } else {
  	server.log(format("Current Pressure: %0.2f hPa", result.pressure));
  }
});
local result = pressureSensor.read();
if ("err" in result) {
  server.error("An Error Occurred: "+result.err);
} else {
  server.log(format("Current Pressure: %0.2f hPa", result.pressure));
}

getTemp()

Returns temperature in degrees Celsius.

server.log("Current Temperature: "+pressure.getTemp() + " C");

setPressNpts(numberOfReadings)

Set the number of readings taken and then internally averaged to produce a pressure result. The value provided will be rounded up to the nearest valid value: 8, 32 and 128.

// Fastest readings, lowest precision

pressure.setPressNpts(8);

// Slowest readings, highest precision

pressure.setPressNpts(128);

setTempNpts(numberOfReadings)

Set the number of readings taken and internally averaged to produce a temperature result. The value provided will be rounded up to the nearest valid value: 8, 16, 32 and 64.

// Fastest readings, lowest precision

pressure.setTempNpts(8);

// Slowest readings, highest precision

pressure.setTempNpts(64);

softReset()

Reset the LPS25H from software. Device will come up disabled.

pressure.softReset();

License

The LPS25H library is licensed under the MIT License.

lps25h's People

Contributors

cat-haines avatar dtex avatar electricimpsamplecode avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.