using System.Threading;
using System.Diagnostics;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Devices.I2c;
using Monoculture.TinyCLR.Drivers.BME280;;
namespace TinyCLRApplication1
{
class Program
{
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);
}
}
}
}
Humm… this is the device that has the plethora of calibration values that you have to take into account when calculating the value of the temp? In your tests was the value accurate?
EDIT: Just read the code, yep it’s that device. Don’t mind if I help myself to your calculator. I tried writing on for dotnet core a few weeks back and found that part was rather confusing.
I wrote the code a couple of months ago and its just been sitting in a private repository on GitHub gathering dust. At the time I had ordered a high-pressure waterproof sensor from China and I was just using the BME280 as a temporary stand-in for some code I was working on. I didn’t do much checking other than eyeballing the results and then comparing them to my thermostat.
I’ve just run it again and this is what i’m getting back:
I think the device would be more accurate than the thermostat in terms of the temp. Also, it was perhaps sitting on your desk at the time (as opposed to the wall). I did not mean the CRC calculation, I am referring to the entire calculation used to compute temp, press and humid.
I’ll let you know if there are any bugs. Further, how did you develop the code for the calculations? Did your port from another project or did you read the datasheet
Well I managed to “port” it over to dotnet core. I don’t think it has any errors! Much thanks Monoculture. Now I don’t know what to do with the modified code.
One small thing I noticed in your screenshot the units are Pa not kPa
I don’t know how closely you followed by code but if I was reimplementing it I would probably cache the output of the three properties in a backing variable and then clear the cache when the update function gets called. That way the calculation isn’t rerun every time the property is accessed. I’d also probably rename the “Update” function to “Read” or something similiar.
So, is this is an open source thing? will we get to see it?
Take a look at the BME280BusWrapper class - Unfortunately I don’t have the board with me at the moment so I haven’t been able to test it but I’ll do that when i get in tonight and if everything looks good I’ll merge the changes into main and do another release.
I also found a bug in the original code - Filter isn’t getting updated in the ChangeSettings method.
I’ve merged the code back into main and uploaded the new version to NuGet…
For some reason I couldn’t get SPI TransferSequential to work properly (I suspect it has something to do with the byte order of the data being returned) so I used your bit of code for that. Hope that’s OK with you?
I see a new problem with the data. The pressure says 75 kPa. That can’t be right. I checked with our met office at the airport (not far from me), their site says it’s supposed to be about 101 kPa.