private BMP280 tempAndPressure;      // Instance of BMP280 class

        public MainPage()
        {
            this.InitializeComponent();

            // Instantiate a new BMP280 class instance
            tempAndPressure = new BMP280();

            this.bmpTimer          = new DispatcherTimer();
            this.bmpTimer.Interval = TimeSpan.FromMilliseconds(5000);
            this.bmpTimer.Tick    += BmpTimer_Tick;
            this.bmpTimer.Start();
        }
Esempio n. 2
0
        public static void Main()
        {
            Debug.WriteLine("Program started");

            // Using the SPI Interface
            //_sensor = new BMP280(Hardware.SC20100_1)
            //{
            //    PressureCompensation = PressureCompensationModes.SeaLevelCompensated,
            //    TemperatureUnit = TemperatureUnits.Fahrenheit
            //};

            // Using the I2C Interface
            _sensor = new BMP280(Hardware.SC20100_1, BMP280.I2CAddress.I2CAddress0)
            {
                PressureCompensation = PressureCompensationModes.SeaLevelCompensated,
                TemperatureUnit      = TemperatureUnits.Fahrenheit
            };

            Debug.WriteLine($"Device ID is {_sensor.DeviceId}");

            // Set recommended mode using SetRecemmondedMode method.
            _sensor.SetRecommendedMode(BMP280.RecommendedModes.WeatherMonitoring);

            // Or set individual parameters as in below. Note: You must call EnableSettings() method to enforce the user settings.
            //_sensor.PressureSamplingRate = Pressure4Click.OversamplingRates.Osr1;
            //_sensor.TemperatureSamplingRate = Pressure4Click.OversamplingRates.Osr1;
            //_sensor.Filter = Pressure4Click.FilterCoefficient.IIROff;
            //_sensor.StandbyDuration = Pressure4Click.StandbyDurations.MS_0_5;
            //_sensor.OperatingMode = Pressure4Click.Mode.Sleep;
            //_sensor.EnableSettings();

            while (true)
            {
                _sensor.ReadSensor(out Single pressure, out Single temperature, out Single altitude);

                Debug.WriteLine($"Pressure.......: {pressure:F1} hPa");
                Debug.WriteLine($"Temperature....: {temperature:F2} °F");
                Debug.WriteLine($"Altitude.......: {altitude:F0} meters\n");

                Thread.Sleep(2000);
            }
        }
Esempio n. 3
0
        public MainPage()
        {
            this.InitializeComponent();

            // Instantiate a new BMP280 class instance
            tempAndPressure = new BMP280();

            // Connect to MySQL. If successful, setup timer
            if (this.Connect())
            {
                this.bmpTimer          = new DispatcherTimer();
                this.bmpTimer.Interval = TimeSpan.FromMilliseconds(5000);
                this.bmpTimer.Tick    += BmpTimer_Tick;
                this.bmpTimer.Start();
            }
            else
            {
                Debug.WriteLine("ERROR: Cannot proceed without database connection.");
            }
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            using (ExplorerHatPro hat = new ExplorerHatPro(ADS1015.Gain.Volt5))
                using (BMP280 bmp280 = new BMP280(0x76)) {
                    while (true)
                    {
                        Debug.WriteLine($"Temperature {bmp280.Temperature.DegreesCelsius}C, Pressure {bmp280.Pressure.Hectopascals}, Light ratio {hat.AnalogRead(AnalogPin.Ain2).ReadRatio()} ");

                        for (int l = 0; l < hat.ColourCount; l++)
                        {
                            hat.Light((Colour)l).On();
                            Task.Delay(20).Wait();
                        }

                        for (int l = 0; l < hat.ColourCount; l++)
                        {
                            hat.Light((Colour)l).Off();
                            Task.Delay(20).Wait();
                        }
                    }
                }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();


            // How to use the ADS1015 and MCP3002 ADC/Converters

            AdcProviderManager adcManager = new AdcProviderManager();

            adcManager.Providers.Add(new ADS1015(ADS1015.Gain.Volt33));                            // Load up ADS1015 4 Channel ADC Converter
            adcManager.Providers.Add(new MCP3002());                                               // Load up MCP3002 2 Channel ADC Converter

            IReadOnlyList <AdcController> adcControllers = await adcManager.GetControllersAsync(); // load ADCs


            //use the ADCs create above
            Ldr      light = new Ldr(adcControllers[0].OpenChannel(0));      // create new light sensor using the ADS1015 ADC provider
            MCP9700A temp  = new MCP9700A(adcControllers[1].OpenChannel(0)); // create temperature sensor using MCP3002 ADC Provider

            var lightLevel = light.ReadValue;                                // read light level from the first ADC ADS1015
            var lightRatio = light.ReadRatio;

            var celsius    = temp.Temperature.DegreesCelsius;    // read temp in celsius
            var fahrenheit = temp.Temperature.DegreesFahrenheit; // read temp in celsius


            BMP280 tempAndPressure = new BMP280();

            var degreesCelsius    = tempAndPressure.Temperature.DegreesCelsius; // read temp in celsius - plenty of other units
            var degreesFahrenheit = tempAndPressure.Temperature.DegreesFahrenheit;

            var bars         = tempAndPressure.Pressure.Bars;         // read air pressure in bars - plenty of other units
            var hectopascals = tempAndPressure.Pressure.Hectopascals; // read air pressure in Hectopascals
            var Atmospheres  = tempAndPressure.Pressure.Atmospheres;


            // LED demo

            Led led = new Led(4);   // open led on pin 4

            led.On();               // turn on
            await Task.Delay(1000); // wait for 1 second

            led.Off();              // turn off

            // relay Demo
            Relay relay = new Relay(6);

            relay.On();             // turn relay on
            await Task.Delay(1000); // wait for 1 second

            led.Off();              // turn relay off


            // motor demo
            Motor leftMotor  = new Motor(22, 24);
            Motor rightMotor = new Motor(12, 25);

            //now do a tight circle
            leftMotor.Forward();
            rightMotor.Backward();
            await Task.Delay(5000);  // wait for 5 second

            leftMotor.Stop();
            rightMotor.Stop();
        }