Skip to content

Commit

Permalink
Merge pull request #4 from hasenradball/prerelease_v1.1.0
Browse files Browse the repository at this point in the history
[esp8266/arduino]: Release v1.1.0
  • Loading branch information
hasenradball authored Nov 9, 2024
2 parents 1468c2a + f32c673 commit 59e8673
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 70 deletions.
51 changes: 41 additions & 10 deletions .github/workflows/compile_examples.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
name: Compile examples folder
name: Compile examples foolder

on:
- push
- pull_request
on: [push, pull_request]

jobs:
compile-examples:
build-arduino:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arduino/compile-sketches@v1
with:
libraries: |
- source-path: ./
sketch-paths:
./examples/Arduino_example/Arduino_example.ino

build-esp8266:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, 'esp8266')

strategy:
fail-fast: false

matrix:
board:
- fqbn: esp8266:esp8266:nodemcu
- fqbn: esp8266:esp8266:d1_mini
core:
- version: 3.1.2
- version: 3.0.2

steps:
- uses: actions/checkout@v3
- uses: arduino/compile-sketches@v1
with:
libraries: |
- source-path: ./
- name: Checkout code
uses: actions/checkout@v4

- name: Compile ESP8266 examples
uses: arduino/compile-sketches@v1
with:
platforms: |
- name: esp8266:esp8266
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
version: ${{ matrix.core.version }}
fqbn: ${{ matrix.board.fqbn }}
libraries: |
- source-path: ./
sketch-paths:
./examples/ESP8266_example/ESP8266_example.ino
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[![Compile examples folder](https://github.com/hasenradball/Bosch_BME280_Arduino/actions/workflows/compile_examples.yml/badge.svg?branch=master)](https://github.com/hasenradball/Bosch_BME280_Arduino/actions/workflows/compile_examples.yml)
[![Spell Check](https://github.com/hasenradball/Bosch_BME280_Arduino/actions/workflows/spell_checker.yml/badge.svg?branch=master)](https://github.com/hasenradball/Bosch_BME280_Arduino/actions/workflows/spell_checker.yml)
# Bosch BME280 Arduino
based on Bosch BME280_driver v3.5.1

![BME280_Module](./docs/Bosch_BME280_module.jpeg)

List of content<br>
* [About](#about)<br>
* [Functionality](#functionality)<br>
Expand All @@ -14,7 +18,7 @@ List of content<br>
## About
The Bosch BME280 is an environmental sensor which is able to measure temperature, humidity and air pressure.

This library is based on the Bosch Sensortec BME280 driver API v3.5.1, and is intented to measure these environmental signals via I²C connection on an Arduino based or ESP based microcontroller.
This library is based on the Bosch Sensortec BME280 driver API v3.5.1, and is intended to measure these environmental signals via I²C connection on an Arduino based or ESP based microcontroller.

The github repository of Bosch Sensortec is: [Github BOSCH Sensor Driver](https://github.com/BoschSensortec/BME280_driver)

Expand All @@ -23,14 +27,14 @@ The website of the BME280 on Bosch Sensortec is: [Bosch Sensortec BME280](https:
## Functionality
The original Bosch driver is included in this package and it has not been modified in any way.
The Bosch BME280 sensor do have 3 operation modes.
1. **Sleep mode** - the sensor is in sleep mode after power on reset. No measurements are performed and power consumtion is on minimum.
1. **Sleep mode** - the sensor is in sleep mode after power on reset. No measurements are performed and power consumption is on minimum.
2. **Forced mode** - one single measurement is performed and returns then to sleep mode. The measurements can be obtained from the data registers.
3. **Normal mode** - cyclic measurements are performed. The measurements can be obtained fron the data registers.
3. **Normal mode** - cyclic measurements are performed. The measurements can be obtained from the data registers.

## Namespace
This Bosch BME280 Wraper uses a namespace as `BME` so if you construct the object you have to call:
This Bosch BME280 wrapper uses a namespace as `BME` so if you construct the object you have to call:
```
BME::Bosch_BME280 bme{-1, -1, BME280_I2C_ADDR_PRIM, 249.67F, false};
BME::Bosch_BME280 bme{BME280_I2C_ADDR_PRIM, 249.67F, false};
```

## Methods
Expand All @@ -39,12 +43,11 @@ The are the following public methods:

#### Constructor
You call the constructor with various parameters:
* the SDA and SCL pin (in case of ESP variants), `-1` in case for Arduino variants
* address of the BME280 (0x76 or 0x77)
* altitude for the calculation of the sea level pressure
* a Bool - `true` if use forced mode or `false` if use normal mode
```
Bosch_BME280(sda_pin, scl_pin, addr, altitude, forced_mode)
Bosch_BME280(addr, altitude, forced_mode)
```
#### Init I²C and Sensor Init
```
Expand Down Expand Up @@ -77,14 +80,24 @@ See also in:
#include <Arduino.h>
#include <Bosch_BME280_Arduino.h>
BME::Bosch_BME280 bme{-1, -1, BME280_I2C_ADDR_PRIM, 249.67F, true};
BME::Bosch_BME280 bme{BME280_I2C_ADDR_PRIM, 249.67F, true};
void setup() {
Serial.begin(115200);
while (!Serial) {
yield();
}
// SDA, SCL needed for ESPs
#if defined (ESP8266)
Wire.begin(SDA, SCL);
#elif defined (ESP32)
Wire.setPins(SDA, SCL);
Wire.begin();
#else
Wire.begin();
#endif
// init Bosch BME 280 Sensor
if (bme.begin() != 0) {
Serial.println("\n\t>>> ERROR: Init of Bosch BME280 Sensor failed! <<<");
Expand Down
Binary file added docs/Bosch_BME280_module.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions examples/Arduino_example/Arduino_example.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#include <Arduino.h>
#include <Wire.h>
#include <Bosch_BME280_Arduino.h>

BME::Bosch_BME280 bme{-1, -1, BME280_I2C_ADDR_PRIM, 249.67F, true};
// global instance
BME::Bosch_BME280 bme{BME280_I2C_ADDR_PRIM, 249.67F, true};

void setup() {
Serial.begin(115200);
while (!Serial) {
yield();
}

// init Bosch BME 280 Sensor
if (bme.begin() != 0) {
Wire.begin();
// init Bosch BME 280 Sensor
if (bme.begin() != 0) {
Serial.println("\n\t>>> ERROR: Init of Bosch BME280 Sensor failed! <<<");
}
}
}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Arduino.h>

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <Bosch_BME280_Arduino.h>

Expand All @@ -8,32 +8,42 @@
// ### --- START: Klassen Instanzen --- ###
// ============================================

BME::Bosch_BME280 sensor_bme280{0, 2, BME280_I2C_ADDR_PRIM, 249.76F, true};
BME::Bosch_BME280 sensor_bme280{BME280_I2C_ADDR_PRIM, 249.76F, true};

// ============================================
// ### --- ENDE: Klassen --- ###
// ### --- END: Klassen --- ###
// ============================================


// ============================================
// ### --- START: Setup --- ###
// ============================================
void setup() {
WiFi.mode(WIFI_OFF);
// Serielle Schnittstelle initialisieren
Serial.begin(115200);
while (!Serial) {
WiFi.mode(WIFI_OFF);
// Serielle Schnittstelle initialisieren
Serial.begin(115200);
while (!Serial) {
yield();
}
Serial.println(F("\n ### >>> ESP01 Test - read Bosch BME280 Sensor Data <<< ###"));
}
Serial.println(F("\n ### >>> ESP01 Test - read Bosch BME280 Sensor Data <<< ###"));

// SDA, SCL needed for ESPs
#if defined (ESP8266)
Wire.begin(SDA, SCL);
#elif defined (ESP32)
Wire.setPins(SDA, SCL);
Wire.begin();
#else
Wire.begin();
#endif

Serial.println(F("\t>>> init Sensor"));

sensor_bme280.begin();
Serial.println(F("\t>>> init Sensor"));
sensor_bme280.begin();
}

// ============================================
// ### --- ENDE: Setup --- ###
// ### --- END: Setup --- ###
// ============================================

// ============================================
Expand All @@ -55,5 +65,5 @@ void loop() {
}
}
// ============================================
// ### --- ENDE: Main Loop --- ###
// ### --- END: Main Loop --- ###
// ============================================
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bosch_BME280_Arduino",
"version": "1.0.2",
"version": "1.1.0",
"repository":
{
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bosch_BME280_Arduino
version=1.0.2
version=1.1.0
author=Frank Häfele <[email protected]>
maintainer=Frank Häfele <[email protected]>
sentence=C++ Library for the Bosch BME280 Sensor based on the original Bosch Sensor API v3.5.1
Expand Down
33 changes: 10 additions & 23 deletions src/Bosch_BME280_Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
Based on: Bosch Sensortec BME280 driver release v3.5.1
*/
#include <Bosch_BME280_Arduino.h>
#include <Wire.h>

/**
* @brief Construct a new bme::Bosch_BME280 Object
*
* @param sda_pin Pin for SDA Signal (-1 for Arduino usage)
* @param scl_pin Pin for SCL Signal (-1 for Arduino usage)
* @param addr I²C-Address for sensor (0x76 default)
* @param altitude Altitude for the calculation of the Air Pressure at NN
* @param forced_mode if true the sensor makes one measurement and goes to sleep (no continous measurement)
* @param forced_mode if true the sensor makes one measurement and goes to sleep (no continuous measurement)
*/
BME::Bosch_BME280::Bosch_BME280(int8_t sda_pin, int8_t scl_pin, uint8_t addr, float altitude, bool forced_mode) :
_sda_pin {sda_pin},
_scl_pin {scl_pin},
_sensor_status {BME280_OK},
_addr {addr},
_altitude {altitude}
BME::Bosch_BME280::Bosch_BME280(uint8_t addr, float altitude, bool forced_mode) :
_altitude {altitude},
_sensor_status {BME280_OK},
_addr {addr}
{
// set internal _mode
if (forced_mode) {
Expand Down Expand Up @@ -50,16 +47,6 @@ int8_t BME::Bosch_BME280::begin() {
_dev.write = &BME::Bosch_BME280::I2CWrite;
_dev.delay_us = &BME::Bosch_BME280::delay_us;

// SDA, SCL needed for ESPs
#if defined (ESP8266)
Wire.begin(_sda_pin, _scl_pin);
#elif defined (ESP32)
Wire.setPins(_sda_pin, _scl_pin);
Wire.begin();
#else
Wire.begin();
#endif
// I2C init END
// Init of sensor
_sensor_status = bme280_init(&_dev);
bme280_print_error_codes("bme280_init", _sensor_status);
Expand Down Expand Up @@ -114,7 +101,7 @@ int8_t BME::Bosch_BME280::measure_normal_mode() {
}

/**
* @brief measure in forced mode. In forced mode the sesnor takes one measurement and then goes to sleep
* @brief measure in forced mode. In forced mode the sensor takes one measurement and then goes to sleep
*
* @return sensor status
*
Expand All @@ -139,7 +126,7 @@ int8_t BME::Bosch_BME280::measure_forced_mode() {
}

/**
* @brief set Sensor settings for forced or normal mode of BME280
* @brief set sensor settings for forced or normal mode of BME280
*
* @return sensor status
*
Expand Down Expand Up @@ -238,7 +225,7 @@ int8_t BME::Bosch_BME280::setSensorSettings() {
* @param cnt count of Bytes
* @param intf_ptr Pointer of user defined function
*
* @return sensor communcation status
* @return sensor communication status
*
* @retval 0 -> Success.
* @retval > 0 -> Warning.
Expand Down Expand Up @@ -281,7 +268,7 @@ BME280_INTF_RET_TYPE BME::Bosch_BME280::I2CRead(uint8_t reg_addr, uint8_t *reg_d
* @param cnt count of Bytes
* @param intf_ptr Pointer of user defined function
*
* @return sensor communcation status
* @return sensor communication status
*
* @retval 0 -> Success.
* @retval > 0 -> Warning.
Expand Down
16 changes: 7 additions & 9 deletions src/Bosch_BME280_Arduino.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef _BOSCH_BME280_ARDUINO_H_
#define _BOSCH_BME280_ARDUINO_H_
#include <Arduino.h>
#include <Wire.h>
#include "BME280_API/bme280.h"

namespace BME {
class Bosch_BME280 {
public:
explicit Bosch_BME280(int8_t sda_pin = -1, int8_t scl_pin = -1, uint8_t addr = BME280_I2C_ADDR_PRIM, float altitude = 249.67F, bool forced_mode = true);
explicit Bosch_BME280(uint8_t addr = BME280_I2C_ADDR_PRIM, float altitude = 249.67F, bool forced_mode = true);

int8_t begin();
int8_t measure();
Expand All @@ -20,17 +19,16 @@ namespace BME {
void setSensorStatus(int8_t sensor_status);

private:
int8_t _sda_pin, _scl_pin;
int8_t _sensor_status;
uint8_t _addr, _mode;
float _altitude;

// variable for delay time in µs
uint32_t _period;
struct bme280_dev _dev;
struct bme280_data _bme280_data;
struct bme280_settings _settings;
// variable for delay time in µs
uint32_t _period;

float _altitude;
int8_t _sensor_status;
uint8_t _addr, _mode;

int8_t setSensorSettings();
int8_t measure_normal_mode();
int8_t measure_forced_mode();
Expand Down

0 comments on commit 59e8673

Please sign in to comment.