PySense nonsense altitude readings



  • Re: Implausible pysense pressure readings

    I am getting silly readings from the MPL3115A2 sensor on a PySense using a LoPy 1.0.

     MicroPython v1.8.6-849-055728a on 2018-02-13; LoPy with ESP32
    Type "help()" for more information.
    >>> 
    >>> from pysense import Pysense
    >>> from MPL3115A2 import MPL3115A2, ALTITUDE
    >>> py = Pysense()
    >>> mp = MPL3115A2(py, mode=ALTITUDE)
    >>> import utime
    >>> for i in range(10):
    ...     print('MPL3115A2 altitude is: ' + str(mp.altitude()))
    ...     utime.sleep(60)
    ...     
    ...     
    ... 
    MPL3115A2 altitude is: -5.4375
    MPL3115A2 altitude is: -4.6875
    MPL3115A2 altitude is: -5.75
    

    All firmware is upto date
    Any ideas what the problem is? Has anyone else encountered similar problems (I note that other false readings came after switching between Pressure and Altitude modes, however this is not case in my code.



  • @catalin said in PySense nonsense altitude readings:

    You could look into datasheet for better explanations: https://www.nxp.com/docs/en/data-sheet/MPL3115A2.pdf

    Yet another data sheet with complete non-sense... It's saying you should use OFF_H, when really the registers to use are BAR_IN_MSB/BAR_IN_LSB.

    @seb or @catalin, it would probably be a good idea to add a function in PL3115A2.py to set this value.

    self.i2c.writeto_mem(MPL3115_I2CADDR, MPL3115_BAR_IN_MSB, bytes([int(qnh*100/2) >> 8, int(qnh*100/2) & 255]))
    

    Note that even with this, one should not expect a very precise altitude indication, it can vary several meters up or down. If you want a more precise altitude (and independence from the weather), you probably need to use a GPS.



  • @jcaron
    Because of this, many libs have parameter to set base presure
    and it is taken in calculation



  • For those not aware, this is how aircraft handle the same issue: https://en.wikipedia.org/wiki/QNH

    Atmospheric pressure varies with altitude and with the weather. At the same exact location, varying pressure is correlated with the weather: high pressure means sunny, low pressure cloudy and stormy, as can be seen in weather forecasts.

    If on the other hand you want to know the altitude, you need to have a reference pressure, usually the pressure at sea level (QNH). If the current pressure is equal to the pressure at sea level, you are at altitude 0. Lower pressures mean higher altitudes, and vice versa.



  • The altitude comes from the current pressure value and the pressure at sea-level. I mean, once the sky becomes cloudy, the altitude will seem to vary some 300meters (in a few minutes).
    The sensor altitude value should be used differential. If now it shows -5m, and it you're at +10m, then it's a +15m offset that has to be considered.
    The MPL3115A2.py sensor has some registers for writing the sea-level pressure (offset correction), but this is not implemented.
    You could look into datasheet for better explanations: https://www.nxp.com/docs/en/data-sheet/MPL3115A2.pdf



  • No, not many places are! It should be something like +10 or +20 m.
    I note other users on the forum have had problems with negative altitudes before. However their problems were related to switching between pressure and altitude modes. In this case I have only selected altitude.



  • Im guessing the location you are in is not -5m below sea level?



Pycom on Twitter