Skip to content

Latest commit

 

History

History
46 lines (37 loc) · 1.24 KB

README.md

File metadata and controls

46 lines (37 loc) · 1.24 KB

LPS25H - Piezoresistive pressure and thermometer sensor

Some of the applications mentioned by the datasheet:

  • Altimeter and barometer for portable devices
  • GPS applications
  • Weather station equipment
  • Sport watches

Documentation

  • You can find the datasheet here

Usage

class Program
{
    // I2C address on SenseHat board
    public const int I2cAddress = 0x5c;

    static void Main(string[] args)
    {
        using (var th = new Lps25h(CreateI2cDevice()))
        {
            while (true)
            {
                var tempValue = th.Temperature;
                var preValue = th.Pressure;
                var altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

                Console.WriteLine($"Temperature: {tempValue.Celsius:0.#}\u00B0C");
                Console.WriteLine($"Pressure: {preValue.Hectopascal:0.##}hPa");
                Console.WriteLine($"Altitude: {altValue:0.##}m");
                Thread.Sleep(1000);
            }
        }
    }

    private static I2cDevice CreateI2cDevice()
    {
        var settings = new I2cConnectionSettings(1, I2cAddress);
        return I2cDevice.Create(settings);
    }
}