pdf-icon

Arduino Guide

Unit Mini BPS Arduino User Guide

1. Preparations

Driver Libraries
The M5Unit-ENV library includes drivers and examples for Unit Mini BPS / Unit Mini BPS v1.1 sensors, making it very convenient to read sensor data.

Dependency Libraries
The above driver libraries such as M5UnitUnified and M5Unit-ENV require additional dependency libraries (e.g., M5HAL , M5Utility , etc.). When installing via the Arduino Library Manager, please follow the prompts to install all dependencies.

2. Example

Example Explanation
This example uses the Unit Mini BPS v1.1 to read barometric pressure data. If you are using the Unit Mini BPS (BMP280 version), you can enable a different instance by toggling the USING_BPS comment.
#include <M5Unified.h>
#include "M5UnitENV.h"

M5Canvas canvas(&M5.Display);

// #define USING_BPS
#define USING_BPS_V11

#if defined(USING_BPS)

BMP280 bmp;

#elif defined(USING_BPS_V11)

QMP6988 qmp;

#endif

float calculate_altitude(const float pressure, const float seaLvhPa = 1013.25f)
{
    return 44330.f * (1.0f - pow((pressure / 100.f) / seaLvhPa, 0.1903f));
}

void setup()
{
    M5.begin();
    Serial.begin(115200);
    M5.Display.setFont(&fonts::lgfxJapanMinchoP_20);
    M5.Display.setTextSize(1);
    auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
    auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
    M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);

    Wire.begin(pin_num_sda, pin_num_scl, 400000U);

#if defined(USING_BPS)
    if (!bmp.begin(&Wire, BMP280_I2C_ADDR, pin_num_sda, pin_num_scl, 400000U)) {
        Serial.println("Couldn't find BMP280");
        M5.Display.clear(TFT_RED);
        while (1) delay(1);
    }
    /* Default settings from datasheet. */
    bmp.setSampling(BMP280::MODE_NORMAL,     /* Operating Mode. */
                    BMP280::SAMPLING_X2,     /* Temp. oversampling */
                    BMP280::SAMPLING_X16,    /* Pressure oversampling */
                    BMP280::FILTER_X16,      /* Filtering. */
                    BMP280::STANDBY_MS_500); /* Standby time. */

#elif defined(USING_BPS_V11)
    if (!qmp.begin(&Wire, QMP6988_SLAVE_ADDRESS_L, pin_num_sda, pin_num_scl, 400000U)) {
        Serial.println("Couldn't find QMP6988");
        M5.Display.clear(TFT_RED);
        while (1) delay(1);
    }

#endif
}

void loop()
{
    M5.update();

#if defined(USING_BPS)

    if (bmp.update()) {
        M5.Display.setCursor(0, 0);
        M5.Display.clear(TFT_BLACK);
        M5.Display.println("-----BMP280-----");
        M5.Display.print(F("Temperature: "));
        M5.Display.print(bmp.cTemp);
        M5.Display.println(" degrees C");
        M5.Display.print(F("Pressure: "));
        M5.Display.print(bmp.pressure);
        M5.Display.println(" Pa");
        M5.Display.print(F("Approx altitude: "));
        M5.Display.print(bmp.altitude);
        M5.Display.println(" m");
        M5.Display.println("-------------\r\n");
    }

#elif defined(USING_BPS_V11)

    if (qmp.update()) {
        M5.Display.setCursor(0, 0);
        M5.Display.clear(TFT_BLACK);
        M5.Display.println("-----QMP6988-----");
        M5.Display.print(F("Temperature: "));
        M5.Display.print(qmp.cTemp);
        M5.Display.println(" *C");
        M5.Display.print(F("Pressure: "));
        M5.Display.print(qmp.pressure);
        M5.Display.println(" Pa");
        M5.Display.print(F("Approx altitude: "));
        M5.Display.print(qmp.altitude);
        M5.Display.println(" m");
        M5.Display.println("-------------\r\n");
    }

#endif
    delay(1000);
}

3. Compile and Upload

    1. Download Mode: Different devices require a download mode before program flashing; this step may vary depending on the main control device. For details, please refer to the device programming download tutorial list at the bottom of the Arduino IDE Getting Started Tutorial page to see the specific operation.
  • For the CoreS3, hold down the reset button (approximately 2 seconds) until the internal green LED lights up, then release. At this point, the device has entered download mode and is waiting for flashing.

    1. Select the device port, click the compile and upload button in the upper left corner of the Arduino IDE, and wait for the program to compile and upload to the device.

4. Reading Pressure Values

On This Page