/// <summary> /// Entry point for example program /// </summary> /// <param name="args">Command line arguments</param> public static void Run() { Console.WriteLine("Using BMP180!"); try { // bus id on the raspberry pi 3 const int busId = 1; var i2cSettings = new I2cConnectionSettings(busId, Bmp180.DefaultI2cAddress); var i2cDevice = I2cDevice.Create(i2cSettings); var i2cBmp280 = new Bmp180(i2cDevice); if (i2cBmp280 != null) { using (i2cBmp280) { // set samplings i2cBmp280.SetSampling(Sampling.Standard); // read values Temperature tempValue = i2cBmp280.ReadTemperature(); Console.WriteLine($"Temperature {tempValue.Celsius} \u00B0C"); var preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure {preValue.Hectopascal} hPa"); double altValue = i2cBmp280.ReadAltitude(); Console.WriteLine($"Altitude {altValue:0.##} m"); Thread.Sleep(1000); // set higher sampling i2cBmp280.SetSampling(Sampling.UltraLowPower); // read values tempValue = i2cBmp280.ReadTemperature(); Console.WriteLine($"Temperature {tempValue.Celsius} \u00B0C"); preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure {preValue.Hectopascal} hPa"); altValue = i2cBmp280.ReadAltitude(); Console.WriteLine($"Altitude {altValue:0.##} m"); } } else { Console.WriteLine($"Failed: No DMP180"); } } catch (Exception) { Console.WriteLine("Failed: Probably no hw."); } }
/// <summary> /// Entry point for example program /// </summary> /// <param name="args">Command line arguments</param> public static void Main(string[] args) { Console.WriteLine("Hello Bmp180!"); // bus id on the raspberry pi 3 const int busId = 1; var i2cSettings = new I2cConnectionSettings(busId, Bmp180.DefaultI2cAddress); var i2cDevice = I2cDevice.Create(i2cSettings); var i2cBmp280 = new Bmp180(i2cDevice); using (i2cBmp280) { // set samplings i2cBmp280.SetSampling(Sampling.Standard); // read values Temperature tempValue = i2cBmp280.ReadTemperature(); Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C"); var preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa"); // Note that if you already have the pressure value and the temperature, you could also calculate altitude by // calling WeatherHelper.CalculateAltitude(preValue, Pressure.MeanSeaLevel, tempValue) which would be more performant. var altValue = i2cBmp280.ReadAltitude(WeatherHelper.MeanSeaLevel); Console.WriteLine($"Altitude: {altValue:0.##}m"); Thread.Sleep(1000); // set higher sampling i2cBmp280.SetSampling(Sampling.UltraLowPower); // read values tempValue = i2cBmp280.ReadTemperature(); Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C"); preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa"); // Note that if you already have the pressure value and the temperature, you could also calculate altitude by // calling WeatherHelper.CalculateAltitude(preValue, Pressure.MeanSeaLevel, tempValue) which would be more performant. altValue = i2cBmp280.ReadAltitude(WeatherHelper.MeanSeaLevel); Console.WriteLine($"Altitude: {altValue:0.##}m"); } }
static void Main(string[] args) { Console.WriteLine("Hello Bmp180!"); //bus id on the raspberry pi 3 const int busId = 1; var i2cSettings = new I2cConnectionSettings(busId, Bmp180.DefaultI2cAddress); var i2cDevice = new UnixI2cDevice(i2cSettings); var i2cBmp280 = new Bmp180(i2cDevice); using (i2cBmp280) { //set samplings i2cBmp280.SetSampling(Sampling.Standard); //read values Temperature tempValue = i2cBmp280.ReadTemperature(); Console.WriteLine($"Temperature {tempValue.Celsius} °C"); double preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure {preValue} Pa"); double altValue = i2cBmp280.ReadAltitude(); Console.WriteLine($"Altitude {altValue:0.##} m"); Thread.Sleep(1000); //set higher sampling i2cBmp280.SetSampling(Sampling.UltraLowPower); //read values tempValue = i2cBmp280.ReadTemperature(); Console.WriteLine($"Temperature {tempValue.Celsius} °C"); preValue = i2cBmp280.ReadPressure(); Console.WriteLine($"Pressure {preValue} Pa"); altValue = i2cBmp280.ReadAltitude(); Console.WriteLine($"Altitude {altValue:0.##} m"); } }