UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

HP20X Class

Module: hp20x

This is a high-accuracy barometer providing pressure, altitude, and temperature data. It can be calibrated for a given altitude offset, and a wide range of interrupt generating capabilities are supported. As usual, see the HP20X datasheet for more details.
This module was developed using a Grove Barometer (High-Accuracy) based on an HP206C chip.
hp20x.jpg

Methods

HP20X

(
  • bus
  • address
)
Number

HP20X constructor

Parameters:

  • bus Number

    I2C bus to use

  • address Number

    Address for this device

Returns:

Number:

init

(
  • dsr
)
Boolean

Sets up initial values and starts operation

Parameters:

  • dsr DSR_BITS_T

    Data sampling rate; one of the DSR_BITS_T values

Returns:

Boolean:

True if successful

writeCmd

(
  • cmd
)
Boolean

Sends a command to the device

Parameters:

  • cmd Number

    Command to send; usually, one of the HP20X_CMD_T values

Returns:

Boolean:

True if successful

writeReg

(
  • reg
  • data
)
Boolean

Writes a value to a register

Parameters:

  • reg HP20X_REG_T

    Register to write to; one of the HP20X_REG_T values

  • data Number

    Value to write

Returns:

Boolean:

True if successful

readReg

(
  • reg
)
Number

Reads a register and returns its value

Parameters:

  • reg HP20X_REG_T

    Register to read; one of the HP20X_REG_T values

Returns:

Number:

Value of a specified register

readData

() Number

Reads 3 bytes of data in response to a conversion request, and converts it to an integer

Returns:

Number:

Value read back (temperature, pressure, etc.)

isReady

() Boolean

Checks to see if the DR_RDY bit is set, indicating the device can accept commands

Returns:

Boolean:

True if the device is ready, false otherwise

waitforDeviceReady

() Boolean

Checks to see if the device is ready, and sleeps/retries if not. Returns once the device indicates it's ready.

Returns:

Boolean:

True if the device is ready; false if retries are exhausted

getTemperature

() Number

Returns the temperature in Celsius

Returns:

Number:

Temperature

getPressure

() Number

Returns the pressure in millibars

Returns:

Number:

Pressure

getAltitude

() Number

Returns the computed altitude in meters

Returns:

Number:

Altitude

compensationEnable

(
  • enable
)

Enables or disables the on-chip compensator. This allows the chip to filter and clean up the output data.

Parameters:

  • enable Boolean

    True to enable, false otherwise

setInterruptEnable

(
  • bits
)
Boolean

Sets up the interrupt enable register. This register defines which events can cause a hardware interrupt pin to be pulled high (active).

Parameters:

  • bits Number

    One or more of the INT_EN_BITS_T bits

Returns:

Boolean:

True if successful, false otherwise

setInterruptConfig

(
  • bits
)
Boolean

Sets up the interrupt configuration register. This register defines which events can cause an interrupt to be indicated.

Parameters:

  • bits Number

    One or more of the INT_EN_BITS_T bits

Returns:

Boolean:

True if successful, false otherwise

getInterruptSource

() Number

Gets the interrupt source register. This register indicates which interrupts have been triggered. In addition, it indicates when certain operations have been completed.

Returns:

Number:

One of more of the INT_SRC_BITS_T values

setDSR

(
  • dsr
)

Sets the data sampling rate. Higher rates are more precise, but take more time per measurement.

Parameters:

  • dsr DSR_BITS_T

    One of the DSR_BITS_T values

recalibrateInternal

()

Starts an internal recalibration of analog blocks. This is faster than a soft reset.

softReset

()

Executes a soft reset. All register values are reset to power-on defaults. This function returns when the reset is complete and the device reports it is ready.

setAltitudeOffset

(
  • off
)

Sets the altitude offset for your region. See the datasheet for more details. Setting this correctly for your region is required for accurate altitude data.

Parameters:

  • off Number

    Offset

setPAThreshholds

(
  • low
  • med
  • high
)

Sets pressure/altitude thresholds for interrupt generation

Parameters:

  • low Number

    Low threshold to generate an interrupt

  • med Number

    Medium threshold to generate an interrupt

  • high Number

    High threshold to generate an interrupt

