Compare commits

...

10 commits

Author SHA1 Message Date
Tyeth Gundry
e2fd901a66
Bump version from 1.0.0 to 1.0.1
Some checks failed
Arduino Library CI / build (push) Has been cancelled
2025-08-26 15:20:44 +01:00
ladyada
a6aba7192f Rename test sketch to fulltest_sths34pf80 with comprehensive documentation
- Renamed test_sths34pf80 to fulltest_sths34pf80 for clarity
- Added detailed header comments explaining the sketch demonstrates all sensor settings
- Uses sensor default values to provide stable API demonstration without unexpected register changes
- Maintains halt-on-error behavior with F() string memory optimization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 17:03:56 -04:00
ladyada
45bfd32b12 Apply clang-format to source files
Some checks failed
Arduino Library CI / build (push) Has been cancelled
- Format Adafruit_STHS34PF80.h and Adafruit_STHS34PF80.cpp with Google C++ style
- 2-space indentation, 80-character line limit, left-aligned pointers
- Consistent formatting for function declarations and definitions
2025-08-23 16:00:03 -04:00
ladyada
2df7d9b529 Remove output.txt test file 2025-08-23 15:58:50 -04:00
ladyada
22362184f8 Add standard Arduino library files and cleanup
- Add MIT LICENSE for 2024 Adafruit Industries
- Add library.properties with proper metadata and dependencies
- Add .clang-format with Google-based C++ formatting rules
- Add GitHub Actions workflow for CI/CD with Arduino builds and Doxygen
- Add Adafruit Community Code of Conduct
- Remove datasheet PDF and text files (not committed to repos)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 15:58:01 -04:00
ladyada
8bd0781af7 Add simple STHS34PF80 demo sketch
- Clean, minimal example showing basic sensor usage
- Always displays ambient temperature in Celsius
- Only shows detection values when events occur (presence, motion, temp shock)
- Only displays object temperatures when presence or motion detected
- 100ms update rate for responsive monitoring

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 15:47:46 -04:00
ladyada
01d2459424 Add reset() function for complete sensor reset
- Add reset() function that combines OTP memory reboot and algorithm reset
- Integrate reset() call into begin() initialization sequence after isConnected()
- Ensures clean sensor state before applying configuration settings
- 5ms delay for proper sensor reset timing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 15:23:11 -04:00
ladyada
cef5e156ec Port STM API functions with enhanced ODR validation and algorithm reset
- Port sths34pf80_tmos_odr_set with comprehensive ODR validation based on averaging settings
- Port sths34pf80_func_cfg_write as writeEmbeddedFunction() with safe power-down procedures
- Port sths34pf80_algo_reset as algorithmReset() for sensor algorithm reset
- Port sths34pf80_tmos_odr_check_safe_set as safeSetOutputDataRate() with proper DRDY handling
- Add proper #define STHS34PF80_EMBEDDED_RESET_ALGO to replace hardcoded 0x2A value
- Implement isConnected() function for chip ID verification (0xD3)
- Add complete data reading functions for all sensor outputs
- Add status flag checking functions (isDataReady, isPresence, isMotion, isTempShock)
- Update test sketch with live sensor readings and continuous monitoring
- Enhance begin() to use recommended default settings and proper initialization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 15:11:39 -04:00
ladyada
354bb82d86 Add complete CTRL3 register support with interrupt configuration
- Add interrupt polarity, output type, and latched mode configuration
- Add interrupt mask support for presence, motion, and ambient shock flags
- Add interrupt signal routing (High-Z, DRDY, INT_OR)
- Add flag definitions for PRES_FLAG, MOT_FLAG, TAMB_SHOCK_FLAG
- Update test sketch with interrupt configuration testing
- All functions tested and verified working with hardware

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-22 18:00:49 -04:00
Limor "Ladyada" Fried
41f1a29cae
Delete sths34pf80.pdf:Zone.Identifier 2025-08-17 21:28:52 -04:00
14 changed files with 1493 additions and 5433 deletions

View file

@ -10,4 +10,4 @@ BinPackParameters: true
BreakBeforeBraces: Attach BreakBeforeBraces: Attach
DerivePointerAlignment: false DerivePointerAlignment: false
PointerAlignment: Left PointerAlignment: Left
SpacesBeforeTrailingComments: 1 SpacesBeforeTrailingComments: 1

View file

@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/setup-python@v1 - uses: actions/checkout@v4
- uses: actions/setup-python@v4
with: with:
python-version: '3.x' python-version: '3.x'
- uses: actions/checkout@v2 - uses: actions/checkout@v4
- uses: actions/checkout@v2
with: with:
repository: adafruit/ci-arduino repository: adafruit/ci-arduino
path: ci path: ci
@ -25,7 +25,7 @@ jobs:
- name: test platforms - name: test platforms
run: python3 ci/build_platform.py main_platforms run: python3 ci/build_platform.py main_platforms
- name: doxygen - name: doxy
env: env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit STHS34PF80 Arduino Library" PRETTYNAME : "Adafruit STHS34PF80 Arduino Library"

View file

