Compare commits
26 Commits
1.4
...
57590c0c5e
| Author | SHA1 | Date | |
|---|---|---|---|
| 57590c0c5e | |||
| 4427d84585 | |||
|
|
2bb12a188c | ||
|
|
eb587224de | ||
|
|
60f85caf3f | ||
|
|
57f7874a46 | ||
|
|
b0e4dac0a8 | ||
|
|
0c177ea312 | ||
|
|
19e719849f | ||
|
|
d6fd205bc5 | ||
|
|
585e7570d6 | ||
|
|
6d1f41b802 | ||
|
|
e6f0f67a51 | ||
|
|
7b6a50be4e | ||
|
|
3655e54aeb | ||
|
|
5185af0a07 | ||
|
|
8ff5ec6ab3 | ||
|
|
cc8f7e27d8 | ||
|
|
bba8bf7d70 | ||
|
|
c44179b07f | ||
|
|
8cad0cbb19 | ||
|
|
0044aa8d95 | ||
|
|
6cf7858423 | ||
|
|
127ebda97a | ||
|
|
4d03e6d538 | ||
|
|
7ce521bae1 |
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Alex
|
||||
Copyright (c) 2021 AlexGyver
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
27
README.md
27
README.md
@@ -1,8 +1,15 @@
|
||||

|
||||

