/      日本語

Sensor Devices (SNS)

Standardized procedures for sensors and various devices
Provides classes that standardize procedures for sensors and various devices.

Procedures for Handling Sensors

For sensors like temperature sensors, procedures such as sensor activation → waiting time → value reading are often common.

Make sure to call Wire.begin() before using I2C sensors. After waking from sleep, reinitialization of Wire is done automatically, so no special code is required (Note: if Wire.end() is explicitly called in user code, reinitialization must be described in wakeup()).

void setup() {
  auto&& brd = the_twelite.board.use<PAL_AMB>();
  ..
  Wire.begin();
  brd.sns_SHTC3.begin();
  brd.sns_LTR308ALS.begin();
}

Procedures after starting the reading differ by sensor type. For example, both sensors in <PAL_AMB> manage elapsed time. To notify the sensor object of the elapsed time, use the process_ev() method.

void loop() {
  auto&& brd = the_twelite.board.use<PAL_AMB>();

  // mostly process every ms.
  if (TickTimer.available()) {
    // wait until sensor capture finish
    if (!brd.sns_LTR308ALS.available()) {
      brd.sns_LTR308ALS.process_ev(E_EVENT_TICK_TIMER);
    }

    if (!brd.sns_SHTC3.available()) {
      brd.sns_SHTC3.process_ev(E_EVENT_TICK_TIMER);
    }
..

In the above example, TickTimer triggers every 1 ms to notify the elapsed time. E_EVENT_TICK_TIMER conveys the 1 ms passage to the sensor object.

When sufficient time has passed due to wake-up from sleep, use E_EVENT_START_UP instead. The sensor object will then quickly become ready for reading.

Common Sensor Methods

setup()

void setup(uint32_t arg1 = 0, uint32_t arg2 = 0)

Initializes the sensor.

begin(), end()

void begin(uint32_t arg1 = 0, uint32_t arg2 = 0)
void end()

Starts or stops sensor acquisition.

process_ev()

void process_ev(uint32_t arg1, uint32_t arg2 = 0)

For sensors that require a wait period, pass E_EVENT_TICK_TIMER or E_EVENT_START_UP to arg1 to notify time progress. If sufficient time has passed after this call, available will become true, and sensor values can be read.

available()

bool available()

Returns true when the sensor is ready for reading.

probe()

bool probe()

(Only for supported sensors) Returns true when the sensor is connected.


SHTC3

Temperature and Humidity Sensor

SHT3x

Temperature and Humidity Sensor

LTR-308ALS

Illuminance sensor

MC3630

Accelerometer

BMx280

Environmental sensor

PCA9632

LED Driver

SHT4x

Temperature and Humidity Sensor