Coder Social home page Coder Social logo

lgtm-migrator / bme680 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robintty/bme680

0.0 0.0 0.0 123 KB

Device driver for the Bosch BME680 temperature, humidity, pressure, air quality sensor

Home Page: https://www.nuget.org/packages/Bme680Driver/

License: MIT License

C# 100.00%

bme680's Introduction

BME680 Build Library

C# driver for the Bosch BME680 temperature/humidity/pressure/air quality sensor. This driver is ported from the Bosch C driver.

The driver only supports the I²C protocol at the moment.

The datasheet can be found here.

Example on how to use this library

The easiest way to use this library is by getting it from Nuget or from Github Packages.

A similar version of this driver is included in the Iot.Device.Bindings library which includes many other device bindings.

You can either use the default settings of the sensor which will perform a measurement of temperature, humidity, pressure and gas (volatile organic compounds) or change those settings to suit your use case.

To use the default settings you could do something like this:

class Program
    {
        static async Task Main(string[] args)
        {
            // The BME680 uses either 0x76 or 0x77 as I2C address, the address has to be specified here
            var settings = new I2cConnectionSettings(1, Bme680.DefaultI2cAddress);
            var i2CDevice = I2cDevice.Create(settings);
            using var bme680 = new Bme680(i2CDevice);

            while (true)
            {
                var measurement = await bme680.PerformMeasurementAsync();

                Console.WriteLine($"Temperature: {measurement.Temperature:0.##}°C");
                Console.WriteLine($"Humidity: {measurement.Humidity:0.##}%");
                Console.WriteLine($"Pressure: {measurement.Pressure:0.##} Pa");
                Console.WriteLine($"Gas Resistance: {measurement.GasResistance:0.##} Ohm");
                Console.WriteLine();

                await Task.Delay(1000);
            }
        }
    }

To use your custom settings you could do something like this:

class Program
    {
        static async Task Main(string[] args)
        {
            // The BME680 uses either 0x76 or 0x77 as I2C address, the address has to be specified here
            var settings = new I2cConnectionSettings(1, Bme680.SecondaryI2cAddress);
            var i2CDevice = I2cDevice.Create(settings);
            using var bme680 = new Bme680(i2CDevice);

            // set custom device settings (A higher sampling also increases the time a measurement will take)
            // A sampling rate of X4 will take roughly 4 times longer than a sampling rate of X1
            // You can find out how long a measurement will take by using the method GetProfileDuration()
            bme680.HumiditySampling = Sampling.X4;
            bme680.TemperatureSampling = Sampling.X1;
            bme680.PressureSampling = Sampling.Skipped;
            bme680.FilterCoefficient = FilterCoefficient.C31;

            // set custom settings for gas conversion
            bme680.GasConversionIsEnabled = true;
            bme680.HeaterIsEnabled = true;
            
            // The BME680 sensor can save up to 10 heater profiles for use                
            // this profile will set the target temperature of the heating plate to 330°C
            // with a heating duration of 120ms and an ambient temperature of 24.0°C
            bme680.SaveHeaterProfileToDevice(HeaterProfile.Profile3, 330, 120, 24.0);
            bme680.CurrentHeaterProfile = HeaterProfile.Profile3;

            Console.WriteLine("Performing measurements with custom configuration:\n");
            while (true)
            {
                // perform the measurement
                var measurement = await bme680.PerformMeasurementAsync();

                // print results
                Console.WriteLine($"Temperature: {measurement.Temperature:0.##}°C");
                Console.WriteLine($"Humidity: {measurement.Humidity:0.##}%");
                Console.WriteLine($"Pressure: {measurement.Pressure:0.##} Pa");
                Console.WriteLine($"Gas Resistance: {measurement.GasResistance:0.##} Ohm");
                Console.WriteLine();

                // it can make sense to update the heater profile continually since the ambient temperature
                // is taken into account when the heater profile is set
                bme680.SaveHeaterProfileToDevice(HeaterProfile.Profile3, 330, 120, measurement.Temperature);

                Task.Delay(1000).Wait();
            }
        }
    }

You can find these examples in the samples folder.

bme680's People

Contributors

robintty avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.