BME680 Sensor
Moderator: Benj
BME680 Sensor
I have just purchased a BME680 sensor for use in a weather station.
Is there a library / macro for the BME680 in FC8.
I have the latest version of FC8.
Can anyone direct me to a library / macro that will work with FC8?
Thank you,
John.
Is there a library / macro for the BME680 in FC8.
I have the latest version of FC8.
Can anyone direct me to a library / macro that will work with FC8?
Thank you,
John.
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
Hi John,
I don't think there is a component at present - so let's make one! It'll be fun!
See the datasheet at https://ae-bst.resource.bosch.com/media ... -DS001.pdf
First step is to get the chip talking to your mcu - I've used i2c (as this ties in nicely with the rtc chips I'm working on at present) - you'll need to connect SDA, SCL (a4 and a5 on Arduino), power and ground - and to use the i2c bus connect SD0 to 5v too... (this selects i2c mode)
Here's my first simple code - reads the bme680 id from register 0xD0 and displays it (outputs it on UART) - my bme680 is at i2c address 0x77 (yours might differ - the last bit can be 0 or 1 so if 0x77 doesn't work try 0x76...
This seems like a simple step - but if doesn't work, nothing will.....
Martin
Note some of the maths gets a bit involved to use all features !
If you want to use SPI that is possible too.....
Note also that the board I'm using allows 5v operation - use a 3.3v mcu or level shifters if this isn't the case for you - and good luck with the smd soldering
I don't think there is a component at present - so let's make one! It'll be fun!
See the datasheet at https://ae-bst.resource.bosch.com/media ... -DS001.pdf
First step is to get the chip talking to your mcu - I've used i2c (as this ties in nicely with the rtc chips I'm working on at present) - you'll need to connect SDA, SCL (a4 and a5 on Arduino), power and ground - and to use the i2c bus connect SD0 to 5v too... (this selects i2c mode)
Here's my first simple code - reads the bme680 id from register 0xD0 and displays it (outputs it on UART) - my bme680 is at i2c address 0x77 (yours might differ - the last bit can be 0 or 1 so if 0x77 doesn't work try 0x76...
This seems like a simple step - but if doesn't work, nothing will.....
Martin
Note some of the maths gets a bit involved to use all features !
If you want to use SPI that is possible too.....
Note also that the board I'm using allows 5v operation - use a 3.3v mcu or level shifters if this isn't the case for you - and good luck with the smd soldering
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 43 times
- Been thanked: 60 times
- Contact:
Re: BME680 Sensor
I think it is a very good idea to check the FC8 supported components before you buy anything.
--
Another good idea is suggested by mnf: make a new component.
Would be great if you can make one.
A lot of people would be grateful to you John.
PS
Thank you Martin.
--
Another good idea is suggested by mnf: make a new component.
Would be great if you can make one.
A lot of people would be grateful to you John.
PS
Thank you Martin.
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
First contact....
Temperature read and displayed (in deg C) - floating point and integer (note that the integer result is x100 - to give two digits
fp resolution)
Other values look a little more 'involved'
Martin
Temperature read and displayed (in deg C) - floating point and integer (note that the integer result is x100 - to give two digits
fp resolution)
Other values look a little more 'involved'
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
... and with GetHumidityFloat. I don't have anything to test against to hand - but in the right ballpark.
A major design decision - currently GetTemp/Humidity etc read the data (calibration and temp etc) from the BME680 - it is up to the user to call Force_read (name needs changing) first.
It 'might' be better to read all the calibration values (once) at initialisation and also to buffer the data registers for all info on 'read'...
Anyone any ideas - thoughts ?
Martin
A major design decision - currently GetTemp/Humidity etc read the data (calibration and temp etc) from the BME680 - it is up to the user to call Force_read (name needs changing) first.
It 'might' be better to read all the calibration values (once) at initialisation and also to buffer the data registers for all info on 'read'...
Anyone any ideas - thoughts ?
Martin
Re: BME680 Sensor
Good Morning All,
Thank you Martin for your suggestions etc.
I am really looking forward to moving on with this project. I am in a learning curve at the moment with regard to programming. My back ground is electronics, from which I retired nearly 20 years ago. I have worked on military radio equipment, mobile telephone base station equipment and mobile phones. I was brought up on the now vintage gear - TVs, radios, amplifiers etc.
The weather station concept that I am working on, is to have the facility to measure, temperature, humidity, air pressure, wind speed and possibly soil moisture sensing to connect to an automatic irrigation system. Possibly an RTC will be added. I started the learning curving using Microsoft's Visual Studio 2019, writing the C++ code. All was going fairly well, until the LCD decided to start showing random characters. The only thing I could put this down to was LCD library problems. The complication was that there are many LCD library versions to choose from. I have now switched to Flowcode8 and all is going well again. I am using at the moment a 20x4 LCD, a bme280 sensor. Temp and Hum are working well and seem quite accurate but the air pressure is causing me a few problems.
With your grateful input Martin, I will start to get into the data sheets and the code that you have sent over and see where we go from here. It is all very interesting stuff and it certainly keeps your brain active.
Thanks also to Vik for the interest.
Cheers for now I will keep you posted as I progress.
Regards,
John.
Thank you Martin for your suggestions etc.
I am really looking forward to moving on with this project. I am in a learning curve at the moment with regard to programming. My back ground is electronics, from which I retired nearly 20 years ago. I have worked on military radio equipment, mobile telephone base station equipment and mobile phones. I was brought up on the now vintage gear - TVs, radios, amplifiers etc.
The weather station concept that I am working on, is to have the facility to measure, temperature, humidity, air pressure, wind speed and possibly soil moisture sensing to connect to an automatic irrigation system. Possibly an RTC will be added. I started the learning curving using Microsoft's Visual Studio 2019, writing the C++ code. All was going fairly well, until the LCD decided to start showing random characters. The only thing I could put this down to was LCD library problems. The complication was that there are many LCD library versions to choose from. I have now switched to Flowcode8 and all is going well again. I am using at the moment a 20x4 LCD, a bme280 sensor. Temp and Hum are working well and seem quite accurate but the air pressure is causing me a few problems.
With your grateful input Martin, I will start to get into the data sheets and the code that you have sent over and see where we go from here. It is all very interesting stuff and it certainly keeps your brain active.
Thanks also to Vik for the interest.
Cheers for now I will keep you posted as I progress.
Regards,
John.
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
Hi John,
Good luck with the project - hopefully have you using the BME680 soon too..
I've now got pressure working and have started changing code to use the 'preload' config I mentioned, it makes for more readable code (and less opportunity for mistakes) (GetPressure uses it)
Just a final push on gas measurements - and we can start moulding it into a component..
For those playing along - a version that calculates the pressure (in Pascals)
Martin
Good luck with the project - hopefully have you using the BME680 soon too..
I've now got pressure working and have started changing code to use the 'preload' config I mentioned, it makes for more readable code (and less opportunity for mistakes) (GetPressure uses it)
Just a final push on gas measurements - and we can start moulding it into a component..
For those playing along - a version that calculates the pressure (in Pascals)
Martin
Re: BME680 Sensor
Hi Martin,
That sounds brilliant. It's sounding actually quit close.
Regards,
John.
That sounds brilliant. It's sounding actually quit close.
Regards,
John.
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
Struggling to get the gas sensing to run...
Registers look to be sensible values - but the gas measurement doesn't run, so I've missed something Gas resistance is just returned as 8000000 - which is the measurement 'skipped' value.
Anyone able to take a look?
Martin
Registers look to be sensible values - but the gas measurement doesn't run, so I've missed something Gas resistance is just returned as 8000000 - which is the measurement 'skipped' value.
Anyone able to take a look?
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
To make life a little easier - I tidied the register dump to show addresses..
Gas_measuring is still not set to 1 however - gas sensing not happening (status bytes output show measuring (bit 5 set) then new data (bit 7))
So, run_gas (0x71<4>) is set high which is correct - other ideas- are res_heat_x or gas_wait_x is set to an invalid value (but both are set)
Martin
Gas_measuring is still not set to 1 however - gas sensing not happening (status bytes output show measuring (bit 5 set) then new data (bit 7))
So, run_gas (0x71<4>) is set high which is correct - other ideas- are res_heat_x or gas_wait_x is set to an invalid value (but both are set)
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
Weather is too good to be inside!
I spotted a couple of mistakes (SetGasSensor - taking a byte for temp and time being the main). I also tidied the coefficient handling so that the actual addresses of the data could be passed - which makes for more readable code. These addresses should really be changed to constants?)
But still no joy
Martin
I spotted a couple of mistakes (SetGasSensor - taking a byte for temp and time being the main). I also tidied the coefficient handling so that the actual addresses of the data could be passed - which makes for more readable code. These addresses should really be changed to constants?)
But still no joy
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
Cracked it
Turns out it had been reading correctly all along - i'd just misinterpreted the meaning of the gas sensing flag.
Also managed to get the sensor connected to a pc ( and used a log of i2c transfers to compare code with some working code in Python.)
Tidy up and I'll post a version to test later. Then convert to a basic component and job done!
Martin
Turns out it had been reading correctly all along - i'd just misinterpreted the meaning of the gas sensing flag.
Also managed to get the sensor connected to a pc ( and used a log of i2c transfers to compare code with some working code in Python.)
Tidy up and I'll post a version to test later. Then convert to a basic component and job done!
Martin
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
So for anyone who would like to try it.
There is an Altitude function - which is actually pretty accurate - IF (and only if) you know the pressure at sea-level (otherwise you can get negative heights in times of high pressure!)
I'll add a AirQuality function next - I've found a straightforward algorithm.
There's a fair few bits still to do - read the status flag for heater temp being stable - I've also only implemented floating point versions of the humidity pressure and gas resistance routines (did both for temp) - there is a GetGasResInt here - but it doesn't work - use the GetGasResistance (which is the FP version). Some values (heater temp for instance) should be clamped. And some documentation!
There a few oddities - GetTempInt returns temperature x100 (so you can get 2 decimal places precision) and pressure returns Pascals (divide by 100 to get the more usual hPa)
The values returned are very similar to those given by Pimoroni's Python library (which makes me a bit more confident that they are right)
Anyone any thoughts on naming / interface before I transfer to a component?
So it was a bit more involved than anticipated - the moral is read the datasheet (very) carefully. Thanks to Steve for some extra info too..
Martin
It's back to the RTC chips for a bit after this!
A version that does temp, pressure, humidity and gas resistance. There is a major change from previous versions - call ReadSensor to initiate and read the sensor. It's important to call GetTemp(Int or Float) as the first conversion - the humidity and pressure values are temperature compensated.There is an Altitude function - which is actually pretty accurate - IF (and only if) you know the pressure at sea-level (otherwise you can get negative heights in times of high pressure!)
I'll add a AirQuality function next - I've found a straightforward algorithm.
There's a fair few bits still to do - read the status flag for heater temp being stable - I've also only implemented floating point versions of the humidity pressure and gas resistance routines (did both for temp) - there is a GetGasResInt here - but it doesn't work - use the GetGasResistance (which is the FP version). Some values (heater temp for instance) should be clamped. And some documentation!
There a few oddities - GetTempInt returns temperature x100 (so you can get 2 decimal places precision) and pressure returns Pascals (divide by 100 to get the more usual hPa)
The values returned are very similar to those given by Pimoroni's Python library (which makes me a bit more confident that they are right)
Anyone any thoughts on naming / interface before I transfer to a component?
So it was a bit more involved than anticipated - the moral is read the datasheet (very) carefully. Thanks to Steve for some extra info too..
Martin
It's back to the RTC chips for a bit after this!
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: BME680 Sensor
A first attempt at making it into a component..
I did a simple test program for an ATTiny85 with i2c (SSD1306) display and BME680 attached. Memory is a bit tight - hence just temp, humidity and pressure. (Integer versions should use less memory (and I use GetTempInt here))
To install - copy the fcpx file to a directory and make sure that Flowcode has a pointer to this (View->Global Options->Locations->look for components in..)
To use:
Initialise - this returns true if the BME680 id byte can be read
SetOversampling
SetGasSensor (if used)
SetGasProfile (if used)
Call ReadSensor to initiate a read - then GetTemperature/Pressure/Humidity/GasResistance.
Note that there is a 'simple' AirQuality routine - call SetGasBaseline - initially with 0.0 which runs a 5minute calibration - the value can be saved and passed in if required
Then call AirQuality - note there should probably be a SetHumidityBaseline function too - Pimoroni reckon 40% - but here it never seems to go much below 70.0 (which is the value I've used!)
Note that the gas sensor requires a 'burning' in period before returning consistent readings.
There is no simulation...
Martin'
I did a simple test program for an ATTiny85 with i2c (SSD1306) display and BME680 attached. Memory is a bit tight - hence just temp, humidity and pressure. (Integer versions should use less memory (and I use GetTempInt here))
To install - copy the fcpx file to a directory and make sure that Flowcode has a pointer to this (View->Global Options->Locations->look for components in..)
To use:
Initialise - this returns true if the BME680 id byte can be read
SetOversampling
SetGasSensor (if used)
SetGasProfile (if used)
Call ReadSensor to initiate a read - then GetTemperature/Pressure/Humidity/GasResistance.
Note that there is a 'simple' AirQuality routine - call SetGasBaseline - initially with 0.0 which runs a 5minute calibration - the value can be saved and passed in if required
Then call AirQuality - note there should probably be a SetHumidityBaseline function too - Pimoroni reckon 40% - but here it never seems to go much below 70.0 (which is the value I've used!)
Note that the gas sensor requires a 'burning' in period before returning consistent readings.
There is no simulation...
Martin'