TMOS Unit
The following products are supported:
Micropython Example:
import os, sys, io
import M5
from M5 import *
from unit import TMOSUnit
from hardware import *
title0 = None
label0 = None
title1 = None
title2 = None
TMOSTest = None
label1 = None
label2 = None
label3 = None
i2c0 = None
tmos_0 = None
def tmos_0_presence_detect_event(arg):
global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0
label1.setText(str((str("Prescence Flag:") + str((tmos_0.get_presence_state())))))
label0.setText(str((str("Prescence:") + str((tmos_0.get_presence_value())))))
def tmos_0_motion_detect_event(arg):
global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0
label3.setText(str((str("Motion Flag:") + str((tmos_0.get_motion_state())))))
label2.setText(str((str("Motion:") + str((tmos_0.get_motion_value())))))
def tmos_0_presence_not_detected_event(arg):
global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0
label1.setText(str((str("Prescence Flag:") + str((tmos_0.get_presence_state())))))
def tmos_0_motion_not_detected_event(arg):
global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0
label3.setText(str((str("Motion Flag:") + str((tmos_0.get_motion_state())))))
def setup():
global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0
M5.begin()
Widgets.fillScreen(0x222222)
title0 = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
label0 = Widgets.Label("Prescence:", 2, 65, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
title1 = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
title2 = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
TMOSTest = Widgets.Title("Title", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
label1 = Widgets.Label(
"Prescence Flag", 2, 98, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
)
label2 = Widgets.Label("Motion:", 2, 130, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
label3 = Widgets.Label("Motion Flag:", 2, 160, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
title0.setText("TMOS Test")
tmos_0 = TMOSUnit(i2c0, 0x5A)
tmos_0.set_callback(tmos_0_presence_detect_event, tmos_0.PRESENCE_DETECT)
tmos_0.set_callback(tmos_0_motion_detect_event, tmos_0.MOTION_DETECT)
tmos_0.set_callback(tmos_0_presence_not_detected_event, tmos_0.PRESENCE_NOT_DETECTED)
tmos_0.set_callback(tmos_0_motion_not_detected_event, tmos_0.MOTION_NOT_DETECTED)
label0.setText(str("Prescence:"))
label1.setText(str("Prescence Flag:"))
label2.setText(str("Motion:"))
label3.setText(str("Motion Flag:"))
print(tmos_0.get_gain_mode())
def loop():
global title0, label0, title1, title2, TMOSTest, label1, label2, label3, i2c0, tmos_0
M5.update()
tmos_0.tick_callback()
if __name__ == "__main__":
try:
setup()
while True:
loop()
except (Exception, KeyboardInterrupt) as e:
try:
from utility import print_error_msg
print_error_msg(e)
except ImportError:
print("please update to latest firmware")
UIFLOW2 Example:
class TMOSUnit
Constructors
- class TMOSUnit(i2c0, address)
Create a TMOSUnit object.
- Parameters:
i2c – I2C object
address – I2C address, 0x5A by default
UIFLOW2:
Methods
- TMOSUnit.get_data_ready() bool
Get data update status of TMOSUnit(TAMBIENT, TOBJECT, TAMB_SHOCK, TPRESENCE, TMOTION).
- Returns:
The data update status of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_motion_state() bool
Get the motion status detected by TMOSUnit
- Returns:
The motion status.
UIFLOW2:
- TMOSUnit.get_motion_value() int
Get motion value(unit:cm^-1)
- Returns:
The motion value of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_presence_state() bool
Get the presence status detected by TMOSUnit
- Returns:
The presence status.
UIFLOW2:
- TMOSUnit.get_presence_value() int
Get presence value(unit:cm^-1)
- Returns:
The presence value of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_tamb_shock_state() bool
Get the ambient temperature shock status detected by TMOSUnit
- Returns:
The ambient temperature shock detection status.
UIFLOW2:
- TMOSUnit.get_tambient_raw_value() int
Get ambient temperature, represents the temperature of the environment in thermal coupling with the sensor.
- Returns:
The ambient temperature of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_temperature_data() float
Get object temperature, represents the amount of infrared radiation emitted from the objects inside the field of view.
- Returns:
The object temperature of TMOSUnit.
UIFLOW2:
- TMOSUnit.set_callback(self, handler, trigger: Literal[0, 1, 2, 3, 4, 5])
Set callback function for different triggers.
- Parameters:
handler – The callback function to be set.
trigger –
The event trigger to set the handler for:
ambient temperature
: 0motion
: 1presence
: 2ambient temperature not
: 3motion not
: 4presence not
: 5
UIFLOW2:
- TMOSUnit.tick_callback(self)
Check the status of the TMOSUnit and execute the corresponding callback functions based on the event flags.
This method should be called periodically to poll the sensor status and handle any detected events.
It checks the following flags and triggers the associated callbacks if the flags are set:
ambient temperature
(0): Indicates an ambient temperature shock event.motion
(1): Indicates a motion detection event.presence
(2): Indicates a presence detection event.ambient temperature not
(3): Indicates an ambient temperature shock event has not occurred.motion not
(4): Indicates a motion detection event has not occurred.presence not
(5): Indicates a presence detection event has not occurred.
The callback functions associated with these events are set using the
set_callback()
method.UIFLOW2:
- TMOSUnit.get_tmos_sensitivity() int
Get the sensitivity configuration of TMOS.
- Returns:
TMOS sensitivity
UIFLOW2:
- TMOSUnit.get_motion_threshold() int
Get the motion threshold for motion detection algorithm.
- return:
The motion threshold of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_motion_hysteresis() int
Get hysteresis value for motion detection algorithm.
- return:
The motion hysteresis of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_presence_threshold() int
Get the presence threshold for presence detection algorithm.
- Returns:
The presence threshold of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_presence_hysteresis() int
Get hysteresis value for presence detection algorithm.
- return:
The presence hysteresis of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_tambient_shock_threshold() int
Get the ambient temperature shock threshold for Tambient shock detection algorithm.
- return:
The ambient temperature shock threshold of TMOSUnit.
UIFLOW2:
- TMOSUnit.get_tambient_shock_hysteresis() int
Get hysteresis value for ambient temperature shock detection algor.
- return:
The ambient temperature shock hysteresis of TMOSUnit.
UIFLOW2:
- TMOSUnit.set_gain_mode(val) None
Set the gain mode of TMOS (Note: DEFAULT mode has high sensitivity but easily leads to sensor oversaturation; WIDE mode has short detection distance but can avoid sensor saturation)
- Parameters:
val (int) –
Gain mode
- Options:
GAIN_WIDE_MODE
: 0GAIN_DEFAULT_MODE
: 7
UIFLOW2:
- TMOSUnit.set_tmos_sensitivity(val) None
Set the sensitivity of TMOS
- Parameters:
val (int) – Sensitivity(0x00 ~ 0xFF)
UIFLOW2:
- TMOSUnit.set_motion_threshold(val)
Set the the motion threshold for motion detection algorithm.
- Parameters:
val (int) – motion threshold(0x0~0x7FFF)
- Returns:
Is the setting successful?
UIFLOW2:
- TMOSUnit.set_motion_hysteresis(val)
Set hysteresis value for motion detection algorithm.
- Parameters:
val (int) – motion hysteresis(0x0~0xFF)
UIFLOW2:
- TMOSUnit.set_presence_threshold(val) bool
Set the presence threshold for presence detection algorithm.
- Parameters:
val (int) – presence threshold(0x0~0x7FFF)
- Returns:
Is the setting successful?
UIFLOW2:
- TMOSUnit.set_presence_hysteresis(val)
Set hysteresis value for presence detection algorithm.
- Parameters:
val (int) – presence hysteresis(0x0~0xFF)
UIFLOW2:
- TMOSUnit.set_tambient_shock_threshold(val) bool
Set ambient temperature shock threshold for Tambient shock detection algorithm.
- Parameters:
val (int) – ambient temperature shock threshold(0x0~0x7FFF)
- Returns:
Is the setting successful?
UIFLOW2:
- TMOSUnit.set_tambient_shock_hysteresis(val)
Set hysteresis value for ambient temperature shock detection algor.
- Parameters:
val (int) – ambient temperature shock hysteresis(0x0~0xFF)
UIFLOW2:
- TMOSUnit.reset() None
Reset TMOSUnit (includes restarting OTP memory content, resetting algorithms).
- TMOSUnit.reset_algo() None
Reset the algorithm (this function must be executed when modifying the threshold, hysteresis, absolute value in the selection of the presence detection algorithm, low-pass filter configuration).
- TMOSUnit.set_lpf_p_bandwidth(val) None
Sets the low pass filter configuration for presence detection.
- Parameters:
val (int) –
Configuration values for the low pass filter.
- Options:
TMOSUnit.STHS34PF80_LPF_ODR_DIV_9
: ODR/9 , 0TMOSUnit.STHS34PF80_LPF_ODR_DIV_20
: ODR/20, 1TMOSUnit.STHS34PF80_LPF_ODR_DIV_50
: ODR/50, 2TMOSUnit.STHS34PF80_LPF_ODR_DIV_100
: ODR/100, 3TMOSUnit.STHS34PF80_LPF_ODR_DIV_200
: ODR/200, 4TMOSUnit.STHS34PF80_LPF_ODR_DIV_400
: ODR/400, 5TMOSUnit.STHS34PF80_LPF_ODR_DIV_800
: ODR/800, 6
- TMOSUnit.get_lpf_p_bandwidth() int
Gets the low pass filter configuration used for presence detection.
- Returns:
Low pass filter bandwidth
- TMOSUnit.set_lpf_a_t_bandwidth(val) None
Sets the low-pass filter configuration for ambient temperature shock detection.
- Parameters:
val (int) –
Configuration values for the low pass filter.
- Options:
TMOSUnit.STHS34PF80_LPF_ODR_DIV_9
: ODR/9 , 0TMOSUnit.STHS34PF80_LPF_ODR_DIV_20
: ODR/20, 1TMOSUnit.STHS34PF80_LPF_ODR_DIV_50
: ODR/50, 2TMOSUnit.STHS34PF80_LPF_ODR_DIV_100
: ODR/100, 3TMOSUnit.STHS34PF80_LPF_ODR_DIV_200
: ODR/200, 4TMOSUnit.STHS34PF80_LPF_ODR_DIV_400
: ODR/400, 5TMOSUnit.STHS34PF80_LPF_ODR_DIV_800
: ODR/800, 6
- TMOSUnit.get_lpf_a_t_bandwidth() int
Gets the low pass filter configuration for ambient temperature shock detection.
- Returns:
Low pass filter bandwidth
- TMOSUnit.set_lpf_p_m_bandwidth(val) None
Sets the low-pass filter configuration for presence and motion detection.
- Parameters:
val (int) –
Configuration values for the low pass filter.
- Options:
TMOSUnit.STHS34PF80_LPF_ODR_DIV_9
: ODR/9 , 0TMOSUnit.STHS34PF80_LPF_ODR_DIV_20
: ODR/20, 1TMOSUnit.STHS34PF80_LPF_ODR_DIV_50
: ODR/50, 2TMOSUnit.STHS34PF80_LPF_ODR_DIV_100
: ODR/100, 3TMOSUnit.STHS34PF80_LPF_ODR_DIV_200
: ODR/200, 4TMOSUnit.STHS34PF80_LPF_ODR_DIV_400
: ODR/400, 5TMOSUnit.STHS34PF80_LPF_ODR_DIV_800
: ODR/800, 6
- TMOSUnit.get_lpf_p_m_bandwidth() int
Gets the low-pass filter configuration for presence and motion detection.
- Returns:
Low pass filter bandwidth
- TMOSUnit.set_lpf_m_bandwidth(val) None
Sets the low-pass filter configuration for motion detection.
- Parameters:
val (int) –
Configuration values for the low pass filter.
- Options:
TMOSUnit.STHS34PF80_LPF_ODR_DIV_9
: ODR/9 , 0TMOSUnit.STHS34PF80_LPF_ODR_DIV_20
: ODR/20, 1TMOSUnit.STHS34PF80_LPF_ODR_DIV_50
: ODR/50, 2TMOSUnit.STHS34PF80_LPF_ODR_DIV_100
: ODR/100, 3TMOSUnit.STHS34PF80_LPF_ODR_DIV_200
: ODR/200, 4TMOSUnit.STHS34PF80_LPF_ODR_DIV_400
: ODR/400, 5TMOSUnit.STHS34PF80_LPF_ODR_DIV_800
: ODR/800, 6
- TMOSUnit.get_lpf_m_bandwidth() int
Gets the low-pass filter configuration for motion detection.
- Returns:
Low pass filter bandwidth
- TMOSUnit.set_avg_tobj_num(val) None
Sets the number of samples to average the object’s temperature.
- Parameters:
val (int) –
Configuration value for the number of samples to average.
- Options:
TMOSUnit.STHS34PF80_AVG_TMOS_2
: RMS noise:90 , 0TMOSUnit.STHS34PF80_AVG_TMOS_8
: RMS noise:50, 1TMOSUnit.STHS34PF80_AVG_TMOS_32
: RMS noise:25, 2TMOSUnit.STHS34PF80_AVG_TMOS_128
: RMS noise:20, 3TMOSUnit.STHS34PF80_AVG_TMOS_256
: RMS noise:15, 4TMOSUnit.STHS34PF80_AVG_TMOS_512
: RMS noise:12, 5TMOSUnit.STHS34PF80_AVG_TMOS_1024
: RMS noise:11, 6TMOSUnit.STHS34PF80_AVG_TMOS_2048
: RMS noise:10, 7
- TMOSUnit.get_avg_tobj_num() int
Gets the number of samples to average the ambient temperature.
- Returns:
Average number of samples of object temperature
- TMOSUnit.set_avg_tamb_num(val) None
Sets the number of samples to average the ambient temperature.
- Parameters:
val (int) –
Configuration value for the number of samples to average.
- Options:
TMOSUnit.STHS34PF80_AVG_T_8
: 0TMOSUnit.STHS34PF80_AVG_T_4
: 1TMOSUnit.STHS34PF80_AVG_T_2
: 2TMOSUnit.STHS34PF80_AVG_T_1
: 3
- TMOSUnit.get_avg_tamb_num() int
Get the average number of samples of ambient temperature.
- Returns:
The number of samples for the average ambient temperature.
- TMOSUnit.set_tmos_odr(val) None
Set the output data rate of TMOS
- Parameters:
val (int) –
TMOS output data rate
- Options:
TMOSUnit.STHS34PF80_TMOS_ODR_OFF
: ODR frequency(Hz):Power-down mode, 0TMOSUnit.STHS34PF80_TMOS_ODR_AT_0Hz25
: ODR frequency(Hz):0.25, 1TMOSUnit.STHS34PF80_TMOS_ODR_AT_0Hz50
: ODR frequency(Hz):0.5, 2TMOSUnit.STHS34PF80_TMOS_ODR_AT_1Hz
: ODR frequency(Hz):1, 3TMOSUnit.STHS34PF80_TMOS_ODR_AT_2Hz
: ODR frequency(Hz):2, 4TMOSUnit.STHS34PF80_TMOS_ODR_AT_4Hz
: ODR frequency(Hz):4, 5TMOSUnit.STHS34PF80_TMOS_ODR_AT_8Hz
: ODR frequency(Hz):8, 6TMOSUnit.STHS34PF80_TMOS_ODR_AT_15Hz
: ODR frequency(Hz):15, 7TMOSUnit.STHS34PF80_TMOS_ODR_AT_30Hz
: ODR frequency(Hz):30, 8
- TMOSUnit.set_block_data_update(val) None
Enable/disable object temperature and ambient temperature register data update
- Parameters:
val (bool) – Enable or disable register data update
- TMOSUnit.get_block_data_update() bool
Get the object temperature and ambient temperature storage data update enable status
- Returns:
Data register update enable status
- TMOSUnit.set_tmos_one_shot(val) None
Set the state of one-time data collection
- Parameters:
val (bool) – One-time collection status
- TMOSUnit.get_tmos_one_shot() bool
Get the status of triggering a one-time collection
- Returns:
Get the status of triggering a one-time collection
- TMOSUnit.refresh_state() self
Retrieve the current status of the TMOSUnit, including presence detection, motion detection, and ambient temperature shock detection.
- Returns:
An instance of the TMOSUnit with updated status flags.