setTemperatureThreshholds

(
  • low
  • med
  • high
)

Sets temperature thresholds for interrupt generation

Parameters:

  • low Number

    Low threshold to generate an interrupt

  • med Number

    Medium threshold to generate an interrupt

  • high Number

    High threshold to generate an interrupt

Properties

CMD_SOFT_RST

Enum HP20X_CMD_T

CMD_ADC_CVT

Enum HP20X_CMD_T

CMD_READ_PT

Enum HP20X_CMD_T

CMD_READ_AT

Enum HP20X_CMD_T

CMD_READ_P

Enum HP20X_CMD_T

CMD_READ_A

Enum HP20X_CMD_T

CMD_READ_T

Enum HP20X_CMD_T

CMD_ANA_CAL

Enum HP20X_CMD_T

CMD_READ_REG

Enum HP20X_CMD_T

CMD_WRITE_REG

Enum HP20X_CMD_T

CHNL_PT

Enum CHNL_BITS_T

CHNL_T

Enum CHNL_BITS_T

CHNL_SHIFT

Enum CHNL_BITS_T

DSR_4096

Enum DSR_BITS_T

DSR_2048

Enum DSR_BITS_T

DSR_1024

Enum DSR_BITS_T

DSR_512

Enum DSR_BITS_T

DSR_256

Enum DSR_BITS_T

DSR_128

Enum DSR_BITS_T

DSR_SHIFT

Enum DSR_BITS_T

REG_ALT_OFF_LSB

Enum HP20X_REG_T

REG_ALT_OFF_MSB

Enum HP20X_REG_T

REG_PA_H_TH_LSB

Enum HP20X_REG_T

REG_PA_H_TH_MSB

Enum HP20X_REG_T

REG_PA_M_TH_LSB

Enum HP20X_REG_T

REG_PA_M_TH_MSB

Enum HP20X_REG_T

REG_PA_L_TH_LSB

Enum HP20X_REG_T

REG_PA_L_TH_MSB

Enum HP20X_REG_T

REG_T_H_TH

Enum HP20X_REG_T

REG_T_M_TH

Enum HP20X_REG_T

REG_T_L_TH

Enum HP20X_REG_T

REG_INT_EN

Enum HP20X_REG_T

REG_INT_CFG

Enum HP20X_REG_T

REG_INT_SRC

Enum HP20X_REG_T

REG_PARA

Enum HP20X_REG_T

INT_EN_T_WIN_EN

Enum INT_EN_BITS_T

INT_EN_PA_WIN_EN

Enum INT_EN_BITS_T

INT_EN_T_TRAV_EN

Enum INT_EN_BITS_T

INT_EN_PA_TRAV_EN

Enum INT_EN_BITS_T

INT_EN_T_RDY_EN

Enum INT_EN_BITS_T

INT_EN_PA_RDY_EN

Enum INT_EN_BITS_T

INT_CFG_T_WIN_CFG

Enum INT_CFG_BITS_T

INT_CFG_PA_WIN_CFG

Enum INT_CFG_BITS_T

INT_CFG_T_TRAV_CFG

Enum INT_CFG_BITS_T

INT_CFG_PA_TRAV_CFG

Enum INT_CFG_BITS_T

INT_CFG_T_RDY_CFG

Enum INT_CFG_BITS_T

INT_CFG_PA_RDY_CFG

Enum INT_CFG_BITS_T

INT_CFG_PA_MODE

Enum INT_CFG_BITS_T

INT_SRC_T_WIN

Enum INT_SRC_BITS_T

INT_SRC_PA_WIN

Enum INT_SRC_BITS_T

INT_SRC_T_TRAV

Enum INT_SRC_BITS_T

INT_SRC_PA_TRAV

Enum INT_SRC_BITS_T

INT_SRC_T_RDY

Enum INT_SRC_BITS_T

INT_SRC_PA_RDY

Enum INT_SRC_BITS_T

INT_SRC_DEV_RDY

Enum INT_SRC_BITS_T

INT_SRC_TH_ERR

Enum INT_SRC_BITS_T

PARA_CMPS_EN

Enum PARA_BITS_T