@ -48,7 +48,7 @@ Adafruit_STHS34PF80::~Adafruit_STHS34PF80() {
* @param wire The Wire object to be used for I2C connections * @param wire The Wire object to be used for I2C connections
* @return True if initialization was successful, otherwise false * @return True if initialization was successful, otherwise false
*/ */
bool Adafruit_STHS34PF80::begin(uint8_t i2c_addr, TwoWire *wire) { bool Adafruit_STHS34PF80::begin(uint8_t i2c_addr, TwoWire* wire) {
if (i2c_dev) { if (i2c_dev) {
delete i2c_dev; delete i2c_dev;
} }
@ -59,10 +59,64 @@ bool Adafruit_STHS34PF80::begin(uint8_t i2c_addr, TwoWire *wire) {
return false; return false;
} }
Adafruit_BusIO_Register chip_id = Adafruit_BusIO_Register( if (!isConnected()) {
i2c_dev, STHS34PF80_REG_WHO_AM_I, 1); return false;
}
if (chip_id.read() != 0xD3) { if (!reset()) {
return false;
}
// Apply recommended default settings
if (!setObjAveraging(STHS34PF80_AVG_TMOS_32)) {
return false;
}
if (!setAmbTempAveraging(STHS34PF80_AVG_T_8)) {
return false;
}
if (!setBlockDataUpdate(true)) {
return false;
}
if (!setOutputDataRate(STHS34PF80_ODR_1_HZ)) {
return false;
}
return true;
}
/*!
* @brief Check if the sensor is connected by reading device ID
* @return True if device ID matches expected value (0xD3), false otherwise
*/
bool Adafruit_STHS34PF80::isConnected() {
if (!i2c_dev) {
return false;
}
Adafruit_BusIO_Register chip_id =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_WHO_AM_I, 1);
return chip_id.read() == 0xD3;
}
/*!
* @brief Reset the sensor completely
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::reset() {
// Reboot OTP memory
if (!rebootOTPmemory()) {
return false;
}
// Wait for sensor reset to complete
delay(5);
// Reset the internal algorithm
if (!algorithmReset()) {
return false; return false;
} }
@ -74,13 +128,14 @@ bool Adafruit_STHS34PF80::begin(uint8_t i2c_addr, TwoWire *wire) {
* @param config The LPF configuration value * @param config The LPF configuration value
* @return True if successful, false otherwise * @return True if successful, false otherwise
*/ */
bool Adafruit_STHS34PF80::setMotionLowPassFilter(sths34pf80_lpf_config_t config) { bool Adafruit_STHS34PF80::setMotionLowPassFilter(
Adafruit_BusIO_Register lpf1_reg = Adafruit_BusIO_Register( sths34pf80_lpf_config_t config) {
i2c_dev, STHS34PF80_REG_LPF1, 1); Adafruit_BusIO_Register lpf1_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF1, 1);
Adafruit_BusIO_RegisterBits lpf_m_bits = Adafruit_BusIO_RegisterBits(
&lpf1_reg, 3, 0); Adafruit_BusIO_RegisterBits lpf_m_bits =
Adafruit_BusIO_RegisterBits(&lpf1_reg, 3, 0);
return lpf_m_bits.write(config); return lpf_m_bits.write(config);
} }
@ -89,12 +144,12 @@ bool Adafruit_STHS34PF80::setMotionLowPassFilter(sths34pf80_lpf_config_t config)
* @return The current LPF configuration value * @return The current LPF configuration value
*/ */
sths34pf80_lpf_config_t Adafruit_STHS34PF80::getMotionLowPassFilter() { sths34pf80_lpf_config_t Adafruit_STHS34PF80::getMotionLowPassFilter() {
Adafruit_BusIO_Register lpf1_reg = Adafruit_BusIO_Register( Adafruit_BusIO_Register lpf1_reg =
i2c_dev, STHS34PF80_REG_LPF1, 1); Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF1, 1);
Adafruit_BusIO_RegisterBits lpf_m_bits = Adafruit_BusIO_RegisterBits( Adafruit_BusIO_RegisterBits lpf_m_bits =
&lpf1_reg, 3, 0); Adafruit_BusIO_RegisterBits(&lpf1_reg, 3, 0);
return (sths34pf80_lpf_config_t)lpf_m_bits.read(); return (sths34pf80_lpf_config_t)lpf_m_bits.read();
} }
@ -103,13 +158,14 @@ sths34pf80_lpf_config_t Adafruit_STHS34PF80::getMotionLowPassFilter() {
* @param config The LPF configuration value * @param config The LPF configuration value
* @return True if successful, false otherwise * @return True if successful, false otherwise
*/ */
bool Adafruit_STHS34PF80::setMotionPresenceLowPassFilter(sths34pf80_lpf_config_t config) { bool Adafruit_STHS34PF80::setMotionPresenceLowPassFilter(
Adafruit_BusIO_Register lpf1_reg = Adafruit_BusIO_Register( sths34pf80_lpf_config_t config) {
i2c_dev, STHS34PF80_REG_LPF1, 1); Adafruit_BusIO_Register lpf1_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF1, 1);
Adafruit_BusIO_RegisterBits lpf_p_m_bits = Adafruit_BusIO_RegisterBits(
&lpf1_reg, 3, 3); Adafruit_BusIO_RegisterBits lpf_p_m_bits =
Adafruit_BusIO_RegisterBits(&lpf1_reg, 3, 3);
return lpf_p_m_bits.write(config); return lpf_p_m_bits.write(config);
} }
@ -118,12 +174,12 @@ bool Adafruit_STHS34PF80::setMotionPresenceLowPassFilter(sths34pf80_lpf_config_t
* @return The current LPF configuration value * @return The current LPF configuration value
*/ */
sths34pf80_lpf_config_t Adafruit_STHS34PF80::getMotionPresenceLowPassFilter() { sths34pf80_lpf_config_t Adafruit_STHS34PF80::getMotionPresenceLowPassFilter() {
Adafruit_BusIO_Register lpf1_reg = Adafruit_BusIO_Register( Adafruit_BusIO_Register lpf1_reg =
i2c_dev, STHS34PF80_REG_LPF1, 1); Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF1, 1);
Adafruit_BusIO_RegisterBits lpf_p_m_bits = Adafruit_BusIO_RegisterBits( Adafruit_BusIO_RegisterBits lpf_p_m_bits =
&lpf1_reg, 3, 3); Adafruit_BusIO_RegisterBits(&lpf1_reg, 3, 3);
return (sths34pf80_lpf_config_t)lpf_p_m_bits.read(); return (sths34pf80_lpf_config_t)lpf_p_m_bits.read();
} }
@ -132,13 +188,14 @@ sths34pf80_lpf_config_t Adafruit_STHS34PF80::getMotionPresenceLowPassFilter() {
* @param config The LPF configuration value * @param config The LPF configuration value
* @return True if successful, false otherwise * @return True if successful, false otherwise
*/ */
bool Adafruit_STHS34PF80::setPresenceLowPassFilter(sths34pf80_lpf_config_t config) { bool Adafruit_STHS34PF80::setPresenceLowPassFilter(
Adafruit_BusIO_Register lpf2_reg = Adafruit_BusIO_Register( sths34pf80_lpf_config_t config) {
i2c_dev, STHS34PF80_REG_LPF2, 1); Adafruit_BusIO_Register lpf2_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF2, 1);
Adafruit_BusIO_RegisterBits lpf_p_bits = Adafruit_BusIO_RegisterBits(
&lpf2_reg, 3, 3); Adafruit_BusIO_RegisterBits lpf_p_bits =
Adafruit_BusIO_RegisterBits(&lpf2_reg, 3, 3);
return lpf_p_bits.write(config); return lpf_p_bits.write(config);
} }
@ -147,40 +204,761 @@ bool Adafruit_STHS34PF80::setPresenceLowPassFilter(sths34pf80_lpf_config_t confi
* @return The current LPF configuration value * @return The current LPF configuration value
*/ */
sths34pf80_lpf_config_t Adafruit_STHS34PF80::getPresenceLowPassFilter() { sths34pf80_lpf_config_t Adafruit_STHS34PF80::getPresenceLowPassFilter() {
Adafruit_BusIO_Register lpf2_reg = Adafruit_BusIO_Register( Adafruit_BusIO_Register lpf2_reg =
i2c_dev, STHS34PF80_REG_LPF2, 1); Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF2, 1);
Adafruit_BusIO_RegisterBits lpf_p_bits = Adafruit_BusIO_RegisterBits( Adafruit_BusIO_RegisterBits lpf_p_bits =
&lpf2_reg, 3, 3); Adafruit_BusIO_RegisterBits(&lpf2_reg, 3, 3);
return (sths34pf80_lpf_config_t)lpf_p_bits.read(); return (sths34pf80_lpf_config_t)lpf_p_bits.read();
} }
/*! /*!
* @brief Set the ambient temperature shock detection low-pass filter configuration * @brief Set the ambient temperature shock detection low-pass filter
* configuration
* @param config The LPF configuration value * @param config The LPF configuration value
* @return True if successful, false otherwise * @return True if successful, false otherwise
*/ */
bool Adafruit_STHS34PF80::setTemperatureLowPassFilter(sths34pf80_lpf_config_t config) { bool Adafruit_STHS34PF80::setTemperatureLowPassFilter(
Adafruit_BusIO_Register lpf2_reg = Adafruit_BusIO_Register( sths34pf80_lpf_config_t config) {
i2c_dev, STHS34PF80_REG_LPF2, 1); Adafruit_BusIO_Register lpf2_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF2, 1);
Adafruit_BusIO_RegisterBits lpf_a_t_bits = Adafruit_BusIO_RegisterBits(
&lpf2_reg, 3, 0); Adafruit_BusIO_RegisterBits lpf_a_t_bits =
Adafruit_BusIO_RegisterBits(&lpf2_reg, 3, 0);
return lpf_a_t_bits.write(config); return lpf_a_t_bits.write(config);
} }
/*! /*!
* @brief Get the ambient temperature shock detection low-pass filter configuration * @brief Get the ambient temperature shock detection low-pass filter
* configuration
* @return The current LPF configuration value * @return The current LPF configuration value
*/ */
sths34pf80_lpf_config_t Adafruit_STHS34PF80::getTemperatureLowPassFilter() { sths34pf80_lpf_config_t Adafruit_STHS34PF80::getTemperatureLowPassFilter() {
Adafruit_BusIO_Register lpf2_reg = Adafruit_BusIO_Register( Adafruit_BusIO_Register lpf2_reg =
i2c_dev, STHS34PF80_REG_LPF2, 1); Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_LPF2, 1);
Adafruit_BusIO_RegisterBits lpf_a_t_bits = Adafruit_BusIO_RegisterBits( Adafruit_BusIO_RegisterBits lpf_a_t_bits =
&lpf2_reg, 3, 0); Adafruit_BusIO_RegisterBits(&lpf2_reg, 3, 0);
return (sths34pf80_lpf_config_t)lpf_a_t_bits.read(); return (sths34pf80_lpf_config_t)lpf_a_t_bits.read();
}
/*!
* @brief Set ambient temperature averaging configuration
* @param config The averaging configuration value
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setAmbTempAveraging(sths34pf80_avg_t_t config) {
Adafruit_BusIO_Register avg_trim_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
Adafruit_BusIO_RegisterBits avg_t_bits =
Adafruit_BusIO_RegisterBits(&avg_trim_reg, 2, 4);
return avg_t_bits.write(config);
}
/*!
* @brief Get ambient temperature averaging configuration
* @return The current averaging configuration value
*/
sths34pf80_avg_t_t Adafruit_STHS34PF80::getAmbTempAveraging() {
Adafruit_BusIO_Register avg_trim_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
Adafruit_BusIO_RegisterBits avg_t_bits =
Adafruit_BusIO_RegisterBits(&avg_trim_reg, 2, 4);
return (sths34pf80_avg_t_t)avg_t_bits.read();
}
/*!
* @brief Set object temperature averaging configuration
* @param config The averaging configuration value
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setObjAveraging(sths34pf80_avg_tmos_t config) {
Adafruit_BusIO_Register avg_trim_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
Adafruit_BusIO_RegisterBits avg_tmos_bits =
Adafruit_BusIO_RegisterBits(&avg_trim_reg, 3, 0);
return avg_tmos_bits.write(config);
}
/*!
* @brief Get object temperature averaging configuration
* @return The current averaging configuration value
*/
sths34pf80_avg_tmos_t Adafruit_STHS34PF80::getObjAveraging() {
Adafruit_BusIO_Register avg_trim_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
Adafruit_BusIO_RegisterBits avg_tmos_bits =
Adafruit_BusIO_RegisterBits(&avg_trim_reg, 3, 0);
return (sths34pf80_avg_tmos_t)avg_tmos_bits.read();
}
/*!
* @brief Set wide gain mode configuration
* @param wide_mode True for wide mode, false for default gain mode
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setWideGainMode(bool wide_mode) {
Adafruit_BusIO_Register ctrl0_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL0, 1);
Adafruit_BusIO_RegisterBits gain_bits =
Adafruit_BusIO_RegisterBits(&ctrl0_reg, 3, 4);
return gain_bits.write(wide_mode ? 0x00 : 0x07);
}
/*!
* @brief Get wide gain mode configuration
* @return True if in wide mode, false if in default gain mode
*/
bool Adafruit_STHS34PF80::getWideGainMode() {
Adafruit_BusIO_Register ctrl0_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL0, 1);
Adafruit_BusIO_RegisterBits gain_bits =
Adafruit_BusIO_RegisterBits(&ctrl0_reg, 3, 4);
return gain_bits.read() == 0x00;
}
/*!
* @brief Set sensitivity value for ambient temperature compensation
* @param sensitivity Signed 8-bit sensitivity value (two's complement)
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setSensitivity(int8_t sensitivity) {
Adafruit_BusIO_Register sens_data_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_SENS_DATA, 1);
return sens_data_reg.write((uint8_t)sensitivity);
}
/*!
* @brief Get sensitivity value for ambient temperature compensation
* @return Signed 8-bit sensitivity value (two's complement)
*/
int8_t Adafruit_STHS34PF80::getSensitivity() {
Adafruit_BusIO_Register sens_data_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_SENS_DATA, 1);
return (int8_t)sens_data_reg.read();
}
/*!
* @brief Set block data update configuration
* @param enable True to enable block data update, false to disable
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setBlockDataUpdate(bool enable) {
Adafruit_BusIO_Register ctrl1_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL1, 1);
Adafruit_BusIO_RegisterBits bdu_bit =
Adafruit_BusIO_RegisterBits(&ctrl1_reg, 1, 4);
return bdu_bit.write(enable ? 1 : 0);
}
/*!
* @brief Get block data update configuration
* @return True if block data update is enabled, false if disabled
*/
bool Adafruit_STHS34PF80::getBlockDataUpdate() {
Adafruit_BusIO_Register ctrl1_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL1, 1);
Adafruit_BusIO_RegisterBits bdu_bit =
Adafruit_BusIO_RegisterBits(&ctrl1_reg, 1, 4);
return bdu_bit.read() == 1;
}
/*!
* @brief Set output data rate configuration with validation
* Ported from: sths34pf80_tmos_odr_set
* @param odr The output data rate value
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setOutputDataRate(sths34pf80_odr_t odr) {
// sths34pf80_ctrl1_t ctrl1;
// sths34pf80_avg_trim_t avg_trim;
// sths34pf80_tmos_odr_t max_odr = STHS34PF80_TMOS_ODR_AT_30Hz;
// int32_t ret;
if (!i2c_dev) {
return false;
}
sths34pf80_odr_t max_odr = STHS34PF80_ODR_30_HZ;
sths34pf80_odr_t current_odr = getOutputDataRate();
// ret = sths34pf80_read_reg(ctx, STHS34PF80_CTRL1, (uint8_t *)&ctrl1, 1);
// if (ret == 0)
// {
// ret = sths34pf80_read_reg(ctx, STHS34PF80_AVG_TRIM, (uint8_t *)&avg_trim,
// 1);
sths34pf80_avg_tmos_t avg_tmos = getObjAveraging();
// switch(avg_trim.avg_tmos)
// {
switch (avg_tmos) {
// default:
// case STHS34PF80_AVG_TMOS_2:
// case STHS34PF80_AVG_TMOS_8:
// case STHS34PF80_AVG_TMOS_32:
// max_odr = STHS34PF80_TMOS_ODR_AT_30Hz;
// break;
default:
case STHS34PF80_AVG_TMOS_2:
case STHS34PF80_AVG_TMOS_8:
case STHS34PF80_AVG_TMOS_32:
max_odr = STHS34PF80_ODR_30_HZ;
break;
// case STHS34PF80_AVG_TMOS_128:
// max_odr = STHS34PF80_TMOS_ODR_AT_8Hz;
// break;
case STHS34PF80_AVG_TMOS_128:
max_odr = STHS34PF80_ODR_8_HZ;
break;
// case STHS34PF80_AVG_TMOS_256:
// max_odr = STHS34PF80_TMOS_ODR_AT_4Hz;
// break;
case STHS34PF80_AVG_TMOS_256:
max_odr = STHS34PF80_ODR_4_HZ;
break;
// case STHS34PF80_AVG_TMOS_512:
// max_odr = STHS34PF80_TMOS_ODR_AT_2Hz;
// break;
case STHS34PF80_AVG_TMOS_512:
max_odr = STHS34PF80_ODR_2_HZ;
break;
// case STHS34PF80_AVG_TMOS_1024:
// max_odr = STHS34PF80_TMOS_ODR_AT_1Hz;
// break;
case STHS34PF80_AVG_TMOS_1024:
max_odr = STHS34PF80_ODR_1_HZ;
break;
// case STHS34PF80_AVG_TMOS_2048:
// max_odr = STHS34PF80_TMOS_ODR_AT_0Hz50;
// break;
case STHS34PF80_AVG_TMOS_2048:
max_odr = STHS34PF80_ODR_0_5_HZ;
break;
}
// if (ret == 0)
// {
// if (val > max_odr)
// {
// return -1;
// }
if (odr > max_odr) {
return false; // Requested ODR exceeds maximum for current averaging setting
}
// ret = sths34pf80_tmos_odr_check_safe_set(ctx, ctrl1, (uint8_t)val);
// }
return safeSetOutputDataRate(current_odr, odr);
}
/*!
* @brief Get output data rate configuration
* @return The current output data rate value
*/
sths34pf80_odr_t Adafruit_STHS34PF80::getOutputDataRate() {
Adafruit_BusIO_Register ctrl1_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL1, 1);
Adafruit_BusIO_RegisterBits odr_bits =
Adafruit_BusIO_RegisterBits(&ctrl1_reg, 4, 0);
return (sths34pf80_odr_t)odr_bits.read();
}
/*!
* @brief Reboot OTP memory
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::rebootOTPmemory() {
Adafruit_BusIO_Register ctrl2_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL2, 1);
Adafruit_BusIO_RegisterBits boot_bit =
Adafruit_BusIO_RegisterBits(&ctrl2_reg, 1, 7);
return boot_bit.write(1);
}
/*!
* @brief Enable or disable embedded function page access
* @param enable True to enable embedded function page, false to disable
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::enableEmbeddedFuncPage(bool enable) {
Adafruit_BusIO_Register ctrl2_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL2, 1);
Adafruit_BusIO_RegisterBits func_cfg_access_bit =
Adafruit_BusIO_RegisterBits(&ctrl2_reg, 1, 4);
return func_cfg_access_bit.write(enable ? 1 : 0);
}
/*!
* @brief Trigger one-shot measurement
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::triggerOneshot() {
Adafruit_BusIO_Register ctrl2_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL2, 1);
Adafruit_BusIO_RegisterBits oneshot_bit =
Adafruit_BusIO_RegisterBits(&ctrl2_reg, 1, 0);
return oneshot_bit.write(1);
}
/*!
* @brief Set interrupt polarity
* @param active_low True for active low (default), false for active high
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setIntPolarity(bool active_low) {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits int_h_l_bit =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 1, 7);
return int_h_l_bit.write(active_low ? 1 : 0);
}
/*!
* @brief Set interrupt output type
* @param open_drain True for open drain, false for push-pull (default)
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setIntOpenDrain(bool open_drain) {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits pp_od_bit =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 1, 6);
return pp_od_bit.write(open_drain ? 1 : 0);
}
/*!
* @brief Set interrupt latched mode
* @param latched True for latched mode, false for pulsed mode (default)
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setIntLatched(bool latched) {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits int_latched_bit =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 1, 2);
return int_latched_bit.write(latched ? 1 : 0);
}
/*!
* @brief Set interrupt mask for function status flags
* @param mask Interrupt mask (bits 2:0 for PRES_FLAG, MOT_FLAG,
* TAMB_SHOCK_FLAG)
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setIntMask(uint8_t mask) {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits int_mask_bits =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 3, 3);
return int_mask_bits.write(mask & 0x07);
}
/*!
* @brief Get interrupt mask for function status flags
* @return Current interrupt mask value (bits 2:0 for PRES_FLAG, MOT_FLAG,
* TAMB_SHOCK_FLAG)
*/
uint8_t Adafruit_STHS34PF80::getIntMask() {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits int_mask_bits =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 3, 3);
return int_mask_bits.read();
}
/*!
* @brief Set interrupt signal type
* @param signal Interrupt signal type (HIGH_Z, DRDY, or INT_OR)
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::setIntSignal(sths34pf80_int_signal_t signal) {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits ien_bits =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 2, 0);
return ien_bits.write(signal);
}
/*!
* @brief Get interrupt signal type
* @return Current interrupt signal type
*/
sths34pf80_int_signal_t Adafruit_STHS34PF80::getIntSignal() {
Adafruit_BusIO_Register ctrl3_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL3, 1);
Adafruit_BusIO_RegisterBits ien_bits =
Adafruit_BusIO_RegisterBits(&ctrl3_reg, 2, 0);
return (sths34pf80_int_signal_t)ien_bits.read();
}
/*!
* @brief Check if new data is ready
* @return True if new data is available, false otherwise
*/
bool Adafruit_STHS34PF80::isDataReady() {
Adafruit_BusIO_Register status_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_STATUS, 1);
Adafruit_BusIO_RegisterBits drdy_bit =
Adafruit_BusIO_RegisterBits(&status_reg, 1, 2);
return drdy_bit.read() == 1;
}
/*!
* @brief Check if presence detection flag is set
* @return True if presence is detected, false otherwise
*/
bool Adafruit_STHS34PF80::isPresence() {
Adafruit_BusIO_Register func_status_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_FUNC_STATUS, 1);
Adafruit_BusIO_RegisterBits pres_flag_bit =
Adafruit_BusIO_RegisterBits(&func_status_reg, 1, 2);
return pres_flag_bit.read() == 1;
}
/*!
* @brief Check if motion detection flag is set
* @return True if motion is detected, false otherwise
*/
bool Adafruit_STHS34PF80::isMotion() {
Adafruit_BusIO_Register func_status_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_FUNC_STATUS, 1);
Adafruit_BusIO_RegisterBits mot_flag_bit =
Adafruit_BusIO_RegisterBits(&func_status_reg, 1, 1);
return mot_flag_bit.read() == 1;
}
/*!
* @brief Check if ambient temperature shock flag is set
* @return True if temperature shock is detected, false otherwise
*/
bool Adafruit_STHS34PF80::isTempShock() {
Adafruit_BusIO_Register func_status_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_FUNC_STATUS, 1);
Adafruit_BusIO_RegisterBits tamb_shock_flag_bit =
Adafruit_BusIO_RegisterBits(&func_status_reg, 1, 0);
return tamb_shock_flag_bit.read() == 1;
}
/*!
* @brief Read object temperature raw value
* @return 16-bit signed object temperature value
*/
int16_t Adafruit_STHS34PF80::readObjectTemperature() {
Adafruit_BusIO_Register tobj_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_TOBJECT_L, 2, LSBFIRST);
return (int16_t)tobj_reg.read();
}
/*!
* @brief Read ambient temperature in degrees Celsius
* @return Ambient temperature in degrees Celsius
*/
float Adafruit_STHS34PF80::readAmbientTemperature() {
Adafruit_BusIO_Register tamb_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_TAMBIENT_L, 2, LSBFIRST);
int16_t raw_temp = (int16_t)tamb_reg.read();
return raw_temp / 100.0f;
}
/*!
* @brief Read compensated object temperature raw value
* @return 16-bit signed compensated object temperature value
*/
int16_t Adafruit_STHS34PF80::readCompensatedObjectTemperature() {
Adafruit_BusIO_Register tobj_comp_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_TOBJ_COMP_L, 2, LSBFIRST);
return (int16_t)tobj_comp_reg.read();
}
/*!
* @brief Read presence detection raw value
* @return 16-bit signed presence detection value
*/
int16_t Adafruit_STHS34PF80::readPresence() {
Adafruit_BusIO_Register tpres_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_TPRESENCE_L, 2, LSBFIRST);
return (int16_t)tpres_reg.read();
}
/*!
* @brief Read motion detection raw value
* @return 16-bit signed motion detection value
*/
int16_t Adafruit_STHS34PF80::readMotion() {
Adafruit_BusIO_Register tmot_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_TMOTION_L, 2, LSBFIRST);
return (int16_t)tmot_reg.read();
}
/*!
* @brief Read ambient temperature shock detection raw value
* @return 16-bit signed ambient temperature shock detection value
*/
int16_t Adafruit_STHS34PF80::readTempShock() {
Adafruit_BusIO_Register tamb_shock_reg = Adafruit_BusIO_Register(
i2c_dev, STHS34PF80_REG_TAMB_SHOCK_L, 2, LSBFIRST);
return (int16_t)tamb_shock_reg.read();
}
/*!
* @brief Write data to embedded function registers
* Ported from: sths34pf80_func_cfg_write
* @param addr Embedded function register address
* @param data Pointer to data to write
* @param len Number of bytes to write
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::writeEmbeddedFunction(uint8_t addr, uint8_t* data,
uint8_t len) {
// sths34pf80_ctrl1_t ctrl1;
// uint8_t odr;
// sths34pf80_page_rw_t page_rw = {0};
// int32_t ret;
// uint8_t i;
if (!i2c_dev) {
return false;
}
// /* Save current odr and enter PD mode */
// ret = sths34pf80_read_reg(ctx, STHS34PF80_CTRL1, (uint8_t *)&ctrl1, 1);
// odr = ctrl1.odr;
// ret += sths34pf80_tmos_odr_check_safe_set(ctx, ctrl1, 0);
sths34pf80_odr_t current_odr = getOutputDataRate();
if (!safeSetOutputDataRate(current_odr, STHS34PF80_ODR_POWER_DOWN)) {
return false;
}
// /* Enable access to embedded functions register */
// ret += sths34pf80_mem_bank_set(ctx, STHS34PF80_EMBED_FUNC_MEM_BANK);
if (!enableEmbeddedFuncPage(true)) {
return false;
}
// /* Enable write mode */
// page_rw.func_cfg_write = 1;
// ret += sths34pf80_write_reg(ctx, STHS34PF80_PAGE_RW, (uint8_t *)&page_rw,
// 1);
Adafruit_BusIO_Register page_rw_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_PAGE_RW, 1);
Adafruit_BusIO_RegisterBits func_cfg_write_bit =
Adafruit_BusIO_RegisterBits(&page_rw_reg, 1, 6);
if (!func_cfg_write_bit.write(1)) {
enableEmbeddedFuncPage(false);
safeSetOutputDataRate(STHS34PF80_ODR_POWER_DOWN, current_odr);
return false;
}
// /* Select register address (it will autoincrement after each write) */
// ret += sths34pf80_write_reg(ctx, STHS34PF80_FUNC_CFG_ADDR, &addr, 1);
Adafruit_BusIO_Register func_cfg_addr_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_FUNC_CFG_ADDR, 1);
if (!func_cfg_addr_reg.write(addr)) {
func_cfg_write_bit.write(0);
enableEmbeddedFuncPage(false);
safeSetOutputDataRate(STHS34PF80_ODR_POWER_DOWN, current_odr);
return false;
}
// /* Write data */
// for (i = 0; i < len; i++) {
// ret += sths34pf80_write_reg(ctx, STHS34PF80_FUNC_CFG_DATA, &data[i], 1);
// }
Adafruit_BusIO_Register func_cfg_data_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_FUNC_CFG_DATA, 1);
for (uint8_t i = 0; i < len; i++) {
if (!func_cfg_data_reg.write(data[i])) {
func_cfg_write_bit.write(0);
enableEmbeddedFuncPage(false);
safeSetOutputDataRate(STHS34PF80_ODR_POWER_DOWN, current_odr);
return false;
}
}
// /* Disable write mode */
// page_rw.func_cfg_write = 0;
// ret += sths34pf80_write_reg(ctx, STHS34PF80_PAGE_RW, (uint8_t *)&page_rw,
// 1);
if (!func_cfg_write_bit.write(0)) {
enableEmbeddedFuncPage(false);
safeSetOutputDataRate(STHS34PF80_ODR_POWER_DOWN, current_odr);
return false;
}
// /* Disable access to embedded functions register */
// ret += sths34pf80_mem_bank_set(ctx, STHS34PF80_MAIN_MEM_BANK);
if (!enableEmbeddedFuncPage(false)) {
safeSetOutputDataRate(STHS34PF80_ODR_POWER_DOWN, current_odr);
return false;
}
// /* Restore odr */
// ret += sths34pf80_tmos_odr_check_safe_set(ctx, ctrl1, odr);
if (!safeSetOutputDataRate(STHS34PF80_ODR_POWER_DOWN, current_odr)) {
return false;
}
// return ret;
return true;
}
/*!
* @brief Algorithm reset procedure
* Ported from: sths34pf80_algo_reset
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::algorithmReset() {
// tmp = 1;
// ret = sths34pf80_func_cfg_write(ctx, STHS34PF80_RESET_ALGO, &tmp, 1);
uint8_t reset_value = 1;
return writeEmbeddedFunction(STHS34PF80_EMBEDDED_RESET_ALGO, &reset_value, 1);
}
/*!
* @brief Safe ODR setting with proper algorithm reset and power-down procedures
* Ported from: sths34pf80_tmos_odr_check_safe_set
* @param current_odr The current output data rate
* @param new_odr The new output data rate to set
* @return True if successful, false otherwise
*/
bool Adafruit_STHS34PF80::safeSetOutputDataRate(sths34pf80_odr_t current_odr,
sths34pf80_odr_t new_odr) {
// sths34pf80_func_status_t func_status;
// sths34pf80_tmos_drdy_status_t status;
// int32_t ret = 0;
if (!i2c_dev) {
return false;
}
Adafruit_BusIO_Register ctrl1_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_CTRL1, 1);
Adafruit_BusIO_RegisterBits odr_bits =
Adafruit_BusIO_RegisterBits(&ctrl1_reg, 4, 0);
// if (odr_new > 0U) {
if (new_odr > STHS34PF80_ODR_POWER_DOWN) {
/*
* Do a clean reset algo procedure everytime odr is changed to an
* operative state.
*/
// ctrl1.odr = 0;
// ret = sths34pf80_write_reg(ctx, STHS34PF80_CTRL1, (uint8_t *)&ctrl1, 1);
if (!odr_bits.write(STHS34PF80_ODR_POWER_DOWN)) {
return false;
}
// ret += sths34pf80_algo_reset(ctx);
if (!algorithmReset()) {
return false;
}
} else {
/* if we need to go to power-down from an operative state
* perform the safe power-down.
*/
// if ((uint8_t)ctrl1.odr > 0U) {
if (current_odr > STHS34PF80_ODR_POWER_DOWN) {
/* reset the DRDY bit */
// ret = sths34pf80_read_reg(ctx, STHS34PF80_FUNC_STATUS, (uint8_t
// *)&func_status, 1);
Adafruit_BusIO_Register func_status_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_FUNC_STATUS, 1);
func_status_reg.read(); // Reading clears the DRDY bit
/* wait DRDY bit go to '1' */
// do {
// ret += sths34pf80_tmos_drdy_status_get(ctx, &status);
// } while (status.drdy != 0U);
Adafruit_BusIO_Register status_reg =
Adafruit_BusIO_Register(i2c_dev, STHS34PF80_REG_STATUS, 1);
Adafruit_BusIO_RegisterBits drdy_bit =
Adafruit_BusIO_RegisterBits(&status_reg, 1, 2);
uint32_t timeout = 1000; // 1 second timeout
while (timeout-- > 0) {
if (drdy_bit.read() == 1) {
break;
}
delay(1);
}
// Continue even if DRDY timeout occurs
// if (timeout == 0) {
// return false; // Timeout waiting for DRDY
// }
/* set ODR to 0 */
// ctrl1.odr = 0;
// ret += sths34pf80_write_reg(ctx, STHS34PF80_CTRL1, (uint8_t *)&ctrl1,
// 1);
if (!odr_bits.write(STHS34PF80_ODR_POWER_DOWN)) {
return false;
}
/* reset the DRDY bit */
// ret += sths34pf80_read_reg(ctx, STHS34PF80_FUNC_STATUS, (uint8_t
// *)&func_status, 1);
func_status_reg.read(); // Reading clears the DRDY bit again
}
}
// Final ODR set (implied from original function usage context)
return odr_bits.write(new_odr);
} }

