Skip to content

Commit

Permalink
Added HDC1000 thermometer and hydrometer and BMP280 thermometer and b…
Browse files Browse the repository at this point in the history
…arometer of the SensorTag CC1350
  • Loading branch information
Rei Vilo committed Oct 14, 2018
1 parent 8a71afc commit d8f6591
Show file tree
Hide file tree
Showing 17 changed files with 864 additions and 160 deletions.
48 changes: 27 additions & 21 deletions examples/WeatherSensors_demo/WeatherSensors_demo.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
///
/// @mainpage WeatherSensors
///
/// @details Description of the project
/// @details Library for the Weather Sensors of the Sensors BoosterPack and the CC1350 SensorTag
/// @n
/// @n
/// @n @a Developed with [embedXcode+](http://embedXcode.weebly.com)
///
/// @author Rei Vilo
/// @author http://embeddedcomputing.weebly.com
/// @date nov. 12, 2016 19:37
/// @version <#version#>
/// @date 12 Nov 2016
/// @version 103
///
/// @copyright (c) Rei Vilo, 2016
/// @copyright GNU General Public Licence
/// @copyright (c) Rei Vilo, 2016-2018
/// @copyright CC = BY SA NC
///
/// @see ReadMe.txt for references
///
Expand All @@ -22,16 +22,16 @@
/// @file WeatherSensors.ino
/// @brief Main sketch
///
/// @details <#details#>
/// @details Example for climate sensors
/// @n @a Developed with [embedXcode+](http://embedXcode.weebly.com)
///
/// @author Rei Vilo
/// @author http://embeddedcomputing.weebly.com
/// @date nov. 12, 2016 19:37
/// @version <#version#>
/// @date 12 Nov 2016
/// @version 102
///
/// @copyright (c) Rei Vilo, 2016
/// @copyright GNU General Public Licence
/// @copyright (c) Rei Vilo, 2016-2018
/// @copyright CC = BY SA NC
///
/// @see ReadMe.txt for references
/// @n
Expand All @@ -46,7 +46,7 @@
#endif // end IDE

// Set parameters
#define USE_TMP007 0
#define USE_TMP007 1
#define USE_OPT3001 1
#define USE_BME280 1

Expand All @@ -59,7 +59,7 @@
#if (USE_TMP007 == 1)
#include "Sensor_TMP007.h"
Sensor_TMP007 myTMP007;
float TMP007_internalTemperature, TMP007_externalTemperature;
float TMP007_internal, TMP007_external;
#endif

#if (USE_OPT3001 == 1)
Expand All @@ -82,6 +82,9 @@ const uint32_t period_ms = 10000;
void setup()
{
Serial.begin(9600);

Serial.println("Wire.begin");
// Wire.setModule(1);
Wire.begin();

#if (USE_TMP007 == 1)
Expand All @@ -95,7 +98,9 @@ void setup()
#endif

#if (USE_BME280 == 1)
Serial.println("myBME280.begin");
myBME280.begin();
Serial.println("myBME280.get");
myBME280.get();
#endif
}
Expand All @@ -105,15 +110,15 @@ void loop()
{
#if (USE_TMP007 == 1)
myTMP007.get();
TMP007_internalTemperature = conversion(myTMP007.internalTemperature(), KELVIN, CELSIUS);
TMP007_externalTemperature = conversion(myTMP007.externalTemperature(), KELVIN, CELSIUS));
Serial.print("TMP007_internalTemperature ");
Serial.print(TMP007_internalTemperature);
Serial.println(CELSIUS.symbol)

Serial.print("TMP007_externalTemperature ");
Serial.print(TMP007_externalTemperature);
Serial.println(CELSIUS.symbol)
TMP007_internal = conversion(myTMP007.internal(), KELVIN, CELSIUS);
TMP007_external = conversion(myTMP007.external(), KELVIN, CELSIUS);
Serial.print("TMP007_internal ");
Serial.print(TMP007_internal);
Serial.println(CELSIUS.symbol);

Serial.print("TMP007_external ");
Serial.print(TMP007_external);
Serial.println(CELSIUS.symbol);
#endif

#if (USE_OPT3001 == 1)
Expand All @@ -125,6 +130,7 @@ void loop()
#endif

