Sensor behaviors
We have classes that formalize procedures for sensors and various devices.
When using TWELITE PAL equipped sensors and devices, please also refer to the description in board(BRD). /TWELITE PAL specific procedures may be required and are included in the board definition.
Some procedures, such as temperature sensors, are common, such as starting sensor operation, waiting time, and reading the sensor value.
Please perform Wire.begin()
before handling I2C sensors. After returning from sleep, reinitialization of Wire is performed automatically, so no special description is necessary (Note: If Wire.end()
is explicitly called from the user code, reinitialization is described in wakeup()
).
The procedure after the start of the readout depends on the type of sensor, for example, both sensors of <PAL_AMB>
manage the elapsed time. For example, the <PAL_AMB>
sensor uses the process_ev()
method to tell the sensor object how much time has elapsed.
In the above example, a TickTimer is used as a starting point every 1 ms to tell the passage of time. The E_EVENT_TICK_TIMER
tells the sensor object that 1ms has passed.
When enough time has elapsed, for example to return from sleep, E_EVENT_START_UP
is passed instead. The sensor object will be processed as ready to read immediately.
Neither of these processes is guaranteed to match the passage of time in the real world. If the actual elapsed time is insufficient, the sensor will return an error or an unexpected value.
Initialize the sensor.
Start and end sensor acquisition.
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, it will be available and the sensor value can be read.
Returns true
when the sensor satisfies the readout condition.
(Only supported sensors) Returns true
when the sensor is connected.
Initial communication immediately after probe()
may fail.
SHTC3 - Temperature and humidity sensor
This is a temperature/humidity sensor using I2C bus.
Available only when board BEHAVIOR <PAL_AMB>
is loaded. Procedures of common methods except begin()
are executed in board BEHAVIOR.
Wire.begin()
: initialize bus 2..begin()
: Start sensor operation 3.
wait a few ms
.available()
becomes true 5.
.get_temp(), .get_humid()`: read values
Before calling begin()
method, Wire is put into operation by Wire.begin()
.
Keep the Wire bus in operation just before sleep (the Wire is automatically restored after returning from sleep).
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.
Reads the humidity. get_humid()
returns an integer value in % and get_humid_per_dmil()
returns an integer value in % times 100.
On error, values between -32760 and -32768 are returned.
Allocates and initializes memory space for the sensor.
Starts acquiring a sensor. Wait about 5 ms before reading the sensor value.
Does not support end()
.
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, it will be available and the sensor value can be read.
Returns true
when the sensor satisfies the readout condition.
Returns true
when the sensor is connected.
LTR-308ALS - Illuminance sensor
Illuminance sensor using I2C bus.
Available only when the board BEHAVIOR <PAL_AMB>
is loaded. Procedures of common methods except begin()
are executed in board BEHAVIOR.
Wire.begin()
: initialize bus 2..begin()
: Start sensor operation 3.
wait 50ms
.available()
becomes `true
.get_luminance()
: read value
Before calling .begin()
method, Wire should be put into operation by Wire.begin()
.
Keep the Wire bus in operation just before sleep (the Wire is automatically restored after returning from sleep).
Returns an integer value of the illuminance [lx]
.
Returns -1
on error.
Allocates and initializes a memory area for the sensor.
Starts acquiring a sensor. Wait about 50ms before reading the sensor value.
Does not support end()
.
In the case of a sensor with a waiting process, give arg1
E_EVENT_TICK_TIMER
or E_EVENT_START_UP
to signal the passage of time. If the required time has elapsed after calling this method, it becomes available and the sensor value can be read.
Returns true
when the sensor satisfies the read condition.
Return true
when the sensor is connected.
SHT3x - Temperature and humidity sensor
Temperature/humidity sensor using I2C bus.
This sensor is not used in the TWELITE PAL series. See below for usage examples. %{% hint="info https://github.com/monowireless/ActEx_Sns_BME280_SHT30
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()becomes
true 6. .get_temp(), .get_humid()
: read values
Before calling setup()
method, Wire is put into operation by Wire.begin()
.
Keep the Wire bus in the operating state just before sleep (the Wire is automatically restored after sleep).
#include <SNS_SHT3X>
and declaration of SNS_SHT3X
class object is required.
Call .begin()
to start acquiring sensor values. It takes several ms to complete.
In the above loop()
, the process is designed to branch according to the state variable "eState". (Reference)
Whether the sensor value is ready or not can be determined by .available()
.
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.
Here div100()
is used to decompose 100x values into integer and decimal parts.
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.
Reads the humidity. get_humid()
returns a value in %, and get_humid_per_dmil()
returns an integer value of 100 times %.
On error, values between -32760
and -32768
are returned.
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.
In the above example, we first try to initialize with the default I2C ID, and if there is no response, we try to initialize with an address of 0x45
.
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()
.
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.
Returns true
when the sensor satisfies the readout condition.
Returns true
when the sensor is connected.
Various information of the sensor device is stored.
Stored values are undefined for this device.
The value passed in setup(uint32_t arg1)
is stored.
The lower 8 bits contain the address of the specified I2C device.
BMx280 - Environmental Sensors
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. https://github.com/monowireless/ActEx_Sns_BME280_SHT30
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()becomes
true 6. .get_press(), .get_temp(), .get_humid()
: read values
Before calling the setup()
method, the Wire must be put into operation by Wire.begin()
.
Keep the Wire bus in the operating state just before sleep (the Wire is automatically restored after sleep).
#include <SNS_SHT3X>
and declaration of SNS_SHT3X
class object is required.
Call .begin()
to start acquiring sensor values. It takes several ms to complete.
In the above loop()
, the process is designed to branch according to the state variable eState
. (Reference)
Whether the sensor value is ready or not can be determined by .available()
.
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.
Here div100()
is used to decompose 100x values into integer and decimal parts.
Reads the atmospheric pressure. The unit is the hectopascal (hectopascal), usually around 1000.
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.
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.
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.
The above code first tries to see if the device responds with the default I2C ID, and if not, tries with 0x77
.
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()
.
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.
Returns true
when the sensor satisfies the readout condition.
Returns true
when the sensor is connected.
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.
The value passed in setup(uint32_t arg1)
is stored.
The lower 8 bits contain the address of the specified I2C device.
MC3630 - accelerometer
Accelerometer using SPI bus.
Available only when board BEHAVIOR <PAL_MOT>
<PAL_NOTICE>
is loaded. Procedures of common methods except begin(), available()
are executed in board BEHAVIOR.
1..begin()
: Sensor operation starts 2. 2.PIN_SNS_INT
interrupt or available()
: FIFO queue reaches the specified number 3. 3..get_que()
: Get data from the FIFO queue
None in particular.
To wake up by PIN_SNS_INT interrupt, the following settings must be made before sleep.
A call to the .wakeup()
method is required. This process is executed in the <PAL_MOT>
board BEHAVIOR.
If the semiconductor's internal FIFO queue is full and no read is performed, the data acquisition is terminated and no new values are stored.
Each sample is stored in a queue smplque
whose elements are axis_xyzt
structures. The members x,y,z correspond to the X, Y, and Z axes, respectively.
The value of each axis is stored as a value where 1G is 1000. The t
is the sample number, which is assigned to each sample in order from 0
.
Reads data from a semiconductor FIFO queue. The number of bytes read is returned, but be sure to read the number of data stored in the size of the queue referenced by .get_que()
.
After returning from sleep, <PAL_MOT>
will do read()
.
Get a sample of the acceleration. The queue is smplque
with axis_xyzt
as an element; the queue should be emptied as soon as it is available.
This sensor does not use setup()
.
Initialize with the settings specified in conf
.
conf[0:15]
(bit0-15): sampling mode, conf[16:23]
(bit16-23): range of acceleration, conf[24:31]
(bit24-31): number of samples until interrupt occurs.
Unofficial settings are not described in the MC3630 datasheet and their behavior is undefined. Please check the behavior of the settings before using them. We are not able to answer any questions or problems related to the unofficial settings.
This sensor does not use process_ev()
.
Returns true
if data is read out to the sensor and stored in the internal queue.
You cannot use probe()
with this sensor.
Reinitializes the SPI bus after sleep recovery and reads acceleration data.
PCA9632 - LED Driver
LED driver used for NOTICE PAL.
1.Wire.begin()
: Initialize bus 2 .setup()
: Initialize the class object .reset()
: Initialization of the driver 4. 4. various procedures
This is a 4-channel LED driver.
Each channel can specify 4 states: off, all lights on, PWM on, and blinking.
Each channel can control illuminance (PWM) independently.
All chs designated as blinking have the same blinking pattern.
When blinking, illuminance can be controlled for each channel individually by PWM
Before calling the setup()
method, Wire must be put into operation state by Wire.begin()
.
Keep the Wire bus in the operating state just before sleep (the Wire is automatically restored after sleep recovery).
#include <SNS_PCA9632>
and declaration of SNS_PCA9632
class object is required.
In the above example, LEDs 1 and 3 are turned on by PWM control.
Be careful of the current value consumed by the driver when lighting up.
Specify i2c_addr
in the constructor.
If you define a class object in a global declaration, the constructor will not be called, so call setup()
.
Initializes the device. \0x0} Writes {0x81, 0x35, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x0B, 0x00}
starting with register address 0x0.
Write a value to the MODE2 register.
Setting b_pow_on
to true
will cause normal operation, setting it to false
will cause sleep.
Determines the blinking (group PWM) period.
If u8var
is specified, the period is (u8var+1)/24
[s].
The u16ms
specifies the period in œms.
Determines the duty ratio of blinking (group PWM). The lighting period is u8duty/256
, where 0 corresponds to lights off and 255 corresponds to all lights on.
brightness (duty ratio of PMW control).
port
specifies the target LED (SNS_PCA9632::LED1..4
).
... duty
specifies 0..255, and the LEDs are turned on with the ratio duty/256
.
Specify the brightness (duty ratio of PMW control) for all LEDs.
p1,p2,p3,p4
specifies 0...255 in duty for LED1...4. The LEDs turn on at a ratio duty/256
.
Changes the lighting state of all LEDs.
u8led1..4
specifies the state of LED1..4 in order.
The states that can be specified are as follows.
Returns true
if a device exists on the I2C bus.
Displays the value of register (0x0-0x8).
conf[0:15] sample mode | contents |
---|---|
conf[16:23] Acceleration range | Contents |
---|---|
The control on the NOTICE PAL is done via .
Content |
---|
MODE_LP_1HZ_UNOFFICIAL
1Hz Low Power (unofficial setting)
MODE_LP_2HZ_UNOFFICIAL
2Hz Low Power (unofficial setting)
MODE_LP_7HZ_UNOFFICIAL
7Hz Low Power (unofficial setting)
MODE_LP_14HZ
14Hz Low Power (default)
MODE_LP_28HZ
28Hz Low Power
MODE_LP_54HZ
54Hz Low Power
MODE_LP_105HZ
105Hz Low Power
MODE_LP_210HZ
210Hz Low Power
MODE_LP_400HZ
400Hz Low Power
MODE_ULP_25HZ
25Hz Ultra Low Power
MODE_ULP_50HZ
50Hz Ultra Low Power
MODE_ULP_100HZ
100Hz Ultra Low Power
MODE_ULP_190HZ
190Hz Ultra Low Power
MODE_ULP_380HZ
380Hz Ultra Low Power
RANGE_PLUS_MINUS_8G
±8G (default)
RANGE_PLUS_MINUS_4G
±4G
RANGE_PLUS_MINUS_2G
±2G
RANGE_PLUS_MINUS_1G
±1G
| OFF |
| All lights on |
| Illumination control(PWM) |
| Blink control (group PWM) |
| Do not change state |