View file

@ -21,36 +21,56 @@
#ifndef __ADAFRUIT_STHS34PF80_H__ #ifndef __ADAFRUIT_STHS34PF80_H__
#define __ADAFRUIT_STHS34PF80_H__ #define __ADAFRUIT_STHS34PF80_H__
#include "Arduino.h"
#include <Adafruit_BusIO_Register.h> #include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h> #include <Adafruit_I2CDevice.h>
#include <Wire.h> #include <Wire.h>
#include "Arduino.h"
#define STHS34PF80_DEFAULT_ADDR 0x5A ///< Default I2C address for the STHS34PF80 #define STHS34PF80_DEFAULT_ADDR 0x5A ///< Default I2C address for the STHS34PF80
#define STHS34PF80_REG_LPF1 0x0C ///< Low-pass filter configuration 1 register #define STHS34PF80_REG_LPF1 0x0C ///< Low-pass filter configuration 1 register
#define STHS34PF80_REG_LPF2 0x0D ///< Low-pass filter configuration 2 register #define STHS34PF80_REG_LPF2 0x0D ///< Low-pass filter configuration 2 register
#define STHS34PF80_REG_WHO_AM_I 0x0F ///< Device identification register #define STHS34PF80_REG_WHO_AM_I 0x0F ///< Device identification register
#define STHS34PF80_REG_AVG_TRIM 0x10 ///< Averaging configuration register #define STHS34PF80_REG_AVG_TRIM 0x10 ///< Averaging configuration register
#define STHS34PF80_REG_CTRL0 0x17 ///< Control register 0 (gain mode) #define STHS34PF80_REG_CTRL0 0x17 ///< Control register 0 (gain mode)
#define STHS34PF80_REG_SENS_DATA 0x1D ///< Sensitivity data register #define STHS34PF80_REG_SENS_DATA 0x1D ///< Sensitivity data register
#define STHS34PF80_REG_CTRL1 0x20 ///< Control register 1 (ODR configuration) #define STHS34PF80_REG_CTRL1 0x20 ///< Control register 1 (ODR configuration)
#define STHS34PF80_REG_CTRL2 0x21 ///< Control register 2 (boot, function access, one-shot) #define STHS34PF80_REG_CTRL2 \
#define STHS34PF80_REG_CTRL3 0x22 ///< Control register 3 (interrupt configuration) 0x21 ///< Control register 2 (boot, function access, one-shot)
#define STHS34PF80_REG_STATUS 0x23 ///< Status register #define STHS34PF80_REG_CTRL3 \
0x22 ///< Control register 3 (interrupt configuration)
#define STHS34PF80_REG_STATUS 0x23 ///< Status register
#define STHS34PF80_REG_FUNC_STATUS 0x25 ///< Function status register #define STHS34PF80_REG_FUNC_STATUS 0x25 ///< Function status register
#define STHS34PF80_REG_TOBJECT_L 0x26 ///< Object temperature LSB register #define STHS34PF80_REG_TOBJECT_L 0x26 ///< Object temperature LSB register
#define STHS34PF80_REG_TOBJECT_H 0x27 ///< Object temperature MSB register #define STHS34PF80_REG_TOBJECT_H 0x27 ///< Object temperature MSB register
#define STHS34PF80_REG_TAMBIENT_L 0x28 ///< Ambient temperature LSB register #define STHS34PF80_REG_TAMBIENT_L 0x28 ///< Ambient temperature LSB register
#define STHS34PF80_REG_TAMBIENT_H 0x29 ///< Ambient temperature MSB register #define STHS34PF80_REG_TAMBIENT_H 0x29 ///< Ambient temperature MSB register
#define STHS34PF80_REG_TOBJ_COMP_L 0x38 ///< Compensated object temperature LSB register #define STHS34PF80_REG_TOBJ_COMP_L \
#define STHS34PF80_REG_TOBJ_COMP_H 0x39 ///< Compensated object temperature MSB register 0x38 ///< Compensated object temperature LSB register
#define STHS34PF80_REG_TOBJ_COMP_H \
0x39 ///< Compensated object temperature MSB register
#define STHS34PF80_REG_TPRESENCE_L 0x3A ///< Presence detection LSB register #define STHS34PF80_REG_TPRESENCE_L 0x3A ///< Presence detection LSB register
#define STHS34PF80_REG_TPRESENCE_H 0x3B ///< Presence detection MSB register #define STHS34PF80_REG_TPRESENCE_H 0x3B ///< Presence detection MSB register
#define STHS34PF80_REG_TMOTION_L 0x3C ///< Motion detection LSB register #define STHS34PF80_REG_TMOTION_L 0x3C ///< Motion detection LSB register
#define STHS34PF80_REG_TMOTION_H 0x3D ///< Motion detection MSB register #define STHS34PF80_REG_TMOTION_H 0x3D ///< Motion detection MSB register
#define STHS34PF80_REG_TAMB_SHOCK_L 0x3E ///< Ambient shock detection LSB register #define STHS34PF80_REG_TAMB_SHOCK_L \
#define STHS34PF80_REG_TAMB_SHOCK_H 0x3F ///< Ambient shock detection MSB register 0x3E ///< Ambient shock detection LSB register
#define STHS34PF80_REG_TAMB_SHOCK_H \
0x3F ///< Ambient shock detection MSB register
#define STHS34PF80_REG_FUNC_CFG_ADDR \
0x08 ///< Embedded function configuration address register
#define STHS34PF80_REG_FUNC_CFG_DATA \
0x09 ///< Embedded function configuration data register
#define STHS34PF80_REG_PAGE_RW 0x11 ///< Page read/write control register
#define STHS34PF80_EMBEDDED_RESET_ALGO \
0x2A ///< Embedded function RESET_ALGO register address
#define STHS34PF80_PRES_FLAG 0x04 ///< Presence detection flag
#define STHS34PF80_MOT_FLAG 0x02 ///< Motion detection flag
#define STHS34PF80_TAMB_SHOCK_FLAG 0x01 ///< Ambient temperature shock flag
/*! /*!
* @brief Low-pass filter configuration options * @brief Low-pass filter configuration options
@ -66,14 +86,65 @@ typedef enum {
} sths34pf80_lpf_config_t; } sths34pf80_lpf_config_t;
/*! /*!
* @brief Class that stores state and functions for interacting with the STHS34PF80 * @brief Ambient temperature averaging options
*/
typedef enum {
STHS34PF80_AVG_T_8 = 0x00, ///< 8 samples (default)
STHS34PF80_AVG_T_4 = 0x01, ///< 4 samples
STHS34PF80_AVG_T_2 = 0x02, ///< 2 samples
STHS34PF80_AVG_T_1 = 0x03, ///< 1 sample
} sths34pf80_avg_t_t;
/*!
* @brief Object temperature averaging options
*/
typedef enum {
STHS34PF80_AVG_TMOS_2 = 0x00, ///< 2 samples
STHS34PF80_AVG_TMOS_8 = 0x01, ///< 8 samples
STHS34PF80_AVG_TMOS_32 = 0x02, ///< 32 samples
STHS34PF80_AVG_TMOS_128 = 0x03, ///< 128 samples (default)
STHS34PF80_AVG_TMOS_256 = 0x04, ///< 256 samples
STHS34PF80_AVG_TMOS_512 = 0x05, ///< 512 samples
STHS34PF80_AVG_TMOS_1024 = 0x06, ///< 1024 samples
STHS34PF80_AVG_TMOS_2048 = 0x07, ///< 2048 samples
} sths34pf80_avg_tmos_t;
/*!
* @brief Output data rate options
*/
typedef enum {
STHS34PF80_ODR_POWER_DOWN = 0x00, ///< Power-down mode
STHS34PF80_ODR_0_25_HZ = 0x01, ///< 0.25 Hz
STHS34PF80_ODR_0_5_HZ = 0x02, ///< 0.5 Hz
STHS34PF80_ODR_1_HZ = 0x03, ///< 1 Hz
STHS34PF80_ODR_2_HZ = 0x04, ///< 2 Hz
STHS34PF80_ODR_4_HZ = 0x05, ///< 4 Hz
STHS34PF80_ODR_8_HZ = 0x06, ///< 8 Hz
STHS34PF80_ODR_15_HZ = 0x07, ///< 15 Hz
STHS34PF80_ODR_30_HZ = 0x08, ///< 30 Hz (1xxx)
} sths34pf80_odr_t;
/*!
* @brief Interrupt enable signal options
*/
typedef enum {
STHS34PF80_INT_HIGH_Z = 0x00, ///< High-Z (disabled)
STHS34PF80_INT_DRDY = 0x01, ///< Data ready
STHS34PF80_INT_OR = 0x02, ///< INT_OR (function flags)
} sths34pf80_int_signal_t;
/*!
* @brief Class that stores state and functions for interacting with the
* STHS34PF80
*/ */
class Adafruit_STHS34PF80 { class Adafruit_STHS34PF80 {
public: public:
Adafruit_STHS34PF80(); Adafruit_STHS34PF80();
~Adafruit_STHS34PF80(); ~Adafruit_STHS34PF80();
bool begin(uint8_t i2c_addr = STHS34PF80_DEFAULT_ADDR, TwoWire *wire = &Wire); bool begin(uint8_t i2c_addr = STHS34PF80_DEFAULT_ADDR, TwoWire* wire = &Wire);
bool isConnected();
bool reset();
bool setMotionLowPassFilter(sths34pf80_lpf_config_t config); bool setMotionLowPassFilter(sths34pf80_lpf_config_t config);
sths34pf80_lpf_config_t getMotionLowPassFilter(); sths34pf80_lpf_config_t getMotionLowPassFilter();
@ -84,8 +155,53 @@ public:
bool setTemperatureLowPassFilter(sths34pf80_lpf_config_t config); bool setTemperatureLowPassFilter(sths34pf80_lpf_config_t config);
sths34pf80_lpf_config_t getTemperatureLowPassFilter(); sths34pf80_lpf_config_t getTemperatureLowPassFilter();
private: bool setAmbTempAveraging(sths34pf80_avg_t_t config);
Adafruit_I2CDevice *i2c_dev; sths34pf80_avg_t_t getAmbTempAveraging();
bool setObjAveraging(sths34pf80_avg_tmos_t config);
sths34pf80_avg_tmos_t getObjAveraging();
bool setWideGainMode(bool wide_mode);
bool getWideGainMode();
bool setSensitivity(int8_t sensitivity);
int8_t getSensitivity();
bool setBlockDataUpdate(bool enable);
bool getBlockDataUpdate();
bool setOutputDataRate(sths34pf80_odr_t odr);
sths34pf80_odr_t getOutputDataRate();
bool rebootOTPmemory();
bool enableEmbeddedFuncPage(bool enable);
bool triggerOneshot();
bool writeEmbeddedFunction(uint8_t addr, uint8_t* data, uint8_t len);
bool setIntPolarity(bool active_low);
bool setIntOpenDrain(bool open_drain);
bool setIntLatched(bool latched);
bool setIntMask(uint8_t mask);
uint8_t getIntMask();
bool setIntSignal(sths34pf80_int_signal_t signal);
sths34pf80_int_signal_t getIntSignal();
bool isDataReady();
bool isPresence();
bool isMotion();
bool isTempShock();
int16_t readObjectTemperature();
float readAmbientTemperature();
int16_t readCompensatedObjectTemperature();
int16_t readPresence();
int16_t readMotion();
int16_t readTempShock();
private:
Adafruit_I2CDevice* i2c_dev;
bool safeSetOutputDataRate(sths34pf80_odr_t current_odr,
sths34pf80_odr_t new_odr);
bool algorithmReset(); // TODO: Implement algorithm reset procedure
}; };
#endif #endif

