diff --git a/.gitea/gas.png b/.gitea/gas.png new file mode 100644 index 0000000..1e75451 Binary files /dev/null and b/.gitea/gas.png differ diff --git a/.gitea/hum.png b/.gitea/hum.png new file mode 100644 index 0000000..393e90d Binary files /dev/null and b/.gitea/hum.png differ diff --git a/.gitea/press.png b/.gitea/press.png new file mode 100644 index 0000000..d5232e4 Binary files /dev/null and b/.gitea/press.png differ diff --git a/.gitea/temp.png b/.gitea/temp.png new file mode 100644 index 0000000..f7b73b9 Binary files /dev/null and b/.gitea/temp.png differ diff --git a/README.md b/README.md index bb7e967..f1ca4b1 100644 --- a/README.md +++ b/README.md @@ -93,3 +93,76 @@ gas resistance: 14702.868852 Ohm ``` Note: Do not trust the gas resistance measurement if `heat_stab_r` is not `1`. + +## Burn-in / logging + +See file `example/log.c` + +![Graph of gas resistance measured over time](.gitea/gas.png) +![Graph of temperature measured over time](.gitea/temp.png) +![Graph of pressure measured over time](.gitea/press.png) +![Graph of humidity measured over time](.gitea/hum.png) + +Compile and run +```sh +stdbuf -o0 ./bme680 2>&1 | tee -a log.txt +``` + +This will give an output similar to this: +``` +2024-05-14T13:03:02+0100 20.8916 99836.7 68.6594 7180.73 1 +2024-05-14T13:04:03+0100 20.8658 99840.3 68.7844 7171.53 1 +2024-05-14T13:05:03+0100 20.8979 99838.6 68.7759 7162.35 1 +2024-05-14T13:06:03+0100 20.9208 99843.8 68.6436 7166.93 1 +2024-05-14T13:07:03+0100 20.9303 99845.4 68.747 7144.05 1 +2024-05-14T13:08:03+0100 20.9249 99846 68.7122 7139.49 0 +2024-05-14T13:09:04+0100 20.9036 99845.2 68.7224 7157.76 1 +2024-05-14T13:10:04+0100 20.8737 99850.5 68.575 7144.05 1 +2024-05-14T13:11:04+0100 20.8753 99850.6 68.8879 7139.49 1 +2024-05-14T13:12:04+0100 20.9152 99849.3 68.8602 7134.94 1 +``` + +If last field is not 1 then the measurement, at least for gas resistance, cannot be trusted. +```sh +sed -n '/1$/p' log.txt > test.txt +``` + +Then graph with gnuplot +``` +# gnuplot +reset + +set key autotitle columnhead +set terminal pngcairo enhanced size 2*1920/3,2*1080/3 +set grid +set xdata time +set timefmt "%Y-%m-%dT%H:%M:%S%z" + + + +# gas res vs time +set title "[I_{dac}=100, 100ms, target=300 C] GasRes over time" +set xlabel "Time" +set ylabel "Gas Resistance (OHM)" +set output "gas.png" +plot 'test.txt' u 1:5 w p pt 3 ps 1 t "BME680" + + +set title "[I_{dac}=100, 100ms, target=300 C] Temperature over time" +set xlabel "Time" +set ylabel "Temperature (C)" +set output "temp.png" +plot 'test.txt' u 1:2 w p pt 3 ps 1 t "BME680" + +set title "[I_{dac}=100, 100ms, target=300 C] Pressure over time" +set xlabel "Time" +set ylabel "Pressure (Pa)" +set output "press.png" +plot 'test.txt' u 1:3 w p pt 3 ps 1 t "BME680" + +set title "[I_{dac}=100, 100ms, target=300 C] Humidity over time" +set xlabel "Time" +set ylabel "Humidity (%RH)" +set output "hum.png" +plot 'test.txt' u 1:4 w p pt 3 ps 1 t "BME680" +``` diff --git a/example/README.md b/example/README.md index dd06d80..08c9974 100644 --- a/example/README.md +++ b/example/README.md @@ -1,6 +1,20 @@ # bme680/example +log.c +``` +2024-05-14T13:03:02+0100 20.8916 99836.7 68.6594 7180.73 1 +2024-05-14T13:04:03+0100 20.8658 99840.3 68.7844 7171.53 1 +2024-05-14T13:05:03+0100 20.8979 99838.6 68.7759 7162.35 1 +2024-05-14T13:06:03+0100 20.9208 99843.8 68.6436 7166.93 1 +2024-05-14T13:07:03+0100 20.9303 99845.4 68.747 7144.05 1 +2024-05-14T13:08:03+0100 20.9249 99846 68.7122 7139.49 0 +2024-05-14T13:09:04+0100 20.9036 99845.2 68.7224 7157.76 1 +2024-05-14T13:10:04+0100 20.8737 99850.5 68.575 7144.05 1 +2024-05-14T13:11:04+0100 20.8753 99850.6 68.8879 7139.49 1 +2024-05-14T13:12:04+0100 20.9152 99849.3 68.8602 7134.94 1 +``` + iterate\_setpoint.c ``` heater_target=300.0, ambient_temp=19.0 diff --git a/example/log.c b/example/log.c new file mode 100644 index 0000000..b18a258 --- /dev/null +++ b/example/log.c @@ -0,0 +1,101 @@ +#define _DEFAULT_SOURCE + +#include +#include +#include +#include + +#include "bme680.h" +#include "i2c.h" + +#define AMBIENT_TEMP_GUESS 19.0 +#define HEATER_TARGET 300.0 + + +int main(void) { + + bme680_t bme680; + uint8_t mode; + double temperature = AMBIENT_TEMP_GUESS; + time_t curr_time; + char date[100]; + + bme680.dev.init = i2c_init; + bme680.dev.read = i2c_read; + bme680.dev.write = i2c_write; + bme680.dev.deinit = i2c_deinit; + bme680.dev.sleep = usleep; + + mode = BME680_MODE_FLOAT | BME680_I2C | BME680_ENABLE_GAS; + + + if (bme680_init(&bme680, mode) != 0) { + fprintf(stderr, "bme680_init()\n"); + exit(EXIT_FAILURE); + } + +START: + bme680_reset(&bme680); + + if (bme680_calibrate(&bme680) != 0) { + fprintf(stderr, "bme680_calibrate()\n"); + bme680_deinit(&bme680); + exit(EXIT_FAILURE); + } + + bme680.cfg.osrs_t = BME680_OVERSAMPLE_X16; + bme680.cfg.osrs_p = BME680_OVERSAMPLE_X16; + bme680.cfg.osrs_h = BME680_OVERSAMPLE_X8; + bme680.cfg.filter = BME680_IIR_COEFF_127; + + bme680.cfg.res_heat[0] = bme680_calc_target(&bme680, HEATER_TARGET, temperature); + bme680.cfg.idac_heat[0] = BME680_IDAC(100); + bme680.cfg.gas_wait[0] = BME680_GAS_WAIT(25, BME680_GAS_WAIT_X4); + + bme680.setpoint = 0; + + if (bme680_configure(&bme680) != 0) { + fprintf(stderr, "bme680_configure()\n"); + bme680_deinit(&bme680); + exit(EXIT_FAILURE); + } + + if (bme680_start(&bme680) != 0) { + fprintf(stderr, "bme680_start()\n"); + bme680_deinit(&bme680); + exit(EXIT_FAILURE); + } + + if (bme680_poll(&bme680) != 0) { + fprintf(stderr, "bme680_poll()\n"); + bme680_deinit(&bme680); + exit(EXIT_FAILURE); + } + + if (bme680_read(&bme680) != 0) { + fprintf(stderr, "bme680_read()\n"); + bme680_deinit(&bme680); + exit(EXIT_FAILURE); + } + + curr_time = time(NULL); + strftime(date, 100, "%FT%T%z", localtime(&curr_time)); + printf("%s %g %g %g %g %d\n", + date, + bme680.fcomp.temp, + bme680.fcomp.press, + bme680.fcomp.hum, + bme680.fcomp.gas_res, + !!bme680.heat_stab); + + temperature = bme680.fcomp.temp; + + // 60 secs + usleep(1000*1000*60); + goto START; + + bme680_deinit(&bme680); + + return 0; +} +