MWX Library
latest_en
latest_en
  • The MWX Library
  • revision history
  • About the MWX library
    • License
    • Terms
    • The design policy
  • Install and Build
    • Environment (OS, etc.)
    • Installing the TWELITE SDK
    • Building ACT
    • Creating a new project
    • Installing VSCode
    • Build definition Makefile
    • Other platforms
  • Sample ACTs
    • act0 .. 4
    • Scratch
    • Slp_Wk_and_Tx
    • Parent_MONOSTICK
    • PingPong
    • BRD_APPTWELITE
    • BRD_I2C_TEMPHUMID
    • PAL_AMB
    • PAL_AMB-usenap
    • PAL_AMB-bhv
    • PAL_MAG
    • PAL_MOT-single
    • PAL_MOT-fifo
    • PulseCounter
    • WirelessUART
    • Rcv_Univsl
    • Unit_???
  • API
    • Definition.
    • class object
      • the_twelite
      • Analogue
      • Buttons
      • EEPROM
      • PulseCounter
      • Serial
      • SerialParser
      • SPI
        • SPI (using member functions)
        • SPI (using helper class)
      • TickTimer
      • Timer0 .. 4
      • Wire
        • Wire (using member functions))
        • Wire (using helper class)
    • Classes
      • MWX_APIRET
      • alloc
      • axis_xyzt
      • packet_rx
      • packet_tx
      • serparser
      • pktparser
        • E_PKT
        • idenify_packet_type()
        • TwePacket
          • TwePacketTwelite
          • TwePacketIO
          • TwePacketUART
          • TwePacketPAL
      • smplbuf
        • .get_stream_helper()
        • smplbuf_strm_u8
      • smplque
      • mwx::stream
        • format (mwx::mwx_format)
        • mwx::bigendian
        • mwx::crlf
        • mwx::flush
        • stream_helper
      • SM_SIMPLE state machine
    • Call back functions
      • setup()
      • begin()
      • loop()
      • wakeup()
      • init_coldboot()
      • init_warmboot()
      • on_rx_packet()
      • on_tx_comp()
    • BEHAVIOR
      • PAL_AMB-behavior
    • Functions
      • System Functions
        • millis()
        • delay()
        • delayMicroseconds()
        • random()
      • DIO General purpose IO
        • pinMode()
        • digitalWrite()
        • digitalRead()
        • attachIntDio()
        • detachIntDio()
        • digitalReadBitmap()
      • Utility Functions
        • Printf utils
        • pack_bits()
        • collect_bits()
        • Byte array utils
        • pack_bytes()
        • expand_bytes()
        • CRC8, XOR, LRC
        • div100()
        • Scale utils
        • pnew
    • External Libraries
      • EASTL
  • Board (BRD)
    • <BRD_APPTWELITE>
    • <MONOSTICK>
    • PAL
      • <PAL_AMB>
      • <PAL_MAG>
      • <PAL_MOT>
      • <PAL_NOTICE>
    • <CUE>
  • Sensor Devices (SNS)
    • SHTC3 - Temp/Humd sensor
    • SHT3x - Temp/Humd sensor
    • LTR-308ALS - Luminance Sensor
    • MC3630 - Accel sensor
    • BMx280 - Temp/Humd/Pressure Sensor
    • PCA9632 - LED Driver
  • Network (NWK)
    • Simple Relay Net <NWK_SIMPLE>
    • Layered Tree Net <NWK_LAYERED>
  • Settings (STG) - Interactive settings mode
    • <STG_STD>
GitBook提供
このページ内
  • Process flow
  • Procedures required for operation
  • Wire bus
  • Procedures when returning from sleep mode
  • Code Example
  • Methods
  • get_press()
  • get_temp(), get_temp_cent()
  • get_humid(), get_humid_per_dmil()
  • Common methods
  • setup()
  • begin(), end()
  • process_ev()
  • available()
  • probe()
  • sns_stat()
  • sns_opt()
PDFとしてエクスポート
  1. Sensor Devices (SNS)

BMx280 - Temp/Humd/Pressure Sensor

BMx280 - Environmental Sensors

前へMC3630 - Accel sensor次へPCA9632 - LED Driver

最終更新 2 年前

Barometric pressure, temperature, and humidity (BME280 only) sensor using I2C bus.

This sensor is not used in the TWELITE PAL series. Please refer to the following for usage examples.

Process flow

1 Wire.begin(): Initialize bus 2 .setup(): Initialize the sensor 3..begin(): Start operation of the sensor 4. 4.wait(): wait for a few ms 5..available()becomestrue 6. .get_press(), .get_temp(), .get_humid(): read values