135
CODE_OF_CONDUCT.md Normal file
View file

@ -0,0 +1,135 @@
<!--
SPDX-FileCopyrightText: 2014 Coraline Ada Ehmke
SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries
SPDX-License-Identifier: CC-BY-4.0
-->
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Promoting or spreading disinformation, lies, or conspiracy theories against
a person, group, organisation, project, or community
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Moderators by tagging @community moderators. You may
also send an open message from any channel, or a direct message to
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2024 Adafruit Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,286 @@
/*
* STHS34PF80 Full Test Sketch
*
* This sketch demonstrates comprehensive testing of all STHS34PF80 sensor settings
* and configuration options. It configures each parameter using the sensor's default
* values to demonstrate the API without changing register states unexpectedly.
*
* The sketch will halt with an error message if any configuration fails, and will
* continuously display real-time sensor readings including temperature, motion,
* presence detection, and temperature shock detection.
*
* Note: All setter functions use the actual sensor default values discovered through
* testing to provide a stable demonstration of the configuration API.
*/
#include "Adafruit_STHS34PF80.h"
Adafruit_STHS34PF80 sths;
void printLPFSetting(sths34pf80_lpf_config_t lpf_setting) {
switch (lpf_setting) {
case STHS34PF80_LPF_ODR_DIV_9:
Serial.print("ODR/9");
break;
case STHS34PF80_LPF_ODR_DIV_20:
Serial.print("ODR/20");
break;
case STHS34PF80_LPF_ODR_DIV_50:
Serial.print("ODR/50");
break;
case STHS34PF80_LPF_ODR_DIV_100:
Serial.print("ODR/100");
break;
case STHS34PF80_LPF_ODR_DIV_200:
Serial.print("ODR/200");
break;
case STHS34PF80_LPF_ODR_DIV_400:
Serial.print("ODR/400");
break;
case STHS34PF80_LPF_ODR_DIV_800:
Serial.print("ODR/800");
break;
default:
Serial.print("Unknown");
break;
}
}
void halt(const __FlashStringHelper* message) {
Serial.println(message);
while (1) delay(10);
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Adafruit STHS34PF80 test!");
if (!sths.begin()) {
halt(F("Could not find a valid STHS34PF80 sensor, check wiring!"));
}
Serial.println(F("STHS34PF80 Found!"));
// Test all low-pass filter configurations
Serial.println(F("\n--- Low-Pass Filter Tests ---"));
// Test Motion LPF
Serial.println(F("\nMotion LPF:"));
if (!sths.setMotionLowPassFilter(STHS34PF80_LPF_ODR_DIV_9)) {
halt(F("Failed to set Motion LPF"));
}
Serial.print(F(" Current setting: "));
printLPFSetting(sths.getMotionLowPassFilter());
Serial.println();
// Test Motion+Presence LPF
Serial.println(F("\nMotion+Presence LPF:"));
if (!sths.setMotionPresenceLowPassFilter(STHS34PF80_LPF_ODR_DIV_20)) {
halt(F("Failed to set Motion+Presence LPF"));
}
Serial.print(F(" Current setting: "));
printLPFSetting(sths.getMotionPresenceLowPassFilter());
Serial.println();
// Test Presence LPF
Serial.println(F("\nPresence LPF:"));
if (!sths.setPresenceLowPassFilter(STHS34PF80_LPF_ODR_DIV_50)) {
halt(F("Failed to set Presence LPF"));
}
Serial.print(F(" Current setting: "));
printLPFSetting(sths.getPresenceLowPassFilter());
Serial.println();
// Test Temperature LPF
Serial.println(F("\nTemperature LPF:"));
if (!sths.setTemperatureLowPassFilter(STHS34PF80_LPF_ODR_DIV_100)) {
halt(F("Failed to set Temperature LPF"));
}
Serial.print(F(" Current setting: "));
printLPFSetting(sths.getTemperatureLowPassFilter());
Serial.println();
// Test Ambient Temperature Averaging
Serial.println(F("\nAmbient Temperature Averaging:"));
if (!sths.setAmbTempAveraging(STHS34PF80_AVG_T_8)) {
halt(F("Failed to set Ambient Temperature Averaging"));
}
Serial.print(F(" Current: "));
switch (sths.getAmbTempAveraging()) {
case STHS34PF80_AVG_T_8: Serial.println(F("8 samples")); break;
case STHS34PF80_AVG_T_4: Serial.println(F("4 samples")); break;
case STHS34PF80_AVG_T_2: Serial.println(F("2 samples")); break;
case STHS34PF80_AVG_T_1: Serial.println(F("1 sample")); break;
default: Serial.println(F("Unknown")); break;
}
// Test Object Temperature Averaging
Serial.println(F("\nObject Temperature Averaging:"));
if (!sths.setObjAveraging(STHS34PF80_AVG_TMOS_32)) {
halt(F("Failed to set Object Temperature Averaging"));
}
Serial.print(F(" Current: "));
switch (sths.getObjAveraging()) {
case STHS34PF80_AVG_TMOS_2: Serial.println(F("2 samples")); break;
case STHS34PF80_AVG_TMOS_8: Serial.println(F("8 samples")); break;
case STHS34PF80_AVG_TMOS_32: Serial.println(F("32 samples")); break;
case STHS34PF80_AVG_TMOS_128: Serial.println(F("128 samples")); break;
case STHS34PF80_AVG_TMOS_256: Serial.println(F("256 samples")); break;
case STHS34PF80_AVG_TMOS_512: Serial.println(F("512 samples")); break;
case STHS34PF80_AVG_TMOS_1024: Serial.println(F("1024 samples")); break;
case STHS34PF80_AVG_TMOS_2048: Serial.println(F("2048 samples")); break;
default: Serial.println(F("Unknown")); break;
}
// Test Wide Gain Mode
Serial.println(F("\nWide Gain Mode:"));
if (!sths.setWideGainMode(false)) {
halt(F("Failed to set Wide Gain Mode"));
}
Serial.print(F(" Current: "));
if (sths.getWideGainMode()) {
Serial.println(F("Wide mode"));
} else {
Serial.println(F("Default gain mode"));
}
// Sensitivity (factory calibrated - read only)
Serial.println(F("\nSensitivity:"));
Serial.print(F(" Current: "));
Serial.println(sths.getSensitivity());
// Test Block Data Update
Serial.println(F("\nBlock Data Update:"));
if (!sths.setBlockDataUpdate(true)) {
halt(F("Failed to set Block Data Update"));
}
Serial.print(F(" Current: "));
if (sths.getBlockDataUpdate()) {
Serial.println(F("Enabled"));
} else {
Serial.println(F("Disabled"));
}
// Set Output Data Rate to continuous mode (1 Hz)
Serial.println(F("\nOutput Data Rate:"));
if (!sths.setOutputDataRate(STHS34PF80_ODR_1_HZ)) {
halt(F("Failed to set Output Data Rate"));
}
Serial.print(F(" Current: "));
switch (sths.getOutputDataRate()) {
case STHS34PF80_ODR_POWER_DOWN: Serial.println(F("Power-down")); break;
case STHS34PF80_ODR_0_25_HZ: Serial.println(F("0.25 Hz")); break;
case STHS34PF80_ODR_0_5_HZ: Serial.println(F("0.5 Hz")); break;
case STHS34PF80_ODR_1_HZ: Serial.println(F("1 Hz")); break;
case STHS34PF80_ODR_2_HZ: Serial.println(F("2 Hz")); break;
case STHS34PF80_ODR_4_HZ: Serial.println(F("4 Hz")); break;
case STHS34PF80_ODR_8_HZ: Serial.println(F("8 Hz")); break;
case STHS34PF80_ODR_15_HZ: Serial.println(F("15 Hz")); break;
case STHS34PF80_ODR_30_HZ: Serial.println(F("30 Hz")); break;
default: Serial.println(F("Unknown")); break;
}
// Test CTRL2 functions
Serial.println(F("\nEmbedded Function Page:"));
if (!sths.enableEmbeddedFuncPage(false)) {
halt(F("Failed to disable Embedded Function Page"));
}
// Only trigger one-shot if in power-down mode
if (sths.getOutputDataRate() == STHS34PF80_ODR_POWER_DOWN) {
Serial.println(F("\nTrigger One-shot:"));
if (!sths.triggerOneshot()) {
halt(F("Failed to trigger one-shot"));
}
} else {
Serial.println(F("\nContinuous mode - no one-shot trigger needed"));
}
// Configure interrupts
Serial.println(F("\nInterrupt Configuration:"));
if (!sths.setIntPolarity(false)) {
halt(F("Failed to set interrupt polarity"));
}
if (!sths.setIntOpenDrain(false)) {
halt(F("Failed to set interrupt output type"));
}
if (!sths.setIntLatched(true)) {
halt(F("Failed to set interrupt latched mode"));
}
// Enable interrupts for all three events (matches default)
uint8_t mask = STHS34PF80_PRES_FLAG | STHS34PF80_MOT_FLAG | STHS34PF80_TAMB_SHOCK_FLAG;
if (!sths.setIntMask(mask)) {
halt(F("Failed to set interrupt mask"));
}
// Set interrupt signal to INT_OR (function flags) - matches default
if (!sths.setIntSignal(STHS34PF80_INT_OR)) {
halt(F("Failed to set interrupt signal"));
}
// Print current interrupt mask status
Serial.print(F(" Current interrupt mask: 0x"));
Serial.print(sths.getIntMask(), HEX);
Serial.print(F(" ("));
uint8_t currentMask = sths.getIntMask();
if (currentMask & STHS34PF80_PRES_FLAG) Serial.print(F("PRES "));
if (currentMask & STHS34PF80_MOT_FLAG) Serial.print(F("MOT "));
if (currentMask & STHS34PF80_TAMB_SHOCK_FLAG) Serial.print(F("TAMB_SHOCK "));
Serial.println(F(")"));
// Print current interrupt signal setting
Serial.print(F(" Current interrupt signal: "));
switch (sths.getIntSignal()) {
case STHS34PF80_INT_HIGH_Z:
Serial.println(F("High-Z (disabled)"));
break;
case STHS34PF80_INT_DRDY:
Serial.println(F("Data ready"));
break;
case STHS34PF80_INT_OR:
Serial.println(F("INT_OR (function flags)"));
break;
default:
Serial.println(F("Unknown"));
break;
}
Serial.println(F("\nConfiguration complete!"));
}
void loop() {
if (sths.isDataReady()) {
Serial.print("Data ready! ");
// Check function status flags
if (sths.isPresence()) {
Serial.print("PRESENCE ");
}
if (sths.isMotion()) {
Serial.print("MOTION ");
}
if (sths.isTempShock()) {
Serial.print("TEMP_SHOCK ");
}
// Read temperature and detection data
Serial.print("Amb: ");
Serial.print(sths.readAmbientTemperature(), 2);
Serial.print("°C, Obj: ");
Serial.print(sths.readObjectTemperature());
Serial.print(", Comp: ");
Serial.print(sths.readCompensatedObjectTemperature());
Serial.print(", Pres: ");
Serial.print(sths.readPresence());
Serial.print(", Mot: ");
Serial.print(sths.readMotion());
Serial.print(", Shock: ");
Serial.print(sths.readTempShock());
Serial.println();
}
delay(100);
}

