twartzek / bme680-raspberry Goto Github PK
View Code? Open in Web Editor NEWC Code which reads measurements of a BME680 connected to a raspberry pi.
License: MIT License
C Code which reads measurements of a BME680 connected to a raspberry pi.
License: MIT License
Hi,
first of all thanks for your code, it allowed me to finally get the bme680 working on my Raspi3!
From what I have seen in code of others, they calibrate the sensor somehow prior to get the readings. Is this done in the bme680 driver already or would it be to be added?
I found a C Library from Bosch BSEC which they recommend to use, but i dont think it works on the Raspi3 - i think that library would then also give you some GAS values or Air Quality Index, do you know how to make sense of the gas resistance value?
I just run 100 measurements with 10sec delay and the gas resistance value kept increasing...
Some times I am not getting any value for the temperature, it just stays at 0.00 - and its definitely not that cold in here!! :-)
cheers! Andreas
Hi,
i need help, i have this output errors .
i had checked before:
i2cdetect -y 1 --> It users the 0x77
gcc (Raspbian 4.9.2-10) 4.9.2
i don't understand the following output:
pi@raspberrypizero:~/BOSCH
$ sudo gcc bme680_main.c bme680.c -o bme680
bme680_main.c: In function ‘user_i2c_write’:
bme680_main.c:102:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int i=1; i<len+1; i++)
^
bme680_main.c:102:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile `
do you have any hints?
ludwich
The BME680 datasheet mentions:
As a raw signal, BME680 will output resistance values and its changes due to varying VOC concentrations (the higher the concentration of reducing VOCs, the lower the resistance and vice versa). Since this raw signal is influenced by parameters other than VOC concentration (e.g. humidity level), the raw values are transformed to an indoor air quality (IAQ) index by smart algorithms inside BSEC.
It would be a nice enhancement to replace the gas measurement resistance value with the IAQ, since the former means very little by itself, and the IAQ index is designed to take the other factors into account.
https://www.bosch-sensortec.com/bst/products/all_products/BSEC
Hi,
not really an issue but wanted to share...
I have adapted the code from twartzek to be compiled as a shared library and the functions callable from python. This is how I did it (code might be incomplete but you get the idea):
I changed the main function and added some subroutines, also made the two following variables global:
//global Variables
struct bme680_dev gas_sensor;
struct bme680_field_data data;
int8_t update_sensor_data(){
int8_t rslt = BME680_OK;
// Trigger a meausurement
rslt = bme680_set_sensor_mode(&gas_sensor); /* Trigger a measurement */
uint16_t meas_period;
bme680_get_profile_dur(&meas_period, &gas_sensor);
// Wait for a measurement to complete
user_delay_ms(meas_period + 1000); /* Wait for the measurement to complete */
rslt = bme680_get_sensor_data(&data, &gas_sensor);
// Avoid using measurements from an unstable heating setup
if(data.status & BME680_HEAT_STAB_MSK)
{
return 0;
}
else {
return -1;
}
}
int16_t get_temperature(){
if (data.temperature != NULL) {
return data.temperature;
}
else {
return -999;
}
}
uint32_t get_pressure(){
if (data.pressure != NULL) {
return data.pressure;
}
else {
return 0;
}
}
uint32_t get_humidity(){
if (data.humidity != NULL) {
return data.humidity;
}
else {
return 0;
}
}
uint32_t get_gas_resistance(){
if (data.gas_resistance != NULL) {
return data.gas_resistance;
}
else {
return 0;
}
}
uint8_t get_status(){
return data.status;
}
uint8_t get_gas_index(){
return data.gas_index;
}
Compile code using gcc
gcc -c -fpic bme680_main.c bme680.c -std=c11
Create shared library
gcc -shared -o libbme680.so bme680.o bme680_main.o
Call from Python
from ctypes import *
bme680 = cdll.LoadLibrary('./libbme680.so')
rslt = bme680.init_device(1)
rslt = bme680.update_sensor_data()
temp = bme680.get_Temperature()
...
bme680.disconnect_device()
I compiled bme680-raspberry program with BOSH API. It works but in most cases temperature readout is 0.00 degC like below:
2018-04-16 15:33:50 T: 0.00 degC, P: 957.62 hPa, H: 49.34 %rH, G: 35208 Ohms
From time to time it is read properly, like this:
2018-04-16 15:33:29 T: 22.86 degC, P: 995.00 hPa, H: 51.59 %rH, G: 31610 Ohms
All other parameters are readout correctly. Notice that if starts begins with correct readout of temperature, it is read correctly up to the end of program. Like after the command:
./bme680 5 10000
But if first readout will be 0.00 then all other readouts are zeros too.
Is it any initialisation improve Your code? How can I resolve the problem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.