Skip to main content

Qwiic BME680 sensor

What this example shows​

Read temperature, humidity and air pressure from a BME680 sensor board over Qwiic and show the three values, each with an icon, and a Soldered logo on the screen. The values refresh once a minute.

You need a BME680 breakout with a Qwiic connector and a Qwiic cable to connect it to Inkplate. The sketch's comments say the sensor board answers on I2C address 0x76 and that the sketch does not need to specify it.

This example also uses the Soldered BME680 library (Soldered-BME280-BME680-Gas-Sensor-Arduino-Library), which is not part of the Inkplate library. Install it before you compile. The icons and the logo are bitmap arrays in icons.h, in the same example folder.

Example code​

Select Board
Inkplate7SPECTRA_Qwiic.ino
#include <BME680-SOLDERED.h> // Soldered library for BME680 Sensor
#include "Inkplate.h" // Include Inkplate library to the sketch
#include "icons.h"

Inkplate inkplate; // Create an object on Inkplate library
BME680 bme680; // Create an object on Soldered BME680 library (with no arguments sent to constructor, that means we are
// using I2C or Qwiic communication for BME680 sensor)

// Add temperature offset to calibrate the sensor
const float temperatureOffset = 0.0;

void setup()
{
Serial.begin(115200);
inkplate.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
inkplate.clearDisplay(); // Clear frame buffer of display
inkplate.setTextSize(1); // Set text scaling to one (normal size)
inkplate.setTextColor(INKPLATE_BLACK);
inkplate.setCursor(0, 0);

// Init. BME680 library. Soldered BME680 sensor board uses 0x76 I2C address for the sensor but doesn't need to
// specify it
if (!bme680.begin())
{
inkplate.println("Sensor init failed!");
inkplate.println("Check sensor wiring/connection!");
inkplate.display();
while (1)
;
}
}

void loop()
{
// Clear frame buffer of the display
inkplate.clearDisplay();

// Set text size to print big numbers for temperature and humidity
inkplate.setTextSize(5);

// Display the temperature icon and measured value
inkplate.setCursor(200, 45);
inkplate.print(bme680.readTemperature() + temperatureOffset);
inkplate.print(" *C");
inkplate.drawBitmap(50, 5, temperature_icon, temperature_icon_w, temperature_icon_h, INKPLATE_RED); // Arguments are: start X, start Y, array variable name, size X, size Y, color


// Display humidity icon and measured value
inkplate.setCursor(200, 180);
inkplate.print(bme680.readHumidity() / 10);
inkplate.print(" %");
inkplate.drawBitmap(43, 140, humidity_icon, humidity_icon_w, humidity_icon_h, INKPLATE_GREEN); // Arguments are: start X, start Y, array variable name, size X, size Y, color


// Display the pressure icon and measured value
inkplate.setTextSize(4);
inkplate.setCursor(200, 315);
inkplate.print(bme680.readPressure() * 10);
inkplate.print(" hPa");
inkplate.drawBitmap(50, 270, pressure_icon, pressure_icon_w, pressure_icon_h, INKPLATE_BLUE); // Arguments are: start X, start Y, array variable name, size X, size Y, color

// Display Soldered logo
inkplate.drawBitmap(425, 401, logo, logo_w, logo_h, INKPLATE_YELLOW); // Arguments are: start X, start Y, array variable name, size X, size Y, color

// This line actually drawing on the Inkplate screen, previous lines just drawing into the frame buffer
inkplate.display();

// Wait a minute bit between readings due to slow refresh rate
delay(60000);

// If you want to save energy, instead of the delay function, you can use deep sleep as we used in DeepSleep
// examples
}

Functions used​

Inkplate()returns None

Creates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.

ReturnsConstructor; no return value.

BME680()returns None

Soldered BME680 library: creates the sensor object. Called with no arguments, it uses I2C, which is what the Qwiic connection is.

ReturnsConstructor; no return value.

bme680.begin()returns bool

Soldered BME680 library: starts the sensor. The sketch shows Sensor init failed! on the screen and stops when it returns false.

Returnstrue if the sensor started.

bme680.readTemperature()returns float

Soldered BME680 library: reads the temperature. The sketch adds temperatureOffset (0.0) and prints it followed by *C.

ReturnsThe temperature reading.

bme680.readHumidity()returns float

Soldered BME680 library: reads the humidity. The sketch divides it by 10 and prints it followed by %.

ReturnsThe humidity reading.

bme680.readPressure()returns float

Soldered BME680 library: reads the pressure. The sketch multiplies it by 10 and prints it followed by hPa.

ReturnsThe pressure reading.

inkplate.begin()returns void

Initializes the library, the peripherals and the frame buffer. Call it once in setup().

ReturnsNothing.

inkplate.clearDisplay()returns void

Fills the frame buffer with white. It does not change the panel.

ReturnsNothing.

inkplate.setTextSize(uint8_t s)returns void

Sets the text magnification: 5 for temperature and humidity, 4 for pressure.

ReturnsNothing.

inkplate.setTextColor(uint16_t c)returns void

Sets the text color, here INKPLATE_BLACK.

ReturnsNothing.

inkplate.setCursor(int16_t x, int16_t y)returns void

Sets where the next printed text starts.

ReturnsNothing.

inkplate.print(value)returns size_t

Prints text or a number into the frame buffer, like Serial.print().

ReturnsNumber of bytes printed.

inkplate.println(text)returns size_t

Prints text into the frame buffer and moves to the next line. The sketch uses it for the two error lines.

ReturnsNumber of bytes printed.

inkplate.drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)returns void

Draws a one-color bitmap with its top-left corner at (x, y) in the given color. The sketch draws the temperature icon in red, the humidity icon in green, the pressure icon in blue and the logo in yellow.

ReturnsNothing.

inkplate.display(bool _leaveOn = 0)returns void

Sends the whole frame buffer to the panel and refreshes it.

ReturnsNothing.

Serial.begin(115200)returns void

Arduino core function: starts the serial port at 115200 baud. The sketch prints nothing to it.

ReturnsNothing.

delay(ms)returns void

Arduino core function: waits for the given number of milliseconds, here 60000.

ReturnsNothing.

What to expect​

The screen shows the temperature with a *C label next to a red icon, the humidity with a % label next to a green icon, the pressure with an hPa label next to a blue icon, and a yellow Soldered logo in the lower right. It refreshes once a minute. The sketch prints nothing to the Serial Monitor.

If the sensor is not found, the screen shows Sensor init failed! and Check sensor wiring/connection! and the sketch stops.

🔗Open the complete example

examples/Inkplate7SPECTRA/Advanced/Communications/Inkplate7SPECTRA_Qwiic

→