#if (USE_BME280 == 1)
Serial.println("myBME280.get");
myBME280.get();
BME280_pressure = myBME280.pressure();
BME280_temperature = conversion(myBME280.temperature(), KELVIN, CELSIUS);
Expand Down
Binary file modified extra/WeatherSensors - Reference Manual.pdf
Binary file not shown.
12 changes: 6 additions & 6 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Weather Sensors BoosterPack Library
version=1.0.2
name=Weather Sensors BoosterPack and CC1350 SensorTag Library
version=1.0.4
author=Rei Vilo
maintainer=Rei Vilo
sentence=Library for the weather sensors of the Sensors BoosterPack
paragraph=The Weather Sensors Library supports the TMP007 infra-red thermometer, OPT3001 light sensor and BME280 thermometer, barometer and hydrometer of the Sensors BoosterPack.
sentence=Library for the weather sensors of the Sensors BoosterPack and the CC1350 SensorTag
paragraph=The Weather Sensors Library supports the TMP007 infra-red thermometer, OPT3001 light sensor and BME280 thermometer, barometer and hydrometer of the Sensors BoosterPack, as well as the HDC1000 thermometer and hydrometer and BMP280 thermometer and barometer of the SensorTag CC1350.
category=Sensors
url=http://embeddedcomputing.weebly.com/sensors-boosterpack.html
architectures=cc3200,cc3200emt,msp432,tivac,msp430
url=http://embeddedcomputing.weebly.com/sensors-boosterpack.html,https://embeddedcomputing.weebly.com/sensortag-cc1350.html
architectures=cc13xx,cc3200,cc3220emt,msp430,msp432,msp432e,msp432r,tivac
96 changes: 54 additions & 42 deletions src/Sensor_BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
//
// Project SensorsBoosterPack
//
// Created by Rei Vilo, 20/08/2015 13:43
// Created by Rei Vilo, 20 Aug 2015
// http://embeddedcomputing.weebly.com
//
// Copyright (c) Rei Vilo, 2015-2016
// Copyright (c) Rei VILO, 2015-2018
// Licence CC = BY SA NC
//
// See Sensor_BME280.h and ReadMe.txt for references
Expand All @@ -19,16 +19,16 @@


// 0xF7 to 0xFE
#define BME280_SLAVE_ADDRESS 0x77
#define BME280_SLAVE_ADDRESS 0x77

#define BME280_DATA_F7_FE 0xf7
#define BME280_CONTROL_TEMPERATURE_PRESSURE 0xf4
#define BME280_CONTROL_HUMIDITY 0xf2
#define BME280_DATA_F7_FE 0xf7
#define BME280_CONTROL_TEMPERATURE_PRESSURE 0xf4
#define BME280_CONTROL_HUMIDITY 0xf2
#define BME280_STATUS 0xf3
#define BME280_CONFIGURATION 0xf5
#define BME280_RESET 0xe0

#define BME280_VALUE_RESET_EXECUTE 0xb6
#define BME280_VALUE_RESET_EXECUTE 0xb6

#define BME280_CALIBRATION_T1 0x88
#define BME280_CALIBRATION_T2 0x8a
Expand All @@ -42,23 +42,23 @@
#define BME280_CALIBRATION_P7 0x9a
#define BME280_CALIBRATION_P8 0x9c
#define BME280_CALIBRATION_P9 0x9e
#define BME280_calibrationH1 0xa1
#define BME280_calibrationH1 0xa1

#define BME280_calibrationH2 0xe1
#define BME280_calibrationH3 0xe3
#define BME280_calibrationH4 0xe4
#define BME280_calibrationH5 0xe5
#define BME280_calibrationH6 0xe7
#define BME280_calibrationH2 0xe1
#define BME280_calibrationH3 0xe3
#define BME280_calibrationH4 0xe4
#define BME280_calibrationH5 0xe5
#define BME280_calibrationH6 0xe7

// Library header
#include "Sensor_BME280.h"
#include "Wire_Utilities.h"

// Code

Sensor_BME280::Sensor_BME280()
Sensor_BME280::Sensor_BME280(uint8_t address)
{

_slaveAddressBME280 = address;
}

String Sensor_BME280::WhoAmI()
Expand All @@ -68,10 +68,17 @@ String Sensor_BME280::WhoAmI()