View file

@ -0,0 +1,62 @@
// Basic test for STHS34PF80 infrared sensor
#include "Adafruit_STHS34PF80.h"
Adafruit_STHS34PF80 sths;
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Adafruit STHS34PF80 test!");
if (!sths.begin()) {
Serial.println("Could not find a valid STHS34PF80 sensor, check wiring!");
while (1) delay(10);
}
Serial.println("STHS34PF80 Found!");
}
void loop() {
if (!sths.isDataReady()) {
delay(10);
return;
}
Serial.print("Data ready! ");
// Read temperature data
Serial.print("Amb: ");
Serial.print(sths.readAmbientTemperature(), 2);
Serial.print("°C");
// Check for presence and show data if detected
if (sths.isPresence()) {
Serial.print(" PRESENCE: ");
Serial.print(sths.readPresence());
}
// Check for motion and show data if detected
if (sths.isMotion()) {
Serial.print(" MOTION: ");
Serial.print(sths.readMotion());
}
// Check for temperature shock and show data if detected
if (sths.isTempShock()) {
Serial.print(" TEMP_SHOCK: ");
Serial.print(sths.readTempShock());
}
// Show object temperatures only if presence or motion detected
if (sths.isPresence() || sths.isMotion()) {
Serial.print(" Obj: ");
Serial.print(sths.readObjectTemperature());
Serial.print(", Comp: ");
Serial.print(sths.readCompensatedObjectTemperature());
}
Serial.println();
delay(100);
}

