cancel
Showing results for 
Search instead for 
Did you mean: 

Wrong pressure reading from LPS25HB sensor.

Posted on August 01, 2017 at 18:56

Hi all,

I am evaluating the LPS25HB pressure sensor on iMX6 host processor, I am interested in getting the altitude for our usecase.

The problem is  I am getting consistent value of pressure with no change even when I  moved from floor to floor in the elevator. Can someone help me in solving this issue?

Here is the simple code which I am using:

const double read_pressure(void)

{

    double pressure = 0.0;

    int pres_raw = 0;

    unsigned char pdataReady = 0;

   qDebug() << Q_FUNC_INFO << 'entry';

    pdataReady = i2c_smbus_read_byte_data(file_i2c, LPS25HB_STATUS_REG);

    while(!(pdataReady & 0x02))

        pdataReady = i2c_smbus_read_byte_data(file_i2c, LPS25HB_STATUS_REG); //loop until pressure data is ready

    pres_raw  = i2c_smbus_read_byte_data(file_i2c, LPS25HB_PRESS_OUT_XL);

    pres_raw |= (int32_t) i2c_smbus_read_byte_data(file_i2c, LPS25HB_PRESS_OUT_L) << 8;

    pres_raw |= (int32_t) i2c_smbus_read_byte_data(file_i2c, LPS25HB_PRESS_OUT_H) << 16;

    qDebug() << Q_FUNC_INFO << pres_raw;

    pressure = pres_raw / 4096.0;

    return pressure;

}

int main(int argc, char *argv[])

{

    int i;

    int alti;

    unsigned char txBuff[5];

    unsigned char rxBuff[32] = {0};

    unsigned char tmp;

   //altimeter_init(LPS25HB_ODR_7HZ);

   file_i2c = open('/dev/i2c-2', O_RDWR);

   file_ioc = ioctl(file_i2c, I2C_SLAVE, 0x5d);

   tmp = i2c_smbus_read_byte_data(file_i2c, LPS25HB_WHO_AM_I_REG);

   qDebug() << Q_FUNC_INFO << 'client_id' << tmp;

   tmp = LPS25HB_PD_MASK;

   tmp |= LPS25HB_BDU_MASK;

   tmp |= 0x20; // set ODR to 7HZ

   i2c_smbus_write_byte_data(file_i2c, LPS25HB_CTRL_REG1, tmp);

   tmp = 0x0F; // set resolution of pressure to 512

   i2c_smbus_write_byte_data(file_i2c, LPS25HB_RES_CONF, tmp);

   while(1){

    qDebug() << Q_FUNC_INFO << read_pressure();

   }

   return 0;

}

Output :

I always get the constant value even if I go DOWN and UP in the elevator

const double read_pressure() 12582912

int main(int, char**) 3072
0 REPLIES 0