-
Notifications
You must be signed in to change notification settings - Fork 96
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
Pressure reading too high (micropython) #3
Comments
Do you have a Raspberry Pi to run this library on and test it against your LoPy setup? This library wasn't targeted at any MicroPython boards, so it's possible there might be issues with the opaque calculations supplied by the manufacturer to transform the sensor readings into meaningful units. I also don't know how the sensor may correlate or deviate from pressure readings from other sources. What do you mean by real pressure? Do you have another sensor you're comparing this against? |
Thanks for the reply - I do have a Pi B so my next step was going to be exactly that. I'll try to get it hooked up and report back. The 'real' pressure is as reported by a BMP180 in the same room and a weather station a couple of miles away, which agree to within 1 hPa or so. The 680 is wrong enough that it's definitely not intended output, but all the other readings seem OK. |
Yeah, that's quite significantly wrong. I have a suspicion it could be a Python vs MicroPython issue, I'll grab a board and run some tests on it. |
A quick test of just the conversion routines disproves my theory- the The temperature is used to compensate the pressure readings, and should in theory cancel out any correlative effect you might see between the two. I'm assuming you're using this library? |
Yup, using this library and the breakout board from pimoroni. I wrote a little I2C wrapper class to convert the smbus *byte_data() and *block_data() calls into micropython's readfrom_mem() and writeto_mem(). This is my first foray into I2C and I'll happily believe it's my code that's at fault, but it does seem to work fine in all other respects. I dug out a Pi B last night so will test on that tomorrow and get back to you. If I get the same weird readings, I guess that rules out a platform/code issue and we're left with a possible dodgy sensor? |
Hello again. So, running this on a Pi B rev 2 gives very similar results. As you can see below I get 1040.41 as the pressure reading (yes, my house really is about 14 degrees C!). For reference a BMP180 currently gives me 1021.53 and the weather station down the road is showing 1020 Dodgy sensor?
|
I don’t think it’s a dodgy sensor. I just noticed that mine reads ~1050 hPa at the moment, while it should read ~1030 hPa. Thats the same ~20 hPa difference you also appear to have. I think it’s miscalculating in software. |
Ah, interesting! I was thinking of compiling the Bosch reference driver to see if it gives a different reading, but that's a bit out of my comfort zone. Will try it if I get the time this evening though. |
This is surprising, since I rigged up the Bosch C code and my Python code to perform the same calculations so I could verify them. Perhaps an error has crept in somewhere with an incorrect sign or premature rounding. Comparing the results you get with the Bosch driver would be a good start- we had some code somewhere to read/print the values. I'll see if I can dig it up. |
Good news, everyone! (for me anyway) It's not my fault! And the sensor is not faulty. See: https://github.com/BoschSensortec/BME680_driver/commit/94fd057adfb36077d57dde21df986f6d48939b29 My Python code is a direct port of Bosch's BME680_driver code. If you read the commit linked above you'll see:
Not only does this fix a bugbear of mine - using division in place of logical shifts - but it also "Fixed bug of temperature compensation in pressure." D'oh! I will port these fixes to Python ASAP. |
Okay, first run at it done. I've verified the Python code isn't riddled with syntax errors, but I've been unable to actually test it. See: d997015 You can try this out by installing it from Git:
(substitute python3 if appropriate) This will symlink this GitHub repository, so you can update to the latest development library by doing a "git pull". Once everything is working, you can clean that up and revert to the stable library by running:
|
I've just updated the library on my Pi and at the moment, the pressure value is spot on. Looking good so far! |
Sounds positive! I won't be able to test this until tomorrow, but will do so and report back. |
I’m afraid it didn’t fix the problem. :-( |
Same results here. I'm seeing this sort of thing if I warm the sensor up gently then let it cool (reference pressure is ~1018hPa): 13.44 C,1040.25 hPa,63.93 %RH,2132 Ohms Definitely still an issue with the temperature compensation (gas readings look odd but they tend to take a while to settle down). If you have a file I could compile against the Bosch API I'd love to test that: unfortunately my C isn't good enough to construct one myself. |
Ok, so I managed to hack together something that uses the Bosch C code and can confirm that it seems to work as expected. Currently: T: 13.40 degC, P: 1021.07 hPa, H 57.11 %rH whereas the latest python code is giving me: 13.04 C,1045.02 hPa,59.151 %RH Pressure reading seems stable with temperature changes using the C library, too. |
Very interesting! How's the gas measurement compared to the Python code? Looks like it's back to the drawing board for @Gadgetoid or @sandyjmacdonald... |
Gas sensor looks reasonable & stable, too (now that I've got my head slightly more around what the C code is doing and managed to make it loop)
If you promise not to laugh (I've never written any C before!), the code is here: https://gist.github.com/gkluoe/a297f6bcf76e4466f1bfa6fd40038983 |
If anyone wants to check their workings-out, CircuitPython code for Adafruit's BME680 breakout is here: https://github.com/adafruit/Adafruit_CircuitPython_BME680 and will, presumably (it's slightly beyond me), be easily comparable to Micropython/Python code. |
Try the Python code as of #4 being merged, it could well be that floating point results were propagating through the calculations and causing the difference. In the interim I'll have a look over the Bosch code versus our port, and see if anything has been overlooked in the new fixes. |
No change for me using the latest python code - but then I'm using 2.7 where, as I understand, it '/' and '//' are functionally the same... |
I'm a little bit stumped with this- perhaps I'm barking up the wrong tree. I'm genuinely surprised that back-porting the upstream fix for what sounds like exactly the same issue hasn't fix this though. Perhaps it's fixed one discrepancy and revealed another. Looks like I've got some more testing and debugging to do. |
Couldn't leave this alone - I think I found the issue: #5 |
@gkluoe are you using this board with micro/circuit-python? |
@robmarkcole yup. Or at least, I was. I haven't put it back on the LoPy yet since moving it over to the pi for debugging. I wrote a little I2CAdapter class, as the methods provided by machine.i2c are a little different from the SMBus methods this code expects. I can commit the code somewhere public this evening if you like. |
Hi @gkluoe would be grateful, thanks 🙏 |
Ho @robmarkcole So as not to hijack this issue, I've opened a new one for micropython support at #7 |
Hi, not sure if it is intended or an error, but, comparing the BME680_driver C code to this python port, I've noticed a difference in the VS
Hope it helps... |
Hi,
I'm using this code on a LoPy and it seems to work well, other than that the pressure reading is too high. I'm consistently seeing readings around 21mb higher than they should be (eg currently 1038 when the real pressure is ~1017). The pressure reading also consistently rises as the temperature drops. It doesn't seem to make a difference whether I have the gas heater on or off.
I've had good success with the BMP180 measuring temp/pressure in the same environment (just a house, nothing special!)
Can you think of anything I should try?
The text was updated successfully, but these errors were encountered: