Exemplo n.º 1
0
        static void Main()
        {
            const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
            const ConnectorPin sclPin = ConnectorPin.P1Pin05;

            Console.WriteLine("HTU21DF Sample: Read humidity and temperature");
            Console.WriteLine();
            Console.WriteLine("\tSDA: {0}", sdaPin);
            Console.WriteLine("\tSCL: {0}", sclPin);
            Console.WriteLine();

            using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()))
            {
                var deviceConnection = new Htu21dfConnection(driver.Connect(0x40));
                deviceConnection.Begin();

                while (!Console.KeyAvailable)
                {
                    var temp     = deviceConnection.ReadTemperature();
                    var humidity = deviceConnection.ReadHumidity();
                    Console.WriteLine($"Temp is: {temp:F1}C. RH is {humidity:F1}%");
                    Thread.Sleep(2000);
                }
            }
        }
Exemplo n.º 2
0
        public virtual IActionResult GetZoneTemperature([FromRoute] string zoneId)
        {
            TemperatureZoneStatus tzs = null;

            I2cDriver driver = new I2cDriver(Raspberry.IO.GeneralPurpose.ProcessorPin.Pin02, Raspberry.IO.GeneralPurpose.ProcessorPin.Pin03);

            if (driver != null)
            {
                BMP180PressureTempSensor p_sensor = new BMP180PressureTempSensor(driver, 0x77, BMP085Mode.UltraHighRes);

                //BH1750Connection l_sensor = new BH1750Connection(driver.Connect(0x40));

                var ht_sensor = new Htu21dfConnection(driver.Connect(0x40));
                ht_sensor.Begin();

                tzs = new TemperatureZoneStatus
                {
                    Id               = zoneId,
                    Name             = "HTU21DF-BMP180",
                    TemperatureValue = ht_sensor.ReadTemperature(),
                    PressureValue    = p_sensor.ReadSealevelPressure(),
                    HumidityValue    = ht_sensor.ReadHumidity(),
                    Units            = TemperatureZoneStatus.UnitsEnum.CelsiusEnum,
                    Timestamp        = DateTime.Now
                };
            }

            var example = tzs ?? default(TemperatureZoneStatus);

            return(new ObjectResult(example));
        }