void Sensor_BME280::begin()
{
writeRegister8(BME280_SLAVE_ADDRESS, BME280_RESET, BME280_VALUE_RESET_EXECUTE);
writeRegister8(_slaveAddressBME280, BME280_RESET, BME280_VALUE_RESET_EXECUTE);
delay(100);
writeRegister8(BME280_SLAVE_ADDRESS, BME280_CONTROL_TEMPERATURE_PRESSURE, 0x3f);
writeRegister8(BME280_SLAVE_ADDRESS, BME280_CONTROL_HUMIDITY, 0x03);
writeRegister8(_slaveAddressBME280, BME280_CONTROL_TEMPERATURE_PRESSURE, 0x25);
// 001.001.01 Default = 0x00
// 001.___.__ Pressure oversampling x1
// ___.001.__ Temperature oversampling x1
// ___.___.01 Mode = forced mode

writeRegister8(_slaveAddressBME280, BME280_CONTROL_HUMIDITY, 0x01);
/// xxxxx.011 Default = 0x00
/// _____.001 Humidity oversampling x1

// Register Address Register content Data type
// 0x88 / 0x89 dig_T1 [7:0] / [15:8] unsigned short = uint16_t
Expand All @@ -93,30 +100,30 @@ void Sensor_BME280::begin()
// 0xE5[7:4] / 0xE6 dig_H5 [3:0] / [11:4] signed short = int16_t
// 0xE7 dig_H6 signed char = int8_t

_calibrationT1 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_T1, LSBFIRST); // uint16_t
_calibrationT2 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_T2, LSBFIRST); // int16_t
_calibrationT3 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_T3, LSBFIRST); // int16_t
_calibrationT1 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_T1, LSBFIRST); // uint16_t
_calibrationT2 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_T2, LSBFIRST); // int16_t
_calibrationT3 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_T3, LSBFIRST); // int16_t

_calibrationP1 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P1, LSBFIRST); // uint16_t
_calibrationP2 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P2, LSBFIRST); // int16_t
_calibrationP3 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P3, LSBFIRST); // int16_t
_calibrationP4 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P4, LSBFIRST); // int16_t
_calibrationP5 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P5, LSBFIRST); // int16_t
_calibrationP6 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P6, LSBFIRST); // int16_t
_calibrationP7 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P7, LSBFIRST); // int16_t
_calibrationP8 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P8, LSBFIRST); // int16_t
_calibrationP9 = readRegister16(BME280_SLAVE_ADDRESS, BME280_CALIBRATION_P9, LSBFIRST); // int16_t
_calibrationP1 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P1, LSBFIRST); // uint16_t
_calibrationP2 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P2, LSBFIRST); // int16_t
_calibrationP3 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P3, LSBFIRST); // int16_t
_calibrationP4 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P4, LSBFIRST); // int16_t
_calibrationP5 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P5, LSBFIRST); // int16_t
_calibrationP6 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P6, LSBFIRST); // int16_t
_calibrationP7 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P7, LSBFIRST); // int16_t
_calibrationP8 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P8, LSBFIRST); // int16_t
_calibrationP9 = readRegister16(_slaveAddressBME280, BME280_CALIBRATION_P9, LSBFIRST); // int16_t

_calibrationH1 = readRegister8(BME280_SLAVE_ADDRESS, BME280_calibrationH1); // uint8_t
_calibrationH2 = readRegister16(BME280_SLAVE_ADDRESS, BME280_calibrationH2, LSBFIRST); // int16_t
_calibrationH3 = readRegister8(BME280_SLAVE_ADDRESS, BME280_calibrationH3); // uint8_t
_calibrationH1 = readRegister8(_slaveAddressBME280, BME280_calibrationH1); // uint8_t
_calibrationH2 = readRegister16(_slaveAddressBME280, BME280_calibrationH2, LSBFIRST); // int16_t
_calibrationH3 = readRegister8(_slaveAddressBME280, BME280_calibrationH3); // uint8_t

// 0xE4 / 0xE5[3:0] dig_H4 [11:4] / [3:0] signed short = int16_t
_calibrationH4 = (readRegister8(BME280_SLAVE_ADDRESS, 0xe4) << 4) + (readRegister8(BME280_SLAVE_ADDRESS, 0xe5) & 0x0f);
_calibrationH4 = (readRegister8(_slaveAddressBME280, 0xe4) << 4) + (readRegister8(_slaveAddressBME280, 0xe5) & 0x0f);
// 0xE5[7:4] / 0xE6 dig_H5 [3:0] / [11:4] signed short = int16_t
_calibrationH5 = (readRegister8(BME280_SLAVE_ADDRESS, 0xe5) >> 4) + (readRegister8(BME280_SLAVE_ADDRESS, 0xe6) << 4);
_calibrationH5 = (readRegister8(_slaveAddressBME280, 0xe5) >> 4) + (readRegister8(_slaveAddressBME280, 0xe6) << 4);

_calibrationH6 = readRegister8(BME280_SLAVE_ADDRESS, BME280_calibrationH6); // int8_t
_calibrationH6 = readRegister8(_slaveAddressBME280, BME280_calibrationH6); // int8_t

