public static void Execute()
        {
            var settings = BME280Driver.GetSpiConnectionSettings(G120E.GpioPin.P2_27);

            var controller = SpiController.FromName(G120E.SpiBus.Spi0);

            var device = controller.GetDevice(settings);

            var driver = new BME280Driver(device);

            driver.Initialize();

            driver.ChangeSettings(
                BME280SensorMode.Forced,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280Filter.Off);

            driver.Read();

            Debug.WriteLine("Pressure: " + driver.Pressure);
            Debug.WriteLine("Humidity: " + driver.Humidity);
            Debug.WriteLine("Temperature:" + driver.Temperature);
        }
        public static void Main()
        {
            var settings = BME280Driver.GetI2CConnectionSettings(BME280Address.Primary);

            var controller = I2cController.FromName(G120E.I2cBus.I2c0);

            var device = controller.GetDevice(settings);

            var driver = new BME280Driver(device);

            driver.Initialize();

            driver.ChangeSettings(
                BME280SensorMode.Forced,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280Filter.Off);

            while (true)
            {
                driver.Read();

                Debug.WriteLine("Pressure: " + driver.Pressure);
                Debug.WriteLine("Humidity: " + driver.Humidity);
                Debug.WriteLine("Temperature:" + driver.Temperature);

                Thread.Sleep(1000);
            }
        }
Exemple #3
0
        public static void Main()
        {
            Console.WriteLine("nanoFramework BME280 Sample!");

            Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
            Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

            var settings = BME280Driver.GetI2CConnectionSettings(BME280Address.Secondary);

            var device = I2cDevice.FromId("I2C1", settings);

            var driver = new BME280Driver(device);

            driver.Initialize();

            driver.ChangeSettings(
                BME280SensorMode.Forced,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280Filter.Off);

            Console.WriteLine(" ---------------- ");

            while (true)
            {
                driver.Read();

                Console.WriteLine("Pressure: " + driver.Pressure.ToString("N2"));
                Console.WriteLine("Humidity: " + driver.Humidity.ToString("N2"));
                Console.WriteLine("Temperature:" + driver.Temperature.ToString("N2"));
                Console.WriteLine(" ---------------- ");

                Thread.Sleep(1000);
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //new WaitForDebugger();


            SpiConnectionSettings _spiConnectionSettings = new SpiConnectionSettings(2,
                                                                                     1)
            {
                Mode          = SpiMode.Mode0,
                DataBitLength = 8
            };

            UnixSpiDevice _spiDevice = new UnixSpiDevice(_spiConnectionSettings);

            BME280Driver _bme280 = new BME280Driver(_spiDevice);

            _bme280.Initialize();

            _bme280.ChangeSettings(
                BME280SensorMode.Forced,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280Filter.Off);

            DateTime _lastLog = DateTime.MinValue;

            string _connectionString = @"Data Source=192.168.1.10\SQL2K16;Initial Catalog=LoggerDatabase;Persist Security Info=True;User ID=logger;Password=******;";

            SqlConnection _con = new SqlConnection(_connectionString);

            _con.Open();
            SqlCommand _command = new SqlCommand(Resources.InsertCommand, _con);

            _command.Parameters.Add(new SqlParameter("Source", "Source1"));
            _command.Parameters.Add(new SqlParameter("Id", System.Data.SqlDbType.UniqueIdentifier));
            _command.Parameters.Add(new SqlParameter("Barometric", System.Data.SqlDbType.Decimal));
            _command.Parameters.Add(new SqlParameter("Humidity", System.Data.SqlDbType.Decimal));
            _command.Parameters.Add(new SqlParameter("Temperature", System.Data.SqlDbType.Decimal));

            while (true)
            {
                _bme280.Update();
                string _data    = $"Pressure : {_bme280.Pressure:0.0} Pa, Humidity : {_bme280.Humidity:0.00}%, Temprature : {_bme280.Temperature:0.00}°C";
                string _logData = $"[{DateTime.Now.ToString("dddd MMM dd, yyyy h:mm:ss tt")}] {_data}";

                if ((DateTime.Now - _lastLog).TotalMinutes > 1)
                {
                    _lastLog = DateTime.Now;
                    File.AppendAllLines("BME280.log", new string[] { _logData });
                    Console.WriteLine(_logData);
                    _command.Parameters["Id"].Value          = Guid.NewGuid();
                    _command.Parameters["Barometric"].Value  = _bme280.Pressure;
                    _command.Parameters["Humidity"].Value    = _bme280.Humidity;
                    _command.Parameters["Temperature"].Value = _bme280.Temperature;
                    _command.ExecuteNonQuery();
                }
                else
                {
                    Console.WriteLine(_data);
                }
                Thread.Sleep(1000);
            }
        }