Temperature, humidity, air pressure and gas values displayed on M5Stick-C and BME680 | そう備忘録

Temperature, humidity, air pressure and gas values displayed on M5Stick-C and BME680

BME680

BME680 is a sensor made by BOSCH that can detect temperature, humidity, air pressure, and gas.

There are several modules that use BME680 available on the market.
In this case, I used a module made by Seeed Studio Bazaar and connected it to the M5Stick-C.

This product comes with a GROVE cable, so it can be easily connected to the M5Stick-C via I2C.

BME680 and GROVE cable

Specifications

The main specifications of the product I purchased are as follows.

  • Operating voltage : 3.3V to 5.0V
  • Temperature : -40 to +85°C
  • Humidity : 0 to 100 %
  • Air pressure: 300 to 1100 hPa
  • Interface : I2C (max. 3.4 MHz)/SPI (3-wire and 4-wire, max. 10 MHz)
  • I2C address : 0x76 (default) / 0x77 (option) *1

*1 The default I2C address is 0x76, but it can be changed to 0x77 by shorting the left and center pins of the red frame on the back.

(default is 0x76 with the center and right pins shorted.

Similarly, short-circuiting the terminal below it makes I2C (default), and opening it makes SPI connection.

Changing the I2C address

It is also capable of measuring VOC (Volatile Organic Compounds)).

The website says it can be used as an IAQ sensor (indoor air quality sensor) by measuring in the range of 0 (clean air) to 500 (dirty air).

In the sample program, the unit was “Kohms” instead of ppm or mg/m3, but I didn’t understand the meaning of this unit.

I think it’s good for roughly grasping how dirty (or not) the air in a room is.

The following is a table of IAQ from the BOSCH data sheet.

The higher the value, the dirtier the air is judged to be.

IAQ
BME680

M5Stick-C

I used the M5Stick-C that I bought before.

M5Stick-C is a stick-type product of M5Stack, which is equipped with ESP32-PICO.

For more details, please refer to the previous article.

If you want to buy it now, I think it will be M5Stick-C Plus.

M5Stick-C

Wiring diagram

The connection between the M5Stick-C and the BME680 is as follows.

The connection can be made by plugging in the supplied GROVE cable.

M5Stick-C and BME680

Installing the library

Before I start, I need to install the BME680 library into the Arduino IDE.

I found several libraries for BME680, but since the module I used this time is from seeed studio, I downloaded it from seeed’s Github.

Go to this page and select “Code” > “Download ZIP” to download Seeed_BME680-master.zip.

Download the library

Start Arduino IDE, go to sketch, Include Library, Add .ZIP Library, select the file you just downloaded and install the BME680 library.

Include the library in ZIP format

Sketch

I wrote a simple sketch based on a sample program I found on Github.

Source Code

/*
 * Testing BME680 on M5Stick-C
 * Displaying the measurement results on the display
 * 
 * @author: Souichirou Kikuchi
 */

#include <M5StickC.h>
#include "seeed_bme680.h"

#define IIC_ADDR  uint8_t(0x76)

Seeed_BME680 bme680(IIC_ADDR); // IIC PROTOCOL

void setupM5StickC() {
    M5.begin();
    delay(10 * 1000); // wait 10 seconds
    setCpuFrequencyMhz(80);
    M5.Axp.begin(false,false,false,false,true);
    M5.Axp.ScreenBreath(10); // Reduce the brightness of the screen
    M5.Lcd.setRotation(1); // change direction
    M5.Lcd.setTextSize(2);
    M5.Lcd.setTextColor(WHITE, BLACK); // White for text, black for background
    M5.Lcd.setCursor(10, 10);
}

void display(float temp, float humi, float pres, float gas) {
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setCursor(0, 0);
    M5.Lcd.printf("temp: %4.1f'C\r\n", temp);
    M5.Lcd.printf("humi:%4.1f%%\r\n", humi);
    M5.Lcd.printf("pres:%5.1fhPa\r\n", pres);
    M5.Lcd.printf("gas: %3.2f Kohms\r\n", gas);
}


void setup() {
    int cnt = 0;
    const int MAX_RETRY = 10;

    Serial.begin(115200);
    while (!Serial);
    M5.Lcd.println("Program start");
    delay(100);
    setupM5StickC();
    Wire.begin();

    while ((!bme680.init()) and (cnt < MAX_RETRY)) {
        M5.Lcd.println("BME680 init failed");
        cnt++;
        delay(10000);
    }
    if (cnt < MAX_RETRY) {
        M5.Lcd.println("BME680 initialized");
    }
}

void loop() {
    float temp, humi, pres, gas;

    if (bme680.read_sensor_data()) {
        M5.Lcd.println("read error");
        return;
    }
    temp = bme680.sensor_result_value.temperature;
    humi = bme680.sensor_result_value.humidity;
    pres = bme680.sensor_result_value.pressure / 100.0; // Converted to hPa
    gas = bme680.sensor_result_value.gas / 1000.0;
    display(temp, humi, pres, gas);
    delay(5000);
}

Compile & Upload

After connecting the M5Stick-C to the PC via USB, a new COM port appeared and the following settings were made in the tool menu.

  • Board: M5Stick-C
  • Upload Speed: 115200
  • Port: COM3 (depends on the environment)

Ctrl + U to compile and upload the executable program to the M5Stick-C board.

tools

Operation check

I was able to confirm that the temperature, humidity, air pressure, and gas were measured at 5-second intervals and displayed on the M5Stick-C monitor.

At any rate, the air pollution in the room was less than 50, so it was Good!

とりあえず部屋の中の空気の汚れは 50 以下なので Good! だった。

M5StickC & BME680

This concludes this article.

Finally.

I hope this article will be useful to someone somewhere.

souichirou kikuchi

I'm Japanese. A reminder to remember what I've done. I'm blogging in the hope that it will be helpful to others who want to do similar things. I mainly write blogs about LEGO, AWS (Amazon Web Services), WordPress, Deep Learning and Raspberry Pi. At work, I'm working on installing collaborative robots and IoT in factories. I passed the JDLA (Japan Deep Learning Association) Deep Learning for GENERAL in July 2019. If you have any questions, please leave them in the comments at the bottom of the article.

comment

Name, Email, and Website are optional.
and, your Email address will not be published.