View file

@ -1,100 +0,0 @@
// Basic test for STHS34PF80 infrared sensor
#include "Adafruit_STHS34PF80.h"
Adafruit_STHS34PF80 sths;
void printLPFSetting(sths34pf80_lpf_config_t lpf_setting) {
switch (lpf_setting) {
case STHS34PF80_LPF_ODR_DIV_9:
Serial.print("ODR/9");
break;
case STHS34PF80_LPF_ODR_DIV_20:
Serial.print("ODR/20");
break;
case STHS34PF80_LPF_ODR_DIV_50:
Serial.print("ODR/50");
break;
case STHS34PF80_LPF_ODR_DIV_100:
Serial.print("ODR/100");
break;
case STHS34PF80_LPF_ODR_DIV_200:
Serial.print("ODR/200");
break;
case STHS34PF80_LPF_ODR_DIV_400:
Serial.print("ODR/400");
break;
case STHS34PF80_LPF_ODR_DIV_800:
Serial.print("ODR/800");
break;
default:
Serial.print("Unknown");
break;
}
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Adafruit STHS34PF80 test!");
if (!sths.begin()) {
Serial.println("Could not find a valid STHS34PF80 sensor, check wiring!");
while (1) delay(10);
}
Serial.println("STHS34PF80 Found!");
// Test all low-pass filter configurations
Serial.println("\n--- Low-Pass Filter Tests ---");
Serial.println("Available options: ODR/9, ODR/20, ODR/50, ODR/100, ODR/200, ODR/400, ODR/800");
// Test Motion LPF
Serial.println("\n1. Motion LPF:");
if (sths.setMotionLowPassFilter(STHS34PF80_LPF_ODR_DIV_9)) {
Serial.println(" Set to ODR/9 - Success");
} else {
Serial.println(" Set to ODR/9 - Failed");
}
Serial.print(" Current setting: ");
printLPFSetting(sths.getMotionLowPassFilter());
Serial.println();
// Test Motion+Presence LPF
Serial.println("\n2. Motion+Presence LPF:");
if (sths.setMotionPresenceLowPassFilter(STHS34PF80_LPF_ODR_DIV_20)) {
Serial.println(" Set to ODR/20 - Success");
} else {
Serial.println(" Set to ODR/20 - Failed");
}
Serial.print(" Current setting: ");
printLPFSetting(sths.getMotionPresenceLowPassFilter());
Serial.println();
// Test Presence LPF
Serial.println("\n3. Presence LPF:");
if (sths.setPresenceLowPassFilter(STHS34PF80_LPF_ODR_DIV_50)) {
Serial.println(" Set to ODR/50 - Success");
} else {
Serial.println(" Set to ODR/50 - Failed");
}
Serial.print(" Current setting: ");
printLPFSetting(sths.getPresenceLowPassFilter());
Serial.println();
// Test Temperature LPF
Serial.println("\n4. Temperature LPF:");
if (sths.setTemperatureLowPassFilter(STHS34PF80_LPF_ODR_DIV_100)) {
Serial.println(" Set to ODR/100 - Success");
} else {
Serial.println(" Set to ODR/100 - Failed");
}
Serial.print(" Current setting: ");
printLPFSetting(sths.getTemperatureLowPassFilter());
Serial.println();
}
void loop() {
delay(1000);
}

