SparkFun Environmental Sensor Breakout - BME68x (Qwiic) Hookup Guide

Contributors: El Duderino, santaimpersonator
Favorited Favorite 1

Arduino Examples

Now that the library is installed, we can move on to uploading some code. Before we discuss the individual examples, we'll cover some of the setup they perform for the BME68x.

The code configures the BME68x to perform oversampling for the temperature, humidity and pressure sensors and sets an IIR (infinite impulse response) filter for these sensors. This helps smooth out environmental data from any short term outliers. Finally, the setup also configures the temperature and time settings for the hot plate on the gas sensor. If you would like to adjust any of these settings, refer to the BME680 Datasheet/BME688 Datasheet and the library source files for more information.

I2C Demo

To open this example, head to File > Examples > BME680 > I2CDemo. Next, open the Tools menu and select your board (in our case, Arduino Uno) and the correct Port your board enumerated on.

Upload the code, open the Arduino Serial Monitor and set your baud rate to 115200. You probably will see the code print out the successful initialization of the BME680 as well as the settings we discussed above and after that, you should see temperature, humidity, pressure, altitude and raw gas readings every five seconds.

Sample screenshot of I2C Demo

Note: While the Arduino library automatically checks for the BME68x at both available addresses, users can also specify a spacific address in their code.

Users can change this line of code:

while (!BME680.begin(I2C_STANDARD_MODE)) {  // Start BME680 using I2C, use first device found
and add the specific I2C address of the sensor:
while (!BME680.begin(I2C_STANDARD_MODE, 0x76)) {  // Start BME680 using I2C, use 0x76 address

SPI Demo

This example is nearly identical to the I2C demo but instead uses SPI mode. One thing to note is, depending on which type of microcontroller you are using, you may need to adjust this line:

const uint8_t  SPI_CS_PIN   = 53;

Set the CS/SS pin to the appropriate pin on your microcontroller. In our case, the Uno uses D10 for CS so the modified version of that line for an Uno or SparkFun RedBoard Qwiic would be:

const uint8_t  SPI_CS_PIN   = 10;

With that line adjusted, upload the code and open your serial monitor. You should see a similar stream of data as the screenshot above for the I2C example.

Tip: If you'd like to use this library with a development board with multiple serial ports like the RedBoard Turbo we show in the Hardware Hookup section, you'll want to add this line: #define Serial SerialUSB prior to your void setup(). This definition can be modified to any serial port on your chosen microcontroller.