LPS25H pressure sensor

Hi Everybody,

I am new on this forum , but have some experience with arduino.

Recently I decided to build some kind of variometer for my RC plane based on arduino uno+LPS25H. Unfortunately, this sensor in default settings has poor accuracy and vario in that condition does not make sense - error is approx +-1m.

In order to improve accurancy I have to turn on FIFO mode , but to do this I have to change register according to decryption "The FIFO buffer is enabled by setting to 1 the FIFO_EN bit (21h - CTRL_REG2)" and then select "FIFO mean mode (F_MODE2:0=”110” in FIFO_CTRL (2Eh))".

According to documentation in"LPS25H.h" file I have:
"void writeReg(int reg, byte value);"

I wrote this simply code to check register , but apparently I did something wrong , because in the results

FIFO CHECK=
32 //FIFO_EN=0x2F
0 //CTRL_REG2=0x21;
41 //FIFO_CTRL=0x2E;

Status&MODE after change=
32
0
110

Would be somebody so nice and help me?

Thank you in advance.

Code:
#include <Wire.h>
#include <LPS25H.h>

LPS25H ps;

//ON
int CTRL_REG2=0x21;
byte valueON = 1;

//MODE
int FIFO_CTRL=0x2E;
byte valueCH =110;

//CHECK
int FIFO_EN=0x2F;

void setup()
{
Serial.begin(9600);
Wire.begin();

if (!ps.init())
{
Serial.println("Failed to autodetect pressure sensor!");
while (1);
}

ps.enableDefault();

Serial.println("FIFO CHECK=");
Serial.println(ps.readReg(FIFO_EN));
Serial.println(ps.readReg(CTRL_REG2));
Serial.println(ps.readReg(FIFO_CTRL));
Serial.println(" ");

Serial.println("Status&MODE after change=");
ps.writeReg(CTRL_REG2,valueON);
ps.writeReg(FIFO_CTRL,valueCH);
Serial.println(ps.readReg(FIFO_EN));
Serial.println(ps.readReg(CTRL_REG2));
Serial.println(ps.readReg(FIFO_CTRL));
}

Which LPS25H library do you use ? The first one that I can find on Github has a few bugs.

That is a 3.3V sensor and the Arduino Uno is a 5V board. How did you connect a 3.3V sensor to a 5V board ?

Why do you have to turn on the FIFO to get more accuracy ? For 32 samples moving average ? That can be done in software in the sketch as well.

The Serial.println() can print hexadecimal values with the parameter HEX.
See the example sketch: https://www.arduino.cc/en/serial/println.

You could also print the "WHO_AM_I" register. That has a specific value of 0xBD.

You use "FIFO_EN" as a register, but in the datasheet there is no register with that name. The register at 0x2F is called "FIFO_STATUS".

You write 110 to FIFO_CTRL. The decimal value of 110 is 0x6E, but the value of 0x6E is not a valid option according to the datasheet.

The CTRL_REG2 has a FIFO_EN bit 0x40. I don't see that you set that bit. In the datasheet they mean that the bit has to be set to 1, they do not mean that the whole register (of 8 bits) has to be set to 1.

With F_MODE2:0 = 1 1 0, they mean the bits. Those are three bits. The F_MODE2 should be 1, the F_MODE1 should be 1, the F_MODE0 should be 0.

When the FIFO is turned on, should the interrupt signal be used to get data from the sensor ?

Hi Koepel,

First of all thank you for your answer and your time.

Yes you are right , I use: GitHub - pololu/lps-arduino: Arduino library for Pololu LPS25H and LPS331AP boards
since this link is on producer site. I am relay disappointed that this library has bugs , I bought this sensor because of accuracy , now I can see that it has no declared features and I have new problem with documentation.

Anyway I would finish this task with register in order to at least have knowledge in future...

3.3V from sensor I just connected to my 3.3V pin in arduino , it works OK.

I guess your solution with mean pressure in sketch it better one , actually I did it but only for 10 samples , now I will increase amount of samples up to 32 or even more. From the listing now I can see that pressure from sensor various every 10 samples.

Please help me with print "WHO_AM_I" register:

is this good code?

int WHO_AM_I=0xBD;

Serial.println(ps.readReg(WHO_AM_I),HEX);

Once again thank you for help and your time.

Is this your sensor: Pololu - LPS25H Pressure/Altitude Sensor Carrier with Voltage Regulator ?
It has a voltage regulator and voltage shifters for SDA and SCL.
Since the Arduino Uno is a 5V board (the microcontroller on the Arduino Uno runs at 5V), therefor it has a 5V I2C bus.
You can connect VIN of the module to the Arduino 5V pin. The level shifters on the sensor module will fix the voltage levels of SDA and SCL.

The Pololu library has an issue. Guess who wrote that issue :wink: After Wire.requestFrom() there is no need to wait and no need for endTransmission. · Issue #2 · pololu/lps-arduino · GitHub.
That issue is almost never a problem, but it might disturb some sensors. If your sketch is correct and there are still problems in the communication, you might try to fix the library.

The sensor has registers, and those registers have contents, the data, its value.
The registers are at 0x00 to 0x3A. That is the offset or the address. Let's call that "register address".

The "WHO_AM_I" register has register address 0x0F, and it is read-only and the data is 0xBD.

Serial.print( "WHO_AM_I = 0x");
Serial.println( ps.readReg( 0x0F), HEX);  // should print BD

Look on the bright side: meanwhile you learn how to read a datasheet.

Hi Koepel,

Yes , this is definitely bright side that I've learned how to read/write register.

Concerning voltage - I bought this sensor from this shop:

Then just wired according to sketch , it works perfect.

Thank you for support.