10
library.properties Normal file
View file

@ -0,0 +1,10 @@
name=Adafruit STHS34PF80
version=1.0.1
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for STHS34PF80 infrared sensor for presence and motion detection
paragraph=This library provides an interface for the STHS34PF80 uncooled infrared sensor. The STHS34PF80 embeds a TMOS sensitive element and signal conditioning ASIC for presence and motion detection with I2C interface, embedded algorithms, and configurable thresholds.
category=Sensors
url=https://github.com/adafruit/Adafruit_STHS34PF80
architectures=*
depends=Adafruit BusIO

View file

@ -1,44 +0,0 @@
Adafruit STHS34PF80 test!
Address 0x5A Detected
I2CWRITE @ 0x5A :: 0xF,
I2CREAD @ 0x5A :: 0xD3,
STHS34PF80 Found!
--- Low-Pass Filter Tests ---
Available options: ODR/9, ODR/20, ODR/50, ODR/100, ODR/200, ODR/400, ODR/800
1. Motion LPF:
I2CWRITE @ 0x5A :: 0xC,
I2CREAD @ 0x5A :: 0x8,
I2CWRITE @ 0x5A :: 0xC, 0x8, STOP
Set to ODR/9 - Success
Current setting: I2CWRITE @ 0x5A :: 0xC,
I2CREAD @ 0x5A :: 0x8,
ODR/9
2. Motion+Presence LPF:
I2CWRITE @ 0x5A :: 0xC,
I2CREAD @ 0x5A :: 0x8,
I2CWRITE @ 0x5A :: 0xC, 0x8, STOP
Set to ODR/20 - Success
Current setting: I2CWRITE @ 0x5A :: 0xC,
I2CREAD @ 0x5A :: 0x8,
ODR/20
3. Presence LPF:
I2CWRITE @ 0x5A :: 0xD,
I2CREAD @ 0x5A :: 0x13,
I2CWRITE @ 0x5A :: 0xD, 0x13, STOP
Set to ODR/50 - Success
Current setting: I2CWRITE @ 0x5A :: 0xD,
I2CREAD @ 0x5A :: 0x13,
ODR/50
4. Temperature LPF:
I2CWRITE @ 0x5A :: 0xD,
I2CREAD @ 0x5A :: 0x13,
I2CWRITE @ 0x5A :: 0xD, 0x13, STOP
Set to ODR/100 - Success
Current setting: I2CWRITE @ 0x5A :: 0xD,
I2CREAD @ 0x5A :: 0x13,
ODR/100

Binary file not shown.

View file

@ -1,4 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.st.com/en/mems-and-sensors/sths34pf80.html
HostUrl=https://www.st.com/resource/en/datasheet/sths34pf80.pdf

File diff suppressed because it is too large Load diff