|
||||
[](https://github.com/GyverLibs/GyverBME280/releases/latest/download/GyverBME280.zip)
|
||||
[](https://alexgyver.ru/)
|
||||
[](https://alexgyver.ru/support_alex/)
|
||||
[](https://github-com.translate.goog/GyverLibs/GyverBME280?_x_tr_sl=ru&_x_tr_tl=en)
|
||||
|
||||
[](https://t.me/GyverLibs)
|
||||
|
||||
# GyverBME280
|
||||
Лёгкая библиотека для работы с BME280 по I2C для Arduino
|
||||
|
||||
**Примечание** (от автора форка): Библиотека частично совместима с оригинальной. Отличается только конструктор и процесс инициализации.
|
||||
|
||||
### Совместимость
|
||||
Совместима со всеми Arduino платформами (используются Arduino-функции)
|
||||
|
||||
@@ -26,6 +33,11 @@
|
||||
- Распаковать и положить в *Документы/Arduino/libraries/*
|
||||
- (Arduino IDE) автоматическая установка из .zip: *Скетч/Подключить библиотеку/Добавить .ZIP библиотеку…* и указать скачанный архив
|
||||
- Читай более подробную инструкцию по установке библиотек [здесь](https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA)
|
||||
### Обновление
|
||||
- Рекомендую всегда обновлять библиотеку: в новых версиях исправляются ошибки и баги, а также проводится оптимизация и добавляются новые фичи
|
||||
- Через менеджер библиотек IDE: найти библиотеку как при установке и нажать "Обновить"
|
||||
- Вручную: **удалить папку со старой версией**, а затем положить на её место новую. "Замену" делать нельзя: иногда в новых версиях удаляются файлы, которые останутся при замене и могут привести к ошибкам!
|
||||
|
||||
|
||||
<a id="init"></a>
|
||||
## Инициализация
|
||||
@@ -123,8 +135,19 @@ void loop() {
|
||||
## Версии
|
||||
- v1.3 - исправлена ошибка при отриц. температуре
|
||||
- v1.4 - разбил на h и cpp
|
||||
- v1.5 - добавлена поддержка BMP280
|
||||
|
||||
<a id="feedback"></a>
|
||||
## Баги и обратная связь
|
||||
При нахождении багов создавайте **Issue**, а лучше сразу пишите на почту [alex@alexgyver.ru](mailto:alex@alexgyver.ru)
|
||||
Библиотека открыта для доработки и ваших **Pull Request**'ов!
|
||||
|
||||
|
||||
При сообщении о багах или некорректной работе библиотеки нужно обязательно указывать:
|
||||
- Версия библиотеки
|
||||
- Какой используется МК
|
||||
- Версия SDK (для ESP)
|
||||
- Версия Arduino IDE
|
||||
- Корректно ли работают ли встроенные примеры, в которых используются функции и конструкции, приводящие к багу в вашем коде
|
||||
- Какой код загружался, какая работа от него ожидалась и как он работает в реальности
|
||||
- В идеале приложить минимальный код, в котором наблюдается баг. Не полотно из тысячи строк, а минимальный код
|
||||
|
||||
146
README_EN.md
Normal file
146
README_EN.md
Normal file
@@ -0,0 +1,146 @@
|
||||
This is an automatic translation, may be incorrect in some places. See sources and examples!
|
||||
|
||||
# Gyverbme280
|
||||
Light library for working with BME280 on I2C for Arduino
|
||||
|
||||
## compatibility
|
||||
Compatible with all arduino platforms (used arduino functions)
|
||||
|
||||
## Content
|
||||
- [installation] (# Install)
|
||||
- [initialization] (#init)
|
||||
- [use] (#usage)
|
||||
- [Example] (# Example)
|
||||
- [versions] (#varsions)
|
||||
- [bugs and feedback] (#fedback)
|
||||
|
||||
<a id="install"> </a>
|
||||
## Installation
|
||||
- The library can be found by the name ** gyverbme280 ** and installed through the library manager in:
|
||||
- Arduino ide
|
||||
- Arduino ide v2
|
||||
- Platformio
|
||||
- [download library] (https://github.com/gyverlibs/gyverbme280/archive/refs/heads/main.zip). Zip archive for manual installation:
|
||||
- unpack and put in * C: \ Program Files (X86) \ Arduino \ Libraries * (Windows X64)
|
||||
- unpack and put in * C: \ Program Files \ Arduino \ Libraries * (Windows X32)
|
||||
- unpack and put in *documents/arduino/libraries/ *
|
||||
- (Arduino id) Automatic installation from. Zip: * sketch/connect the library/add .Zip library ... * and specify downloaded archive
|
||||
- Read more detailed instructions for installing libraries [here] (https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%BD%D0%BE%BE%BE%BED0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA)
|
||||
### Update
|
||||
- I recommend always updating the library: errors and bugs are corrected in the new versions, as well as optimization and new features are added
|
||||
- through the IDE library manager: find the library how to install and click "update"
|
||||
- Manually: ** remove the folder with the old version **, and then put a new one in its place.“Replacement” cannot be done: sometimes in new versions, files that remain when replacing are deleted and can lead to errors!
|
||||
|
||||
|
||||
<a id="init"> </a>
|
||||
## initialization
|
||||
`` `CPP
|
||||
Gyverbme280 BME;
|
||||
`` `
|
||||
|
||||
<a id="usage"> </a>
|
||||
## Usage
|
||||
`` `CPP
|
||||
Bool Begin (VOID);// Launch with a standard address (0x76)
|
||||
Bool Begin (Uint8_T Address);// Launch addressing the address
|
||||
Bool ISMEASURING (VOID);// returns True while the measurement is underway
|
||||
Float Readpressure (Void);// Read the pressure in PA
|
||||
Float Readhumidity (VOID);// read humidity in %
|
||||
VOID OneMeasurement (VOID);// make one dimension and go into a dream
|
||||
Float ReadTemperature (VOID);// Read the temperature in degrees with
|
||||
|
||||
VOID setmode (uint8_t mode);// set the operating mode
|
||||
// modes:
|
||||
Normal_Mode
|
||||
Forced_Mode
|
||||
|
||||
VOID SetFilter (Uint8_t Mode);// Change the filtration coefficient.Call before Begin
|
||||
// coefficients:
|
||||
Filter_disable
|
||||
Filter_coEF_2
|
||||
Filter_coEF_4
|
||||
Filter_coEF_8
|
||||
Filter_coEF_16
|
||||
|
||||
VOID SetstandbyTime (Uint8_t Mode);// Change the time between measurements.Call before Begin
|
||||
// modes:
|
||||
Standby_500us
|
||||
Standby_10ms
|
||||
Standby_20ms
|
||||
Standby_6250us
|
||||
Standby_125MS
|
||||
Standby_250MS
|
||||
Standby_500ms
|
||||
Standby_1000ms
|
||||
|
||||
VOID sethumoversampling (Uint8_t Mode);// Configure oversemling or turn off humidity.Call before Begin
|
||||
VOID settempoVersampling (Uint8_t Mode);// Configure oversemling or turn off the temperature.Call before Begin
|
||||
VOID SetPressoversampling (Uint8_t Mode);// configure oversemling or disconnect dCranberry.Call before Begin
|
||||
// modes:
|
||||
Module_disable
|
||||
Oversampling_1
|
||||
Oversampling_2
|
||||
Oversampling_4
|
||||
Oversampling_8
|
||||
Oversampling_16
|
||||
`` `
|
||||
|
||||
<a id="EXAMPLE"> </a>
|
||||
## Example
|
||||
The rest of the examples look at ** Examples **!
|
||||
`` `CPP
|
||||
/*
|
||||
A simple example, demonstrating the basic functions of measuring temperature, pressure and humidity
|
||||
*/
|
||||
|
||||
#incLude <gyverbme280.h> // Library connection
|
||||
Gyverbme280 BME;// Creating a BME Object
|
||||
|
||||
VOID setup () {
|
||||
Serial.Begin (9600);// launch of the sequential port
|
||||
bme.begin ();// if additional.Settings are not needed - initialize the sensor
|
||||
}
|
||||
|
||||
VOID loop () {
|
||||
Serial.print ("Temperature:");
|
||||
Serial.print (BME.Readtemperature ());// We display the temporary core in [*c]
|
||||
Serial.println (" *c");
|
||||
|
||||
Serial.print ("Humidity:");
|
||||
Serial.print (bme.readhumidity ());// We display humidity in [%]
|
||||
Serial.println (" %");
|
||||
|
||||
Float Pressure = Bme.Readpressure ();// read pressure in [pa]
|
||||
Serial.print ("Pressure:");
|
||||
Serial.print (Pressure / 100.0F);// Removing pressure in [GPA]
|
||||
Serial.print ("hpa,");
|
||||
Serial.print (Pressuretommhg (Pressure));// Removing the pressure in [mm RT.pillar]
|
||||
Serial.println ("MM HG");
|
||||
Serial.print ("altitide:");
|
||||
Serial.print// We display height B [m above the ur.seas]
|
||||
Serial.println ("m");
|
||||
Serial.println ("");
|
||||
DELAY (1000);
|
||||
}
|
||||
`` `
|
||||
|
||||
<a id="versions"> </a>
|
||||
## versions
|
||||
- V1.3 - Fixed error when ledge.temperature
|
||||
- v1.4 - divided into h and CPP
|
||||
- V1.5 - Added BMP280 support
|
||||
|
||||
<a id="feedback"> </a>
|
||||
## bugs and feedback
|
||||
Create ** Issue ** when you find the bugs, and better immediately write to the mail [alex@alexgyver.ru] (mailto: alex@alexgyver.ru)
|
||||
The library is open for refinement and your ** pull Request ** 'ow!
|
||||
|
||||
|
||||
When reporting about bugs or incorrect work of the library, it is necessary to indicate:
|
||||
- The version of the library
|
||||
- What is MK used
|
||||
- SDK version (for ESP)
|
||||
- version of Arduino ide
|
||||
- whether the built -in examples work correctly, in which the functions and designs are used, leading to a bug in your code
|
||||
- what code has been loaded, what work was expected from it and how it works in reality
|
||||
- Ideally, attach the minimum code in which the bug is observed.Not a canvas of a thousand lines, but a minimum code
|
||||
@@ -1,5 +1,5 @@
|
||||
name=GyverBME280
|
||||
version=1.4
|
||||
version=1.5
|
||||
author=AlexGyver <alex@alexgyver.ru>
|
||||
maintainer=AlexGyver <alex@alexgyver.ru>
|
||||
sentence=Light library for BME280 sensor
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
/* ============ Utilities ============ */
|
||||
|
||||
float pressureToAltitude(float pressure) {
|
||||
if(!pressure) return 0; // If the pressure module has been disabled return '0'
|
||||
if (!pressure) return 0; // If the pressure module has been disabled return '0'
|
||||
pressure /= 100.0F; // Convert [Pa] to [hPa]
|
||||
return 44330.0 * (1.0 - pow(pressure / 1013.25, 0.1903)); // Сalculate altitude
|
||||
return 44330.0f * (1.0f - pow(pressure / 1013.25f, 0.1903f)); // Сalculate altitude
|
||||
}
|
||||
|
||||
float pressureToMmHg(float pressure) {
|
||||
@@ -14,23 +14,27 @@ float pressureToMmHg(float pressure) {
|
||||
|
||||
/* ============ Setup & begin ============ */
|
||||
|
||||
bool GyverBME280::begin(void) {
|
||||
return GyverBME280::begin(0x76);
|
||||
GyverBME280::GyverBME280(TwoWire &wire) {
|
||||
_wire = &wire;
|
||||
}
|
||||
|
||||
bool GyverBME280::begin() {
|
||||
return begin(0x76);
|
||||
}
|
||||
|
||||
bool GyverBME280::begin(uint8_t address) {
|
||||
_i2c_address = address;
|
||||
/* === Start I2C bus & check BME280 === */
|
||||
Wire.begin(); // Start I2C bus
|
||||
if(!GyverBME280::reset()) return false; // BME280 software reset & ack check
|
||||
if(GyverBME280::readRegister(0xD0) != 0x60) return false; // Check chip ID
|
||||
GyverBME280::readCalibrationData(); // Read all calibration values
|
||||
if (!reset()) return false; // BME280 software reset & ack check
|
||||
uint8_t ID = readRegister(0xD0);
|
||||
if (ID != 0x60 && ID != 0x58) return false; // Check chip ID (bme/bmp280)
|
||||
readCalibrationData(); // Read all calibration values
|
||||
|
||||
/* === Load settings to BME280 === */
|
||||
GyverBME280::writeRegister(0xF2 , _hum_oversampl); // write hum oversampling value
|
||||
GyverBME280::writeRegister(0xF2 , GyverBME280::readRegister(0xF2)); // rewrite hum oversampling register
|
||||
GyverBME280::writeRegister(0xF4 , ((_temp_oversampl << 5) | (_press_oversampl << 2) | _operating_mode)); // write temp & press oversampling value , normal mode
|
||||
GyverBME280::writeRegister(0xF5 , ((_standby_time << 5) | (_filter_coef << 2))); // write standby time & filter coef
|
||||
writeRegister(0xF2, _hum_oversampl); // write hum oversampling value
|
||||
writeRegister(0xF2, readRegister(0xF2)); // rewrite hum oversampling register
|
||||
writeRegister(0xF4, ((_temp_oversampl << 5) | (_press_oversampl << 2) | _operating_mode)); // write temp & press oversampling value , normal mode
|
||||
writeRegister(0xF5, ((_standby_time << 5) | (_filter_coef << 2))); // write standby time & filter coef
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ void GyverBME280::setPressOversampling(uint8_t mode) {
|
||||
/* ============ Reading ============ */
|
||||
|
||||
int32_t GyverBME280::readTempInt(void) {
|
||||
int32_t temp_raw = GyverBME280::readRegister24(0xFA); // Read 24-bit value
|
||||
int32_t temp_raw = readRegister24(0xFA); // Read 24-bit value
|
||||
if (temp_raw == 0x800000) return 0; // If the temperature module has been disabled return '0'
|
||||
|
||||
temp_raw >>= 4; // Start temperature reading in integers
|
||||
@@ -76,18 +80,18 @@ int32_t GyverBME280::readTempInt(void) {
|
||||
|
||||
|
||||
float GyverBME280::readTemperature(void) {
|
||||
int32_t temp_raw = GyverBME280::readTempInt();
|
||||
int32_t temp_raw = readTempInt();
|
||||
float T = (temp_raw * 5 + 128) >> 8;
|
||||
return T / 100; // Return temperature in float
|
||||
return T / 100.0; // Return temperature in float
|
||||
}
|
||||
|
||||
|
||||
float GyverBME280::readPressure(void) {
|
||||
uint32_t press_raw = GyverBME280::readRegister24(0xF7); // Read 24-bit value
|
||||
uint32_t press_raw = readRegister24(0xF7); // Read 24-bit value
|
||||
if (press_raw == 0x800000) return 0; // If the pressure module has been disabled return '0'
|
||||
|
||||
press_raw >>= 4; // Start pressure converting
|
||||
int64_t value_1 = ((int64_t)GyverBME280::readTempInt()) - 128000;
|
||||
int64_t value_1 = ((int64_t)readTempInt()) - 128000;
|
||||
int64_t value_2 = value_1 * value_1 * (int64_t)CalibrationData._P6;
|
||||
value_2 = value_2 + ((value_1 * (int64_t)CalibrationData._P5) << 17);
|
||||
value_2 = value_2 + (((int64_t)CalibrationData._P4) << 35);
|
||||
@@ -107,14 +111,14 @@ float GyverBME280::readPressure(void) {
|
||||
|
||||
|
||||
float GyverBME280::readHumidity(void) {
|
||||
Wire.beginTransmission(_i2c_address); // Start I2C transmission
|
||||
Wire.write(0xFD); // Request humidity data register
|
||||
if(Wire.endTransmission() != 0) return 0;
|
||||
Wire.requestFrom(_i2c_address, 2); // Request humidity data
|
||||
int32_t hum_raw = ((uint16_t)Wire.read() << 8) | (uint16_t)Wire.read(); // Read humidity data
|
||||
_wire->beginTransmission(_i2c_address); // Start I2C transmission
|
||||
_wire->write(0xFD); // Request humidity data register
|
||||
if (_wire->endTransmission() != 0) return 0;
|
||||
_wire->requestFrom(_i2c_address, 2); // Request humidity data
|
||||
int32_t hum_raw = ((uint16_t)_wire->read() << 8) | (uint16_t)_wire->read(); // Read humidity data
|
||||
if (hum_raw == 0x8000) return 0; // If the humidity module has been disabled return '0'
|
||||
|
||||
int32_t value = (GyverBME280::readTempInt() - ((int32_t)76800)); // Start humidity converting
|
||||
int32_t value = (readTempInt() - ((int32_t)76800)); // Start humidity converting
|
||||
value = (((((hum_raw << 14) - (((int32_t)CalibrationData._H4) << 20) -
|
||||
(((int32_t)CalibrationData._H5) * value)) +((int32_t)16384)) >> 15) *
|
||||
(((((((value * ((int32_t)CalibrationData._H6)) >> 10) *(((value *
|
||||
@@ -131,20 +135,18 @@ float GyverBME280::readHumidity(void) {
|
||||
/* ============ Misc ============ */
|
||||
|
||||
bool GyverBME280::isMeasuring(void) {
|
||||
return (bool)((GyverBME280::readRegister(0xF3) & 0x08) >> 3); // Read status register & mask bit "measuring"
|
||||
return (bool)((readRegister(0xF3) & 0x08) >> 3); // Read status register & mask bit "measuring"
|
||||
}
|
||||
|
||||
void GyverBME280::oneMeasurement(void) {
|
||||
GyverBME280::writeRegister(0xF4 , ((GyverBME280::readRegister(0xF4) & 0xFC) | 0x02)); // Set the operating mode to FORCED_MODE
|
||||
writeRegister(0xF4 , ((readRegister(0xF4) & 0xFC) | 0x02)); // Set the operating mode to FORCED_MODE
|
||||
}
|
||||
|
||||
GyverBME280::GyverBME280() {}
|
||||
|
||||
/* ============ Private ============ */
|
||||
|
||||
/* = BME280 software reset = */
|
||||
bool GyverBME280::reset(void) {
|
||||
if(!GyverBME280::writeRegister(0x0E , 0xB6)) return false;
|
||||
if (!writeRegister(0x0E , 0xB6)) return false;
|
||||
delay(10);
|
||||
return true;
|
||||
}
|
||||
@@ -152,66 +154,66 @@ bool GyverBME280::reset(void) {
|
||||
|
||||
/* = Read and combine three BME280 registers = */
|
||||
uint32_t GyverBME280::readRegister24(uint8_t address) {
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(address);
|
||||
if(Wire.endTransmission() != 0) return 0x800000;
|
||||
Wire.requestFrom(_i2c_address, 3);
|
||||
return (((uint32_t)Wire.read() << 16) | ((uint32_t)Wire.read() << 8) | (uint32_t)Wire.read());
|
||||
_wire->beginTransmission(_i2c_address);
|
||||
_wire->write(address);
|
||||
if (_wire->endTransmission() != 0) return 0x800000;
|
||||
_wire->requestFrom(_i2c_address, 3);
|
||||
return (((uint32_t)_wire->read() << 16) | ((uint32_t)_wire->read() << 8) | (uint32_t)_wire->read());
|
||||
}
|
||||
|
||||
|
||||
/* = Write one 8-bit BME280 register = */
|
||||
bool GyverBME280::writeRegister(uint8_t address , uint8_t data) {
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(address);
|
||||
Wire.write(data);
|
||||
if(Wire.endTransmission() != 0) return false;
|
||||
_wire->beginTransmission(_i2c_address);
|
||||
_wire->write(address);
|
||||
_wire->write(data);
|
||||
if (_wire->endTransmission() != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* = Read one 8-bit BME280 register = */
|
||||
uint8_t GyverBME280::readRegister(uint8_t address) {
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(address);
|
||||
if(Wire.endTransmission() != 0) return 0;
|
||||
Wire.requestFrom(_i2c_address , 1);
|
||||
return Wire.read();
|
||||
_wire->beginTransmission(_i2c_address);
|
||||
_wire->write(address);
|
||||
if (_wire->endTransmission() != 0) return 0;
|
||||
_wire->requestFrom(_i2c_address , 1);
|
||||
return _wire->read();
|
||||
}
|
||||
|
||||
/* = Structure to store all calibration values = */
|
||||
void GyverBME280::readCalibrationData(void) {
|
||||
/* first part request*/
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(0x88);
|
||||
if(Wire.endTransmission() != 0) return;
|
||||
Wire.requestFrom(_i2c_address , 25);
|
||||
_wire->beginTransmission(_i2c_address);
|
||||
_wire->write(0x88);
|
||||
if (_wire->endTransmission() != 0) return;
|
||||
_wire->requestFrom(_i2c_address , 25);
|
||||
/* reading */
|
||||
CalibrationData._T1 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._T2 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._T3 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P1 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P2 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P3 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P4 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P5 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P6 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P7 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P8 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._P9 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._H1 = Wire.read();
|
||||
CalibrationData._T1 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._T2 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._T3 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P1 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P2 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P3 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P4 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P5 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P6 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P7 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P8 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._P9 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._H1 = _wire->read();
|
||||
|
||||
/* second part request*/
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(0xE1);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(_i2c_address , 8);
|
||||
_wire->beginTransmission(_i2c_address);
|
||||
_wire->write(0xE1);
|
||||
_wire->endTransmission();
|
||||
_wire->requestFrom(_i2c_address , 8);
|
||||
/* reading */
|
||||
CalibrationData._H2 = (Wire.read() | (Wire.read() << 8));
|
||||
CalibrationData._H3 = Wire.read();
|
||||
CalibrationData._H4 = (Wire.read() << 4);
|
||||
uint8_t interVal = Wire.read();
|
||||
CalibrationData._H2 = (_wire->read() | (_wire->read() << 8));
|
||||
CalibrationData._H3 = _wire->read();
|
||||
CalibrationData._H4 = (_wire->read() << 4);
|
||||
uint8_t interVal = _wire->read();
|
||||
CalibrationData._H4 |= (interVal & 0xF);
|
||||
CalibrationData._H5 = (((interVal & 0xF0) >> 4) | (Wire.read() << 4));
|
||||
CalibrationData._H6 = Wire.read();
|
||||
CalibrationData._H5 = (((interVal & 0xF0) >> 4) | (_wire->read() << 4));
|
||||
CalibrationData._H6 = _wire->read();
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
Версии:
|
||||
v1.3 - исправлена ошибка при отриц. температуре
|
||||
v1.4 - разбил на h и cpp
|
||||
v1.5 - добавлена поддержка BMP280s
|
||||
*/
|
||||
|
||||
#ifndef GyverBME280_h
|
||||
@@ -49,8 +50,8 @@
|
||||
class GyverBME280 {
|
||||
|
||||
public:
|
||||
GyverBME280(); // Create an object of class BME280
|
||||
bool begin(void); // Initialize sensor with standart 0x76 address
|
||||
GyverBME280(TwoWire &wire); // Create an object of class BME280
|
||||
bool begin(); // Initialize sensor with standart 0x76 address
|
||||
bool begin(uint8_t address); // Initialize sensor with not standart 0x76 address
|
||||
bool isMeasuring(void); // Returns 'true' while the measurement is in progress
|
||||
float readPressure(void); // Read and calculate atmospheric pressure [float , Pa]
|
||||
@@ -67,6 +68,7 @@ public:
|
||||
private:
|
||||
|
||||
//============================== DEFAULT SETTINGS ========================================|
|
||||
TwoWire *_wire = nullptr;
|
||||
int _i2c_address = 0x76; // BME280 address on I2C bus |
|
||||
uint8_t _operating_mode = NORMAL_MODE; // Sensor operation mode |
|
||||
uint8_t _standby_time = STANDBY_250MS; // Time between measurements in NORMAL_MODE |
|
||||
@@ -103,7 +105,6 @@ private:
|
||||
int16_t _H5;
|
||||
int8_t _H6;
|
||||
} CalibrationData;
|
||||
|
||||
};
|
||||
|
||||
float pressureToMmHg(float pressure); // Convert [Pa] to [mm Hg]
|
||||
|
||||
Reference in New Issue
Block a user