pi3g / bme68x-python-library

Python 3 Library for BME688 and BME680 (Bosch Sensortec sensors), supports Bosch BSEC
MIT License
46 stars 18 forks source link

Error while running sample code.. #22

Open rpprojects1 opened 1 year ago

rpprojects1 commented 1 year ago

Hi Everyone,

while running the sample code (python3 forced_mode.py ) I am getting the following error:

TESTING FORCED MODE WITHOUT BSEC INITIALIZED BME68X VARIANT = BME688 SET BME68X CONFIG SET HEATER CONFIG (FORCED MODE) SET HEATER CONFIG (FORCED MODE) {'sample_nr': 1, 'timestamp': 312986, 'temperature': 23.257213592529297, 'pressure': 100083.6015625, 'humidity': 82.25715637207031, 'gas_resistance': 9402.5849609375, 'status': 160}

TESTING FORCED MODE WITH BSEC INITIALIZED BME68X VARIANT = BME688 SET BME68X CONFIG SET HEATER CONFIG (FORCED MODE) Traceback (most recent call last): File "forced_mode.py", line 18, in bme.set_sample_rate(bsec.BSEC_SAMPLE_RATE_LP) AttributeError: 'bme68x.BME68X' object has no attribute 'set_sample_rate'

and when i try to run : ~/bme68x-python-library/tools/bmerawdata $ python3 bmerawdata.py

i get the following error :

INITIALIZED BME68X VARIANT = BME688 SET BME68X CONFIG SET HEATER CONFIG (FORCED MODE) HEATR CONF IN SET AI CONF [5, 2, 10, 30, 5, 5, 5, 5, 5, 5] 320 100 100 100 200 200 200 320 320 320 5 2 10 30 5 5 5 5 5 5 SET HEATER CONFIG (PARALLEL MODE) Traceback (most recent call last): File "bmerawdata.py", line 178, in bme68x_ai = BME68X_AI(BME68XCONST.BME68X_I2C_ADDR_HIGH, ai_conf) File "bmerawdata.py", line 67, in init self.sensor_id = self.get_sensor_id() AttributeError: 'BME68X_AI' object has no attribute 'get_sensor_id'

any idea what could be wrong?

mcalisterkm commented 1 year ago

Which version of BSEC are you using and which version of bme68x-python-library?

The current BSEC 2 is 2.4.0.0 and you will find a version of bme68x-python-library that work with this release here:

The bmerawdata.py example does not record in a format compatible with the current release of BME AI Studio. The 8 sensor BOSCH Sensortec dev board is a better bet for recording data than a single sensor. I have some notes and data here:.

Keith

rpprojects1 commented 1 year ago

Thank you for your reply and detailed documentation. I am new to this and so have the following question:

I tried using 8 sensor BOSCH dev board as you suggested. Now, how do I deploy my model for inference? This is the information I am struggling to find.

Do I need to change the sketch on the dev board? I have the config file placed in the raspberry pi appropriate folder. Do I need to change any other things in the pi file?

Screenshot 2023-09-11 at 3 41 27 pm

![Uploading Screenshot 2023-09-11 at 3.42.59 pm.png…]()

mcalisterkm commented 1 year ago

The 8 sensor dev board is used to collect data, that data is loaded off the sd-card into BME AI studio, and a model is generated. In my example here the folder 8x-test.bmeproject is the project folder from my BME AI Studio it has the data collected and BME AI studio should be able to load the project using this data and generate a model config.

The model I generated is in the main folder 2023_05_06_15_00_Air-Ethanol_HP-354_RDC-5-10.config along with the python file sniff.py. The python code sniff.py loads the config in this line:

# This is the config file output by AI_Studio
config_file = '2023_05_06_15_00_Air-Ethanol_HP-354_RDC-5-10.config'

I have assumed that the config file is in the same folder as sniff.py and build a path based on the location of the running python file

config_path = str(Path(__file__).resolve().parent.joinpath(config_file))

So you will need to change the name of config_file to your generated config and if you want to put the file somewhere else you will need to change the config_path.

My sniff.py code will output Air and Ethanol results as that was what the model trained for, however your model is coffee so you may want to change the labels in the code

             # print(f'{entry}')
            print(f'NORMAL AIR {entry["gas_estimate_1"]:.1%}\nETHANOL {entry["gas_estimate_2"]:.1%}')
            print()

There can be up to 4 subscriptions so "gas_estimate_1" to "gas_estimate_4", but you will know how many your model trained on and therefore need to be subscribed. If this changes from 2 then you need to alter the sniff.py subscriptions here.

# Air and Ethanol - two subscriptions (0,1)
    print(f'SUBSCRIBE GAS ESTIMATES {bme.subscribe_gas_estimates(2)}')

In your ls listing above I see coffe.zip, and that is a bit confusing - is coffee.zip the config file output by BME AI Studio or the whole project folder? All you need to transfer to the PI is sniff.py and the "<...> .config file" - in my project that is 2023_05_06_15_00_Air-Ethanol_HP-354_RDC-5-10.config.

Try to run through my example by loading the project into BME AI studio and following from Step 4 in the ReadMe. If you do not have hand sanitiser try a few drops of perfume on a tissue (uses ethanol as a base that evaporates).

rpprojects1 commented 1 year ago

@mcalisterkm - Thanks Keith. You saved me at least a couple of days of research time. Thank you so much. I checked with your config file and it's working well. Now I may be being lazy and leaning a bit (hope not) - but is there a ready code that gives gas inference as well as the temperature and humidity reading?

mcalisterkm commented 1 year ago

What do you mean by gas inference? The BME688 is a mox sensor it heats the gas at a set temperature and measures resistance, and by heating samples at different temperatures and applying the results to BME AI studio it builds an AI model to recognise - "sniff" - that sample again. The sensor and its software has no inherent ability to sniff for example Carbon Dioxide or Air unless you train an AI model to do that. That is what sniff.py is doing, applying and AI model trained on Air and Ethanol, to give an estimate of a gas sample on the sensor against Air and Ethanol as a % probability.

I have an example of how to collect data, produce a model and run the model on a single bme688 sensor/Pi here:. PI3G have a video on youtube - the meat & cheese demo. And Bosh have software and docs here

Oops - BSEC does give an estimated CO2 ppm value, which is calculated. But the principle remains you need to train on the gas you wish to detect.