Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ To add altitude use this routine:
}

where **referencePressure** is the pressure in Pa at zero altitude; for example, 101325.0.

#### Examples

BME_I2CTest.ino - Basic usage example; Sends data through Serial monitor
BME_Sleep.ino - Sleeps in-between readings
61 changes: 61 additions & 0 deletions examples/BME_I2CTest/BME_I2CTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Tiny BME280 Library
https://github.com/technoblogy/tiny-bme280
Example to print out environmental data (temperature, pressure, humidity) once per second.

Created by Max Kendall
Modified 20 January 2024
Library by Technoblogy

Connections:
BME --- MCU
VCC to 3v3
GND to GND
SDA to A4
SCL to A5

Set your Serial monitor to 9600 baud and click the magnifiying glass icon on the top-right.
*/

#include <TinyBME280.h>

void setup() {
// Runs once at start or board reset

// Uncomment to change address. Default is 0x77
//BME280setI2Caddress(address)

// Begin the I2C connection with BME280
BME280setup();

// Begin Serial monitor output for debugging
Serial.begin(9600);

Serial.println("BME280 Interface Example.");
}

void loop() {
// Runs forever after setup

// Gives the temperature as a signed 32-bit integer in °C with a resolution of 0.01°C. So an output value of “5123” equals 51.23°C.
float temp = BME280temperature() / 100;

// Pives the pressure in Pa as an unsigned 32-bit integer, so an output value of “96386” equals 96386 Pa, or 963.86 hPa.
float press = BME280pressure() / 100;

// Gives the humidity in %RH with a resolution of 0.01% RH, so an output value of “4653” represents 46.53 %RH.
float humid = BME280humidity() / 100;


// Print the data to Serial output!
Serial.print("Temperature: ");
Serial.print(temp);

Serial.print("Pressure: ");
Serial.println(press);

Serial.print("Humidity: ");
Serial.print(humid);

delay(1000);
}
71 changes: 71 additions & 0 deletions examples/BME_Sleep/BME_Sleep.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Tiny BME280 Library
https://github.com/technoblogy/tiny-bme280
Example to print out environmental data (temperature, pressure, humidity) once every two seconds.
Sleeps in-between reading for lower power consumption.

Created by Max Kendall
Modified 20 January 2024
Library by Technoblogy

Connections:
BME --- MCU
VCC to 3v3
GND to GND
SDA to A4
SCL to A5

Set your Serial monitor to 9600 baud and click the magnifiying glass icon on the top-right.
*/

#include <TinyBME280.h>

void setup() {
// Runs once at start or board reset

// Uncomment to change address. Default is 0x77
//BME280setI2Caddress(address)

// Begin the I2C connection with BME280
BME280setup();

// Begin Serial monitor output for debugging
Serial.begin(9600);

Serial.println("BME280 Interface Example.");
}

void loop() {
// Runs forever after setup

// Wake up BME if asleep
BME280setup();

// Give time to wake up
delay(15);

// Gives the temperature as a signed 32-bit integer in °C with a resolution of 0.01°C. So an output value of “5123” equals 51.23°C.
float temp = BME280temperature() / 100;

// Pives the pressure in Pa as an unsigned 32-bit integer, so an output value of “96386” equals 96386 Pa, or 963.86 hPa.
float press = BME280pressure() / 100;

// Gives the humidity in %RH with a resolution of 0.01% RH, so an output value of “4653” represents 46.53 %RH.
float humid = BME280humidity() / 100;


// Print the data to Serial output!
Serial.print("Temperature: ");
Serial.print(temp);

Serial.print("Pressure: ");
Serial.println(press);

Serial.print("Humidity: ");
Serial.print(humid);

// Go to sleep
BME280sleep();

delay(2000);
}