public double GetHumidity()
        {
            using (var sensor = new Sht3x(_sht3x))
            {
                var humidity = sensor.Humidity;

                _logger.LogDebug($"Humidity: {humidity}");

                return(humidity);
            }
        }
        public double GetTemp()
        {
            using (var sensor = new Sht3x(_sht3x))
            {
                var temp = sensor.Temperature.Celsius;

                _logger.LogDebug($"Temperature: {temp} C");

                return(temp);
            }
        }
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, (byte)I2cAddress.AddrLow);
            I2cDevice             device   = I2cDevice.Create(settings);

            using (Sht3x sensor = new Sht3x(device))
            {
                while (true)
                {
                    Console.WriteLine($"Temperature: {sensor.Temperature.Celsius} ℃");
                    Console.WriteLine($"Humidity: {sensor.Humidity} %");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }
        public static Weather GetWeather()
        {
            // Temperature and Humidity Sensor - SHT3x
            I2cConnectionSettings sht3xSettings = new I2cConnectionSettings(1, (byte)Iot.Device.Sht3x.I2cAddress.AddrLow);
            UnixI2cDevice         sht3x         = new UnixI2cDevice(sht3xSettings);

            // Digital Pressure Sensors - BMP280
            I2cConnectionSettings bmpSettings = new I2cConnectionSettings(1, Bmp280.DefaultI2cAddress);
            UnixI2cDevice         bmp280      = new UnixI2cDevice(bmpSettings);

            // Analog to Digital Converter - ADS1115
            I2cConnectionSettings adsSettings = new I2cConnectionSettings(1, (byte)Iot.Device.Ads1115.I2cAddress.GND);

            // Get temperature and humidity
            double temperature = 0, humidity = 0;

            using (Sht3x tempHumiSensor = new Sht3x(sht3x))
            {
                temperature = tempHumiSensor.Temperature.Celsius;
                humidity    = tempHumiSensor.Humidity;
            }

            // Get pressure
            double pressure = 0;

            using (Bmp280 pressureSensor = new Bmp280(bmp280))
            {
                pressure = pressureSensor.ReadPressureAsync().Result;
            }

            // Get UV
            Lm8511 uvSensor = new Lm8511(adsSettings);
            double uv       = uvSensor.UV;

            Weather weather = new Weather
            {
                DateTime    = DateTime.Now,
                Temperature = temperature,
                Humidity    = humidity,
                Pressure    = pressure,
                UV          = uv
            };

            return(weather);
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, (byte)I2cAddress.AddrLow);
            I2cDevice             device   = I2cDevice.Create(settings);

            using (Sht3x sensor = new Sht3x(device))
            {
                while (true)
                {
                    var tempValue = sensor.Temperature;
                    var humValue  = sensor.Humidity;

                    Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C");
                    Console.WriteLine($"Relative humidity: {humValue:0.#}%");

                    // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity.
                    Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
                    Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }