adafruit / Adafruit_BME680

117 stars 76 forks source link

Read from sensor asynchrously #14

Closed yoursunny closed 5 years ago

yoursunny commented 5 years ago

This Change adds a pair of beginReading() and endReading() functions. It allows the microcontroller to perform other work, such as network operations, while the BME680 sensor is performing the reading.

ladyada commented 5 years ago

looks good, for measurement time please use uint32_t rather than 'long' also some returns were changed to 0, but the function returns bool type so turn those back :)

yoursunny commented 5 years ago

for measurement time please use uint32_t rather than 'long'

_meas_end indicates the absolute time when the current measurement would end, so the type should match the return type of millis().

also some returns were changed to 0, but the function returns bool type so turn those back

beginMeasurement returns the absolute time when the current measurement would end (i.e. _meas_end). Its return type is not bool, so return false becomes return 0.

ladyada commented 5 years ago

ok got it - what hardware have you tested with?

yoursunny commented 5 years ago

I tested this with ESP32 Heltec_WiFi_Kit_32 and Adafruit BME680 breakout board. However, I haven't fully tested the async logic. Shall I add an example for async reading?

ladyada commented 5 years ago

an example would be good - yeah! do you have an AVR or SAMD board to test with, arduino or feather?

yoursunny commented 5 years ago

an example would be good - yeah!

I'll try to create an example.

do you have an AVR or SAMD board to test with, arduino or feather?

I don't have any Arduino boards. Hopefully another user having them could help testing it once I upload the example.

ladyada commented 5 years ago

ok if you can add an async demo, ill do the test!

yoursunny commented 5 years ago

Example is uploaded.

Reading started at 37859 and will finish at 38042
You can do other work during BME680 measurement.
Reading completed at 38177
Temperature = 24.18 *C
Pressure = 1003.87 hPa
Humidity = 54.90 %
Gas = 762.62 KOhms
Approx. Altitude = 78.22 m

There are still some delay()s inside Bosch's library causing endReading to take about 130ms, but I won't go into these. The overall benefit of this change is gaining about 180ms during a measurement for parallel work.

ladyada commented 5 years ago

awesome!