pyupm_hp20x module

class pyupm_hp20x.HP20X(bus=0, address=118)[source]

Bases: object

API for the HP20X-based Grove Barometer (High-Accuracy)

ID: hp20x

Name: High-accuracy Barometer

Other Names: HP20X Barometer (High-Accuracy)

Category: pressure

Manufacturer: seeed

Link:http://www.seeedstudio.com/depot/Grove-Barometer- HighAccuracy-p-1865.html

Connection: i2c 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.

C++ includes: hp20x.hpp

CHNL_PT = 0
CHNL_SHIFT = 0
CHNL_T = 2
CMD_ADC_CVT = 64
CMD_ANA_CAL = 40
CMD_READ_A = 49
CMD_READ_AT = 17
CMD_READ_P = 48
CMD_READ_PT = 16
CMD_READ_REG = 128
CMD_READ_T = 50
CMD_SOFT_RST = 6
CMD_WRITE_REG = 192
DSR_1024 = 2
DSR_128 = 5
DSR_2048 = 1
DSR_256 = 4
DSR_4096 = 0
DSR_512 = 3
DSR_SHIFT = 2
INT_CFG_PA_MODE = 64
INT_CFG_PA_RDY_CFG = 32
INT_CFG_PA_TRAV_CFG = 8
INT_CFG_PA_WIN_CFG = 2
INT_CFG_T_RDY_CFG = 16
INT_CFG_T_TRAV_CFG = 4
INT_CFG_T_WIN_CFG = 1
INT_EN_PA_RDY_EN = 32
INT_EN_PA_TRAV_EN = 8
INT_EN_PA_WIN_EN = 2
INT_EN_T_RDY_EN = 16
INT_EN_T_TRAV_EN = 4
INT_EN_T_WIN_EN = 1
INT_SRC_DEV_RDY = 64
INT_SRC_PA_RDY = 32
INT_SRC_PA_TRAV = 8
INT_SRC_PA_WIN = 2
INT_SRC_TH_ERR = 128
INT_SRC_T_RDY = 16
INT_SRC_T_TRAV = 4
INT_SRC_T_WIN = 1
PARA_CMPS_EN = 128
REG_ALT_OFF_LSB = 0
REG_ALT_OFF_MSB = 1
REG_INT_CFG = 12
REG_INT_EN = 11
REG_INT_SRC = 13
REG_PARA = 14
REG_PA_H_TH_LSB = 2
REG_PA_H_TH_MSB = 3
REG_PA_L_TH_LSB = 6
REG_PA_L_TH_MSB = 7
REG_PA_M_TH_LSB = 4
REG_PA_M_TH_MSB = 5
REG_T_H_TH = 8
REG_T_L_TH = 10
REG_T_M_TH = 9
compensationEnable(enable)[source]

void compensationEnable(bool enable)

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

enable: True to enable, false otherwise

getAltitude()[source]

float getAltitude()

Returns the computed altitude in meters

Altitude

getInterruptSource()[source]

uint8_t getInterruptSource()

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

One of more of the INT_SRC_BITS_T values

getPressure()[source]

float getPressure()

Returns the pressure in millibars

Pressure

getTemperature()[source]

float getTemperature()

Returns the temperature in Celsius

Temperature

init(*args)[source]

bool init(DSR_BITS_T dsr=DSR_4096)

Sets up initial values and starts operation

dsr: Data sampling rate; one of the DSR_BITS_T values

True if successful

isReady()[source]

bool isReady()

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

True if the device is ready, false otherwise

readData()[source]

int readData()

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

Value read back (temperature, pressure, etc.)

readReg(reg)[source]

uint8_t readReg(HP20X_REG_T reg)

Reads a register and returns its value

reg: Register to read; one of the HP20X_REG_T values

Value of a specified register

recalibrateInternal()[source]

void recalibrateInternal()

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

setAltitudeOffset(off)[source]

void setAltitudeOffset(int16_t 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.

off: Offset

setDSR(dsr)[source]

void setDSR(DSR_BITS_T dsr)

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

dsr: One of the DSR_BITS_T values

setInterruptConfig(bits)[source]

bool setInterruptConfig(uint8_t bits)

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

bits: One or more of the INT_EN_BITS_T bits

True if successful, false otherwise

setInterruptEnable(bits)[source]

bool setInterruptEnable(uint8_t bits)

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

bits: One or more of the INT_EN_BITS_T bits

True if successful, false otherwise

setPAThreshholds(low, med, high)[source]

void setPAThreshholds(int16_t low, int16_t med, int16_t high)

Sets pressure/altitude thresholds for interrupt generation

low: Low threshold to generate an interrupt

med: Medium threshold to generate an interrupt

high: High threshold to generate an interrupt

setTemperatureThreshholds(low, med, high)[source]

void setTemperatureThreshholds(int8_t low, int8_t med, int8_t high)

Sets temperature thresholds for interrupt generation

low: Low threshold to generate an interrupt

med: Medium threshold to generate an interrupt

high: High threshold to generate an interrupt

softReset()[source]

void 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.

waitforDeviceReady()[source]

bool waitforDeviceReady()

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

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

writeCmd(cmd)[source]

bool writeCmd(uint8_t cmd)

Sends a command to the device

cmd: Command to send; usually, one of the HP20X_CMD_T values

True if successful

writeReg(reg, data)[source]

bool writeReg(HP20X_REG_T reg, uint8_t data)

Writes a value to a register

reg: Register to write to; one of the HP20X_REG_T values

data: Value to write

True if successful