Procedures required for operation

Wire bus

Before calling the setup() method, the Wire must be put into operation by Wire.begin().

Procedures when returning from sleep mode

Keep the Wire bus in the operating state just before sleep (the Wire is automatically restored after sleep).

Code Example

#include <TWELITE>
#include <SNS_BME280>

SNS_BME280 sns_bme280; // Declaration of Objects

#include <SNS_SHT3X> and declaration of SNS_SHT3X class object is required.

initialization

void setup() {
    Wire.begin();
    sns_bme280.setup();
}

Start acquiring sensor values

void loop() {

  if(eState == E_STATE::INIT) {
    sns_bme280.begin();
    eState = E_STATE::CAPTURE;
  }

}

Call .begin() to start acquiring sensor values. It takes several ms to complete.

センサー値の取得待ち

void loop() {

  if(eState == E_STATE::CAPTURE) {
    if (sns_bme280.available()) {
      // Sensor value readout available
    }
  }

}

Whether the sensor value is ready or not can be determined by .available().

Readout of sensor values

void loop() {

  if(eState == E_STATE::CAPTURE) {
    if (sns_bme280.available()) {
      Serial << crlf << "BMx280:"
            << " P=" << int(sns_bme280.get_press()) << "hP";
            << " T=" << sns_bme280.get_temp() << 'C'
						<< " H=" << sns_bme280.get_humid() << '%';
    }
  }

}

As soon as the sensor value is ready, the value can be read out.

.get_temp(), get_humid() includes floating point operations; you can also get 100x integer values.

auto temp = div100(sns_bme280.get_temp_cent());
auto humd = div100(sns_bme280.get_humid_per_dmil);

Serial << crlf << "BMx280:"
  << " P=" << int(sns_bme280.get_press()) << "hP";
  << format(" T=%c%d.%02d", temp.neg ? '-' : ' ', temp.quo, temp.rem)
  << format(" T=%c%d.%02d", humd.neg ? '-' : ' ', humd.quo, humd.rem);

Methods

get_press()

int16_t get_press()

Reads the atmospheric pressure. The unit is the hectopascal (hectopascal), usually around 1000.

get_temp(), get_temp_cent()

double get_temp()
int16_t get_temp_cent()

Read temperature. get_temp() returns a value in °C and get_temp_cent() returns an integer value that is 100 times the value in °C.

On error, values between -32760 and -32768 are returned.

get_humid(), get_humid_per_dmil()

double get_humid()
int16_t get_humid_per_dmil()

Reads the humidity. get_humid() returns an integer value in % and get_humid_per_dmil() returns 100 times %.

On error, values between -32760 and -32768 are returned.

Common methods

setup()

void setup(uint32_t arg1 = 0UL) 

Allocates and initializes the memory area for the sensor.

The 8 bits from LSB of arg1 can store the I2C address. If not specified, leave it as 0.

#include <SNS_BME280>
SNS_BME280 sns_bme280;
bool b_found_bme280 = false;

void setup() {
  ...
  sns_bme280.setup();
	if (!sns_bme280.probe()) {
			delayMicroseconds(100); // device needs small time for further I2C comm.
			sns_bme280.setup(0x77); // alternative ID
			if (sns_bme280.probe()) b_found_bme280 = true;
	} else {
			b_found_bme280 = true;
	}
	...

The above code first tries to see if the device responds with the default I2C ID, and if not, tries with 0x77.

begin(), end()

void begin()
void end()

Starts acquiring a sensor. It takes a few ms to read the value of the sensor and must wait until available() is true.

It does not support end().

process_ev()

void process_ev(uint32_t arg1, uint32_t arg2 = 0)

In the case of a sensor with wait processing, arg1 is given E_EVENT_TICK_TIMER or E_EVENT_START_UP to indicate the elapse of time. After calling this method, if the required time has elapsed, available() will be set to true and the sensor value can be read.

available()

bool available()

Returns true when the sensor satisfies the readout condition.

probe()

bool probe()

Returns true when the sensor is connected.

sns_stat()

uint32_t sns_stat()

Various information on the sensor device is stored.

  • The lower 8 bits store the chip model of BME280/BMP280. If it is 0x60, it is BME280, and if it is 0x58, it is BMP280.

sns_opt()

uint32_t& sns_opt()

The value passed in setup(uint32_t arg1) is stored.

  • The lower 8 bits contain the address of the specified I2C device.

In the above loop(), the process is designed to branch according to the state variable eState. ()

Here is used to decompose 100x values into integer and decimal parts.

https://github.com/monowireless/ActEx_Sns_BME280_SHT30
Reference
div100()