Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BME688 gas resistance calculation #909

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public SpiClockConfiguration.Mode SpiBusMode
/// Initializes a new instance of the BME280 class
/// </summary>
/// <param name="i2cBus">I2C Bus to use for communicating with the sensor</param>
/// <param name="address">I2C address of the sensor (default = 0x77)</param>
/// <param name="address">I2C address of the sensor (default = 0x76)</param>
public Bme280(II2cBus i2cBus, byte address = (byte)Addresses.Default)
{
bme280Comms = new I2cCommunications(i2cBus, address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ internal enum Registers : byte
TEMPDATA = 0x22,
HUMIDITYDATA = 0x25,

GAS_RES = 0x2A,
GAS_RANGE = 0x2B,
GAS_RES = 0x2C,
GAS_RANGE = 0x2D,
RES_HEAT_0 = 0x5A,
GAS_WAIT_0 = 0x64,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public bool GasConversionIsEnabled
{
var gasConversion = busComms.ReadRegister((byte)Registers.CTRL_GAS_1);
byte mask = 0x10;
gasConversion = (byte)((gasConversion & (byte)~mask) | Convert.ToByte(value) << 4);
gasConversion = (byte)((gasConversion & (byte)~mask) | Convert.ToByte(value) << 5);

busComms.WriteRegister((byte)Registers.CTRL_GAS_1, gasConversion);
gasConversionIsEnabled = value;
Expand Down Expand Up @@ -587,10 +587,11 @@ private Resistance CalculateGasResistance(ushort adcGasRes, byte gasRange)
{
if (calibration == null) throw new NullReferenceException("Calibration must be defined");

var var1 = 1340.0 + 5.0 * calibration.RangeSwErr;
var var2 = var1 * (1.0 + k1Lookup[gasRange] / 100.0);
var var3 = 1.0 + k2Lookup[gasRange] / 100.0;
var gasResistance = 1.0 / (var3 * 0.000000125 * (1 << gasRange) * ((adcGasRes - 512.0) / var2 + 1.0));
var var1 = ((uint)262144) >> gasRange;
var var2 = (adcGasRes) - 512;
var2 *= 3;
var2 = 4096 + var2;
var gasResistance = 1_000_000.0 * var1 / var2;

return new Resistance(gasResistance, Resistance.UnitType.Ohms);
}
Expand Down
Loading