/*
QuickDebugln("calibration T1 ui16: %i", _calibrationT1);
Expand Down Expand Up @@ -152,14 +159,14 @@ uint8_t Sensor_BME280::get()
int32_t _rawPressure, _rawTemperature, _rawHumidity;
int32_t t_fine;

// while (readRegister8(BME280_SLAVE_ADDRESS, BME280_STATUS) & 0x08);
// while (readRegister8(_slaveAddressBME280, BME280_STATUS) & 0x08);

Wire.beginTransmission(BME280_SLAVE_ADDRESS);
Wire.beginTransmission(_slaveAddressBME280);
Wire.write(BME280_DATA_F7_FE);
Wire.endTransmission();

// uint8_t data[8];
// Wire.requestFrom(BME280_SLAVE_ADDRESS, 8);
// Wire.requestFrom(_slaveAddressBME280, 8);
// while (Wire.available() < 8);
// for (uint8_t i=0; i<8; i++) {
// data[i] = Wire.read();
Expand All @@ -169,7 +176,7 @@ uint8_t Sensor_BME280::get()
// _rawTemperature = ((uint32_t)data[3] << 12) + ((uint32_t)data[4] << 4) + ((uint32_t)data[5]>> 4); // fa.fb.fc
// _rawHumidity = ((uint32_t)data[6] << 8) + ((uint32_t)data[7]); // fd.fe

Wire.requestFrom(BME280_SLAVE_ADDRESS, 8);
Wire.requestFrom(_slaveAddressBME280, 8);
while (Wire.available() < 8);
_rawPressure = ((uint32_t)Wire.read() << 12) + ((uint32_t)Wire.read() << 4) + ((uint32_t)Wire.read() >> 4); // f7.f8.f9
_rawTemperature = ((uint32_t)Wire.read() << 12) + ((uint32_t)Wire.read() << 4) + ((uint32_t)Wire.read() >> 4); // fa.fb.fc
Expand Down Expand Up @@ -348,7 +355,12 @@ float Sensor_BME280::pressure()

void Sensor_BME280::setPowerMode(uint8_t mode)
{

uint8_t configuration = readRegister8(_slaveAddressBME280, BME280_CONTROL_TEMPERATURE_PRESSURE);

configuration &= 0b11111100;
configuration |= mode;

writeRegister8(_slaveAddressBME280, BME280_CONTROL_TEMPERATURE_PRESSURE, configuration);
}

float Sensor_BME280::absolutePressure(float altitudeMeters)
Expand All @@ -369,7 +381,7 @@ float Sensor_BME280::altitude(float referencePressure, float referenceAltitude)
// Sea level pressure
float seaLevelPressure = referencePressure / pow(1 - referenceAltitude / 44330.77, 5.255876);
// Altitude based on absolute pressure
return 44330.0 * (1.0 - pow(_pressure / seaLevelPressure, 0.1903));
return 44330.0 * (1.0 - pow(_pressure / seaLevelPressure, 0.190263));
}


Expand Down
23 changes: 18 additions & 5 deletions src/Sensor_BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
/// @author Rei Vilo
/// @author http://embeddedcomputing.weebly.com
///
/// @date 20/08/2015 13:43
/// @date 20 Aug 2017
/// @version 102
///
/// @copyright (c) Rei Vilo, 2015-2016
/// @copyright (c) Rei Vilo, 2015-2018
/// @copyright CC = BY SA NC
///
/// @see ReadMe.txt for references
Expand Down Expand Up @@ -57,25 +57,36 @@
///
/// @brief Release
///
#define Sensor_BME280_RELEASE 102
#define Sensor_BME280_RELEASE 103

#define BM280_SUCCESS 0 ///< success
#define BM280_ERROR 1 ///< error

#include "Wire.h"

///
/// @brief Default BME280 I2C address
///
#define BME280_SLAVE_ADDRESS 0x77

#define BME280_FORCED_MODE 0b01
#define BME280_SLEEP_MODE 0b00
#define BME280_NORMAL_MODE 0b11


///
/// @brief Class for sensor BME280
/// @details Combined humidity and pressure sensor
/// @details Combined temperature, humidity and pressure sensor
/// @see http://www.bosch-sensortec.com/de/homepage/products_3/environmental_sensors_1/bme280/bme280_1
///
class Sensor_BME280
{
public:
///
/// @brief Constructor
/// @param address default = BME280_SLAVE_ADDRESS
///
Sensor_BME280();
Sensor_BME280(uint8_t address = BME280_SLAVE_ADDRESS);

///
/// @brief Initialisation
Expand Down Expand Up @@ -184,6 +195,8 @@ class Sensor_BME280
int16_t _calibrationH4;
int16_t _calibrationH5;
int8_t _calibrationH6;

uint8_t _slaveAddressBME280;
};

#endif
Loading

0 comments on commit d8f6591

Please sign in to comment.