コード例 #1
0
        private static void Pressure(PressureTemperatureHumiditySensor sensor)
        {
            using (sensor)
            {
                sensor.SeaLevelPressureInHectopascals = 1013.25f;
                bool ok = sensor.Begin();

                if (!ok)
                {
                    Console.WriteLine($"Error initializing sensor");
                    return;
                }

                for (var i = 0; i < 5; ++i)
                {
                    sensor.ReadSensor();

                    Console.WriteLine($"Pressure:    {sensor.PressureInHectopascals:0.00} hPa");
                    Console.WriteLine($"Humdity:     {sensor.Humidity:0.00} %");
                    Console.WriteLine($"Temperature: {sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    Console.WriteLine($"Altitude:    {sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                    Console.WriteLine();

                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
        }
コード例 #2
0
        private static void Pressure_Lcd(LcdController lcd, PressureTemperatureHumiditySensor sensor)
        {
            using (sensor)
            {
                sensor.SeaLevelPressureInHectopascals = 1013.25f;
                bool ok = sensor.Begin();

                if (!ok)
                {
                    Console.WriteLine($"Error initializing sensor");
                    return;
                }

                for (var i = 0; i < 3; ++i)
                {
                    sensor.ReadSensor();

                    Console.WriteLine($"Pressure:    {sensor.PressureInHectopascals:0.00} hPa");
                    Console.WriteLine($"Humdity:     {sensor.Humidity:0.00} %");
                    Console.WriteLine($"Temperature: {sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    Console.WriteLine($"Altitude:    {sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                    Console.WriteLine();

                    ShowInfo(lcd, "Pressure", $"{sensor.PressureInHectopascals:0.00} hPa/mb");
                    ShowInfo(lcd, "Humdity", $"{sensor.Humidity:0.00} %");
                    ShowInfo(lcd, "Temperature", $"{sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    ShowInfo(lcd, "Altitude", $"{sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                }
            }
        }
コード例 #3
0
        private static void I2c_Pressure()
        {
            Console.WriteLine(nameof(I2c_Pressure));
            var settings = new I2cConnectionSettings(1, PressureTemperatureHumiditySensor.DefaultI2cAddress);
            var sensor   = new PressureTemperatureHumiditySensor(settings);

            Pressure(sensor);
        }
コード例 #4
0
        private static void Spi_Pressure(GpioDriver driver)
        {
            using (var controller = new GpioController(driver))
            {
                GpioPin chipSelectPin = controller.OpenPin(s_chipSelectLinePinNumber);

                var settings = new SpiConnectionSettings(s_spiBusId, 0);
                var sensor   = new PressureTemperatureHumiditySensor(chipSelectPin, settings);
                Pressure(sensor);
            }
        }
コード例 #5
0
ファイル: AzureIoTSample.cs プロジェクト: thedeveus/corefxlab
        public void StartSendingData()
        {
            EventHubClient eventHubClient = CreateEventHubClient("DataEventHubConnectionString");
            Stopwatch      watch          = Stopwatch.StartNew();

            var pressureSettings = new I2cConnectionSettings(Program.I2cBusId, PressureTemperatureHumiditySensor.DefaultI2cAddress);
            var colorSettings    = new I2cConnectionSettings(Program.I2cBusId, RgbColorSensor.DefaultI2cAddress);

            using (var pressureSensor = new PressureTemperatureHumiditySensor(pressureSettings))
                using (var colorSensor = new RgbColorSensor(colorSettings))
                {
                    pressureSensor.SeaLevelPressureInHectopascals = 1013.25f;
                    bool ok = pressureSensor.Begin();

                    if (!ok)
                    {
                        Console.WriteLine($"Error initializing pressure sensor");
                        return;
                    }

                    ok = colorSensor.Begin();

                    if (!ok)
                    {
                        Console.WriteLine($"Error initializing color sensor");
                        return;
                    }

                    while (watch.Elapsed.TotalDays < 1)
                    {
                        pressureSensor.ReadSensor();
                        colorSensor.ReadSensor();

                        Console.WriteLine($"Pressure:    {pressureSensor.PressureInHectopascals:0.00} hPa");
                        Console.WriteLine($"Humdity:     {pressureSensor.Humidity:0.00} %");
                        Console.WriteLine($"Temperature: {pressureSensor.TemperatureInCelsius:0.00} C, {pressureSensor.TemperatureInFahrenheit:0.00} F");
                        Console.WriteLine($"Altitude:    {pressureSensor.AltitudeInMeters:0.00} m, {pressureSensor.AltitudInFeet:0.00} ft");
                        Console.WriteLine();

                        Console.WriteLine($"Color:       {Program.ToRgbString(colorSensor.Color)}");
                        Console.WriteLine($"Temperature: {colorSensor.Temperature:0.00} K");
                        Console.WriteLine($"Luminosity:  {colorSensor.Luminosity:0.00} lux");
                        Console.WriteLine();

                        Console.WriteLine("Sending sensors data to Azure IoT Hub...");
                        Console.WriteLine();

                        CreateMessage(pressureSensor, colorSensor, out Message message);
                        SendMessage(eventHubClient, ref message);

                        Thread.Sleep(TimeSpan.FromSeconds(1));
                    }
                }
        }
コード例 #6
0
        private static void Spi_Pressure(GpioDriver driver)
        {
            using (var controller = new GpioController(driver, PinNumberingScheme.Bcm))
            {
                Pin csPin = controller.OpenPin(8);

                var settings = new SpiConnectionSettings(0, 0);
                var sensor   = new PressureTemperatureHumiditySensor(csPin, settings);
                Pressure(sensor);
            }
        }
コード例 #7
0
        private static void I2c_Pressure_Lcd(GpioDriver driver)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var controller = new GpioController(driver))
            {
                GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                lcd.Begin(16, 2);

                var settings = new I2cConnectionSettings(s_i2cBusId, PressureTemperatureHumiditySensor.DefaultI2cAddress);
                var sensor   = new PressureTemperatureHumiditySensor(settings);
                Pressure_Lcd(lcd, sensor);
            }
        }
コード例 #8
0
ファイル: AzureIoTSample.cs プロジェクト: thedeveus/corefxlab
        private static void CreateMessage(PressureTemperatureHumiditySensor pressureSensor, RgbColorSensor colorSensor, out Message message)
        {
            message = new Message()
            {
                TimeStamp               = DateTime.Now,
                TemperatureInCelsius    = pressureSensor.TemperatureInCelsius,
                TemperatureInFahrenheit = pressureSensor.TemperatureInFahrenheit,
                PressureInHectopascals  = pressureSensor.PressureInHectopascals,
                AltitudeInMeters        = pressureSensor.AltitudeInMeters,
                AltitudInFeet           = pressureSensor.AltitudInFeet,
                Humidity = pressureSensor.Humidity,

                ColorR          = colorSensor.Color.R,
                ColorG          = colorSensor.Color.G,
                ColorB          = colorSensor.Color.B,
                ColorBrightness = colorSensor.Color.GetBrightness(),
                ColorHue        = colorSensor.Color.GetHue(),
                ColorSaturation = colorSensor.Color.GetSaturation(),

                ColorTemperature = colorSensor.Temperature,
                Luminosity       = colorSensor.Luminosity,
            };
        }
コード例 #9
0
        private static void Spi_Pressure_Lcd(GpioDriver driver)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;
            const int chipSelectLinePinNumber = 8;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var controller = new GpioController(driver))
            {
                GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                lcd.Begin(16, 2);

                GpioPin chipSelectLinePin = controller.OpenPin(chipSelectLinePinNumber);

                var settings = new SpiConnectionSettings(s_spiBusId, 0);
                var sensor   = new PressureTemperatureHumiditySensor(chipSelectLinePin, settings);
                Pressure_Lcd(lcd, sensor);
            }
        }