Home » enviro:bit BME280 sensor and bpi:bit Arduino code example

enviro:bit BME280 sensor and bpi:bit Arduino code example

by shedboy71

In this example we look at the enviro:bit which is an add on from pimoroni which has a BME280 temperature, pressure, and humidity sensor fitted to it a long with a TCS3472 light and colour sensor and a MEMS microphone

Lets look at the enviro:bit fitted to a bpi:bit

enviro:bit and bpi:bit

enviro:bit and bpi:bit

Features:

  • Comes fully-assembled and ready to use.
  • BME280 temperature, pressure, and humidity sensor.
  • TCS3472 light and colour sensor.
  • MEMS microphone.
  • Compatible with micro:bit.
  • Microsoft MakeCode and MicroPython support.
  • No soldering required!

Lets look at the BME280 sensor now

The BME280 is an integrated environmental sensor developed specifically for mobile applications where size and low power consumption are key design constraints. The unit combines individual high linearity, high accuracy sensors for pressure, humidity and temperature in an 8-pin metal-lid 2.5 x 2.5 x 0.93 mm³ LGA package, designed for low current consumption (3.6 μA @1Hz), long term stability and high EMC robustness.

The humidity sensor features an extremely fast response time which supports performance requirements for emerging applications such as context awareness, and high accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with features exceptionally high accuracy and resolution at very low noise. The integrated temperature sensor has been optimized for very low noise and high resolution. It is primarily used for temperature compensation of the pressure and humidity sensors, and can also be used for estimating ambient temperature.

The BME280 supports a full suite of operating modes which provides the flexibility to optimize the device for power consumption, resolution and filter performance.

Parts List

Name link
Banana PI Bit board Banana PI Bit board with EPS32
envirobit Pimoroni enviro:bit for BBC micro:bit

Code

You need to import the BME280 and sensor libraries into the Arduino IDE. The BME280 sensor is set to 0x76 on the envirobit

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C


unsigned long delayTime;

void setup() {
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));

    unsigned status;
    
    // default settings
    // (you can also pass in a Wire library object like &Wire2)
    status = bme.begin(0x76);  
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1);
    }
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() { 
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}

[/codesyntax]

Output

Open the serial monitor window and you will see something like this

Temperature = 21.40 *C
Pressure = 1009.94 hPa
Approx. Altitude = 27.61 m
Humidity = 41.04 %

Temperature = 21.40 *C
Pressure = 1009.92 hPa
Approx. Altitude = 27.74 m
Humidity = 41.03 %

Temperature = 21.39 *C
Pressure = 1009.90 hPa
Approx. Altitude = 27.90 m
Humidity = 41.04 %

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.